Skip to content

Commit 0c43d15

Browse files
committed
test: one describe per file and drop assertions that only restated constants
1 parent 52b8a20 commit 0c43d15

7 files changed

Lines changed: 363 additions & 345 deletions

File tree

‎.github/scripts/tests/dependabot-pr-reminder/classify.test.mts‎

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,66 @@ import { pr } from './fixtures.mts';
55

66
const options = { sharedTeamThreshold: 3 };
77

8-
describe('classifyPullRequests', () => {
9-
it('lists a PR under each requested team', () => {
10-
const pullRequest = pr({ requestedTeams: ['a', 'b'] });
8+
describe('classify', () => {
9+
describe('classifyPullRequests', () => {
10+
it('lists a PR under each requested team', () => {
11+
const pullRequest = pr({ requestedTeams: ['a', 'b'] });
1112

12-
const { byTeam } = classifyPullRequests([pullRequest], options);
13+
const { byTeam } = classifyPullRequests([pullRequest], options);
1314

14-
expect(byTeam).toStrictEqual({ a: [pullRequest], b: [pullRequest] });
15-
});
15+
expect(byTeam).toStrictEqual({ a: [pullRequest], b: [pullRequest] });
16+
});
1617

17-
it('puts a PR with no team in the fallback', () => {
18-
const pullRequest = pr();
18+
it('puts a PR with no team in the fallback', () => {
19+
const pullRequest = pr();
1920

20-
const { fallback } = classifyPullRequests([pullRequest], options);
21+
const { fallback } = classifyPullRequests([pullRequest], options);
2122

22-
expect(fallback.noTeam).toStrictEqual([pullRequest]);
23-
});
23+
expect(fallback.noTeam).toStrictEqual([pullRequest]);
24+
});
2425

25-
it('keeps a PR with exactly the threshold under its teams', () => {
26-
const pullRequest = pr({ requestedTeams: ['a', 'b', 'c'] });
26+
it('keeps a PR with exactly the threshold under its teams', () => {
27+
const pullRequest = pr({ requestedTeams: ['a', 'b', 'c'] });
2728

28-
const { byTeam, fallback } = classifyPullRequests([pullRequest], options);
29+
const { byTeam, fallback } = classifyPullRequests([pullRequest], options);
2930

30-
expect(Object.keys(byTeam)).toStrictEqual(['a', 'b', 'c']);
31-
expect(fallback.sharedByManyTeams).toStrictEqual([]);
32-
});
31+
expect(Object.keys(byTeam)).toStrictEqual(['a', 'b', 'c']);
32+
expect(fallback.sharedByManyTeams).toStrictEqual([]);
33+
});
3334

34-
it('puts a PR with more teams than the threshold in the fallback', () => {
35-
const pullRequest = pr({ requestedTeams: ['a', 'b', 'c', 'd'] });
35+
it('puts a PR with more teams than the threshold in the fallback', () => {
36+
const pullRequest = pr({ requestedTeams: ['a', 'b', 'c', 'd'] });
3637

37-
const { byTeam, fallback } = classifyPullRequests([pullRequest], options);
38+
const { byTeam, fallback } = classifyPullRequests([pullRequest], options);
3839

39-
expect(byTeam).toStrictEqual({});
40-
expect(fallback.sharedByManyTeams).toStrictEqual([pullRequest]);
41-
});
40+
expect(byTeam).toStrictEqual({});
41+
expect(fallback.sharedByManyTeams).toStrictEqual([pullRequest]);
42+
});
43+
44+
it('only counts the owner teams, ignoring case and repeats', () => {
45+
const pullRequest = pr({
46+
requestedTeams: ['a', 'A', 'b', 'x', 'y', 'z'],
47+
});
4248

43-
it('only counts the owner teams, ignoring case and repeats', () => {
44-
const pullRequest = pr({ requestedTeams: ['a', 'A', 'b', 'x', 'y', 'z'] });
49+
const { byTeam, fallback } = classifyPullRequests([pullRequest], {
50+
...options,
51+
ownerTeams: ['@MetaMask/a', 'b'],
52+
});
4553

46-
const { byTeam, fallback } = classifyPullRequests([pullRequest], {
47-
...options,
48-
ownerTeams: ['@MetaMask/a', 'b'],
54+
expect(Object.keys(byTeam)).toStrictEqual(['a', 'b']);
55+
expect(fallback.sharedByManyTeams).toStrictEqual([]);
4956
});
5057

51-
expect(Object.keys(byTeam)).toStrictEqual(['a', 'b']);
52-
expect(fallback.sharedByManyTeams).toStrictEqual([]);
53-
});
58+
it('puts a PR in the fallback when no owner team is left', () => {
59+
const pullRequest = pr({ requestedTeams: ['ui'] });
5460

55-
it('puts a PR in the fallback when no owner team is left', () => {
56-
const pullRequest = pr({ requestedTeams: ['ui'] });
61+
const { byTeam, fallback } = classifyPullRequests([pullRequest], {
62+
...options,
63+
ownerTeams: ['extension-platform'],
64+
});
5765

58-
const { byTeam, fallback } = classifyPullRequests([pullRequest], {
59-
...options,
60-
ownerTeams: ['extension-platform'],
66+
expect(byTeam).toStrictEqual({});
67+
expect(fallback.noTeam).toStrictEqual([pullRequest]);
6168
});
62-
63-
expect(byTeam).toStrictEqual({});
64-
expect(fallback.noTeam).toStrictEqual([pullRequest]);
6569
});
6670
});

‎.github/scripts/tests/dependabot-pr-reminder/cli.test.mts‎

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,58 @@ const SCRIPT = fileURLToPath(
1212
new URL('../../dependabot-pr-reminder/cli.mts', import.meta.url),
1313
);
1414

15-
describe('cli entry point', () => {
16-
let directory: string | undefined;
15+
describe('cli', () => {
16+
describe('entry point', () => {
17+
let directory: string | undefined;
1718

18-
afterEach(async () => {
19-
if (directory) {
20-
await rm(directory, { recursive: true, force: true });
21-
directory = undefined;
22-
}
23-
});
19+
afterEach(async () => {
20+
if (directory) {
21+
await rm(directory, { recursive: true, force: true });
22+
directory = undefined;
23+
}
24+
});
2425

25-
/**
26-
* Runs the script with no settings, so it stops at once with a message.
27-
*
28-
* @param scriptPath - The path to run it through.
29-
* @returns What it printed on stderr.
30-
*/
31-
async function runWithoutSettings(scriptPath: string): Promise<string> {
32-
try {
33-
await execFileAsync(process.execPath, [scriptPath], {
34-
env: { PATH: process.env.PATH ?? '' },
35-
});
36-
} catch (error) {
37-
return (error as { stderr?: string }).stderr ?? '';
26+
/**
27+
* Runs the script with no settings, so it stops at once with a message.
28+
*
29+
* @param scriptPath - The path to run it through.
30+
* @returns What it printed on stderr.
31+
*/
32+
async function runWithoutSettings(scriptPath: string): Promise<string> {
33+
try {
34+
await execFileAsync(process.execPath, [scriptPath], {
35+
env: { PATH: process.env.PATH ?? '' },
36+
});
37+
} catch (error) {
38+
return (error as { stderr?: string }).stderr ?? '';
39+
}
40+
return '';
3841
}
39-
return '';
40-
}
4142

42-
it('runs when started by its plain path', async () => {
43-
const output = await runWithoutSettings(SCRIPT);
43+
it('runs when started by its plain path', async () => {
44+
const output = await runWithoutSettings(SCRIPT);
4445

45-
expect(output).toContain('are required');
46-
});
46+
expect(output).toContain('are required');
47+
});
4748

48-
it('runs when started through a path with .. segments', async () => {
49-
// Built as a string, since `path.join` would remove the `..` segments.
50-
const dotted = `${dirname(SCRIPT)}/../dependabot-pr-reminder/cli.mts`;
49+
it('runs when started through a path with .. segments', async () => {
50+
// Built as a string, since `path.join` would remove the `..` segments.
51+
const dotted = `${dirname(SCRIPT)}/../dependabot-pr-reminder/cli.mts`;
5152

52-
const output = await runWithoutSettings(dotted);
53+
const output = await runWithoutSettings(dotted);
5354

54-
expect(dotted).toContain('/../');
55-
expect(output).toContain('are required');
56-
});
55+
expect(dotted).toContain('/../');
56+
expect(output).toContain('are required');
57+
});
5758

58-
it('runs when started through a symlinked directory', async () => {
59-
directory = await mkdtemp(join(tmpdir(), 'reminder-cli-'));
60-
const link = join(directory, 'scripts');
61-
await symlink(resolve(SCRIPT, '..'), link);
59+
it('runs when started through a symlinked directory', async () => {
60+
directory = await mkdtemp(join(tmpdir(), 'reminder-cli-'));
61+
const link = join(directory, 'scripts');
62+
await symlink(resolve(SCRIPT, '..'), link);
6263

63-
const output = await runWithoutSettings(join(link, 'cli.mts'));
64+
const output = await runWithoutSettings(join(link, 'cli.mts'));
6465

65-
expect(output).toContain('are required');
66+
expect(output).toContain('are required');
67+
});
6668
});
6769
});

‎.github/scripts/tests/dependabot-pr-reminder/dependabot-title.test.mts‎

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,41 @@ import { describe, expect, it } from 'vitest';
22

33
import { describeUpdate } from '../../dependabot-pr-reminder/dependabot-title.mts';
44

5-
describe('describeUpdate', () => {
6-
it.each([
7-
[
8-
'chore(deps): bump @noble/curves from 1.9.7 to 2.4.0',
9-
'`@noble/curves` 1.9.7 → 2.4.0',
10-
],
11-
[
12-
'chore(deps-dev): bump jsdom from 27.4.0 to 31.0.1',
13-
'`jsdom` 27.4.0 → 31.0.1 (dev)',
14-
],
15-
['Bump foo from 1.0.0 to 1.1.0 in /packages/a', '`foo` 1.0.0 → 1.1.0'],
16-
[
17-
'chore(deps): bump tar from 7.5.24 to 8.0.5 in /packages/foundryup in the npm_and_yarn group across 1 directory',
18-
'`tar` 7.5.24 → 8.0.5',
19-
],
20-
[
21-
'chore(deps): bump the external-non-major group across 1 directory with 7 updates',
22-
'`external-non-major` group, 7 updates',
23-
],
24-
['Bump the tools group in /app with 1 update', '`tools` group, 1 update'],
25-
['bump a&b from 1<2 to 3>4', '`a&amp;b` 1&lt;2 → 3&gt;4'],
26-
])('reads %s', (title, expected) => {
27-
const description = describeUpdate(title);
5+
describe('dependabot-title', () => {
6+
describe('describeUpdate', () => {
7+
it.each([
8+
[
9+
'chore(deps): bump @noble/curves from 1.9.7 to 2.4.0',
10+
'`@noble/curves` 1.9.7 → 2.4.0',
11+
],
12+
[
13+
'chore(deps-dev): bump jsdom from 27.4.0 to 31.0.1',
14+
'`jsdom` 27.4.0 → 31.0.1 (dev)',
15+
],
16+
['Bump foo from 1.0.0 to 1.1.0 in /packages/a', '`foo` 1.0.0 → 1.1.0'],
17+
[
18+
'chore(deps): bump tar from 7.5.24 to 8.0.5 in /packages/foundryup in the npm_and_yarn group across 1 directory',
19+
'`tar` 7.5.24 → 8.0.5',
20+
],
21+
[
22+
'chore(deps): bump the external-non-major group across 1 directory with 7 updates',
23+
'`external-non-major` group, 7 updates',
24+
],
25+
['Bump the tools group in /app with 1 update', '`tools` group, 1 update'],
26+
['bump a&b from 1<2 to 3>4', '`a&amp;b` 1&lt;2 → 3&gt;4'],
27+
])('reads %s', (title, expected) => {
28+
const description = describeUpdate(title);
2829

29-
expect(description).toBe(expected);
30-
});
30+
expect(description).toBe(expected);
31+
});
3132

32-
it.each(['Bump a and b', 'Something else entirely'])(
33-
'does not read %s',
34-
(title) => {
35-
const description = describeUpdate(title);
33+
it.each(['Bump a and b', 'Something else entirely'])(
34+
'does not read %s',
35+
(title) => {
36+
const description = describeUpdate(title);
3637

37-
expect(description).toBeUndefined();
38-
},
39-
);
38+
expect(description).toBeUndefined();
39+
},
40+
);
41+
});
4042
});

0 commit comments

Comments
 (0)