Repository navigation
Expand file tree
/
Copy pathpr-review.test.mjs
More file actions
87 lines (72 loc) · 3.33 KB
/
Copy pathpr-review.test.mjs
File metadata and controls
87 lines (72 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import assert from 'node:assert/strict';
import test from 'node:test';
import { reviewPullRequest } from './pr-review.mjs';
const checklist = [
'My code follows the style guidelines of this project',
'I have performed a self-review of the code',
'I have commented my code, particularly in hard-to-understand areas',
'I have made corresponding changes to the documentation',
'My changes generate no new warnings',
'Any dependent changes have been merged and published in downstream modules',
'I have checked my code and corrected any misspellings',
];
const validPullRequest = {
title: 'docs: clarify installation',
body: [
'## Description',
'Clarify setup instructions.',
'## Type of Change',
'Documentation',
'## How Has This Been Tested?',
'Reviewed the generated page.',
'## Checklist',
...checklist.map((item) => `- [x] ${item}`),
].join('\n'),
};
test('accepts a complete small pull request', () => {
const result = reviewPullRequest(validPullRequest, [
{ filename: 'src/app.test.tsx', status: 'modified', additions: 2, deletions: 1 },
{ filename: 'docs/guide.md', status: 'modified', additions: 5, deletions: 0 },
]);
assert.deepEqual(result.failures, []);
assert.deepEqual(result.warnings, []);
assert.ok(result.messages.includes('Thanks for updating tests! Only you can prevent production fires.'));
assert.ok(result.messages.includes('Thanks for updating documentation.'));
});
test('fails missing title, description, and required sections and warns on unchecked items', () => {
const result = reviewPullRequest({ title: '', body: '' }, []);
assert.equal(result.failures.length, 6);
assert.equal(result.warnings.length, checklist.length);
});
test('warns when the diff exceeds either threshold', () => {
const files = Array.from({ length: 11 }, (_, index) => ({
filename: `src/file-${index}.tsx`,
status: 'modified',
additions: 20,
deletions: 0,
}));
const result = reviewPullRequest(validPullRequest, files);
assert.ok(result.warnings.includes('This PR changes more than 200 lines.'));
assert.ok(result.warnings.includes('This PR changes more than 10 files.'));
});
test('warns when a package manifest changes', () => {
const result = reviewPullRequest(validPullRequest, [
{ filename: 'package.json', status: 'modified', additions: 1, deletions: 1 },
]);
assert.ok(result.warnings.includes('package.json changed. Ensure applicable lock files are updated.'));
});
test('does not require the template from bot-authored pull requests', () => {
const result = reviewPullRequest({ title: 'chore(deps): bump vite', body: '', user: { type: 'Bot' } }, [
{ filename: 'package.json', status: 'modified', additions: 1, deletions: 1 },
]);
assert.deepEqual(result.failures, []);
assert.deepEqual(result.warnings, ['package.json changed. Ensure applicable lock files are updated.']);
});
test('still requires the title from bot-authored pull requests', () => {
const result = reviewPullRequest({ title: '', body: '', user: { type: 'Bot' } }, []);
assert.deepEqual(result.failures, ['Missing PR Title - Add a relevant pull request title.']);
});
test('still requires the template from human-authored pull requests', () => {
const result = reviewPullRequest({ title: 'fix: typo', body: '', user: { type: 'User' } }, []);
assert.equal(result.failures.length, 5);
});