Skip to content

Commit eeb04cd

Browse files
committed
add some more test cases
1 parent 2eaa4a9 commit eeb04cd

File tree

7 files changed

+76
-9
lines changed

7 files changed

+76
-9
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
id: test-action
5858
uses: ./
5959
with:
60-
ignoreDefault: true
60+
ignoreDefault: false
6161

6262
- name: Print Output
6363
id: output

__tests__/main.test.ts

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,77 @@ jest.unstable_mockModule('@actions/core', () => core);
1515
// mocks are used in place of any actual dependencies.
1616
const { runAction } = await import('../src/main.js');
1717

18-
test('run action', async () => {
18+
test('can run successfully', async () => {
1919
core.isDebug.mockReturnValue(false);
20-
return runAction({
20+
runAction({
2121
includeGitignore: false,
2222
ignoreDefault: false,
23-
files: '',
23+
files: `root/file1.js file.md`,
2424
allRulesMustHit: false,
25+
codeownersContent: `
26+
/root @owner3
27+
*.md @owner4
28+
`,
2529
});
30+
31+
// expect 4 group calls
32+
expect(core.startGroup).toHaveBeenCalledTimes(5);
33+
expect(core.endGroup).toHaveBeenCalledTimes(5);
34+
expect(core.error).toHaveBeenCalledTimes(0);
35+
expect(core.setOutput.mock.calls[0][0]).toBe('missedFiles');
36+
expect(core.setOutput.mock.calls[0][1]).toBe(``);
37+
expect(core.setFailed).toHaveBeenCalledTimes(0);
38+
});
39+
40+
test('fails on missing files', async () => {
41+
core.isDebug.mockReturnValue(false);
42+
runAction({
43+
includeGitignore: false,
44+
ignoreDefault: true,
45+
files: `root/file1.js file.js file.md any/file.md not/root/missed.js folder/file.js notroot/folder/file.js`,
46+
allRulesMustHit: true,
47+
codeownersContent: `#comment
48+
* @all-ignored
49+
folder @owner1
50+
/root @owner3
51+
*.md @owner4
52+
`,
53+
});
54+
55+
// expect 4 group calls
56+
expect(core.startGroup).toHaveBeenCalledTimes(5);
57+
expect(core.endGroup).toHaveBeenCalledTimes(5);
58+
expect(core.error).toHaveBeenCalledTimes(2);
59+
expect(core.error.mock.calls[0][1]!.file).toBe('/file.js');
60+
expect(core.error.mock.calls[1][1]!.file).toBe('/not/root/missed.js');
61+
expect(core.setOutput.mock.calls[0][0]).toBe('missedFiles');
62+
expect(core.setOutput.mock.calls[0][1]).toBe(`/file.js\n/not/root/missed.js`);
63+
expect(core.setFailed).toHaveBeenCalledTimes(1);
64+
});
65+
66+
test('fails on unused codeowner rules', async () => {
67+
core.isDebug.mockReturnValue(false);
68+
runAction({
69+
includeGitignore: false,
70+
ignoreDefault: true,
71+
files: `root/file.js file.md`,
72+
allRulesMustHit: true,
73+
codeownersContent: `#comment
74+
* @all-ignored
75+
folder @owner1
76+
/root @owner3
77+
*.md @owner4
78+
`,
79+
});
80+
81+
// expect 4 group calls
82+
expect(core.startGroup).toHaveBeenCalledTimes(5);
83+
expect(core.endGroup).toHaveBeenCalledTimes(5);
84+
expect(core.error).toHaveBeenCalledTimes(1);
85+
expect(core.error.mock.calls[0][1]!.file).toBe('CODEOWNERS');
86+
expect(core.error.mock.calls[0][1]!.startLine).toBe(3);
87+
expect(core.error.mock.calls[0][0]).toBe('Rule not used: folder');
88+
expect(core.setOutput.mock.calls[0][0]).toBe('missedFiles');
89+
expect(core.setOutput.mock.calls[0][1]).toBe(``);
90+
expect(core.setFailed).toHaveBeenCalledTimes(1);
2691
});

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"package": "npx rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
3434
"package:watch": "npm run package -- --watch",
3535
"test": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 npx jest",
36-
"all": "npm run format:write && npm run lint && npm run test && npm run coverage && npm run package"
36+
"all": "npm run format:write && npm run lint -- --fix && npm run test && npm run coverage && npm run package"
3737
},
3838
"license": "MIT",
3939
"dependencies": {

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export const runAction = async (input: Input): Promise<void> => {
3333
.split(' ')
3434
.map((file) => (file.startsWith('/') ? file : `/${file}`));
3535
} else {
36-
filesToCheck = await (await glob.create('*')).glob();
36+
// glob all files except .git folder
37+
filesToCheck = await (await glob.create('*\n!.git/**')).glob();
3738
if (input['includeGitignore'] === true) {
3839
core.info('Ignoring .gitignored files');
3940
let gitIgnoreFiles: string[] = [];

0 commit comments

Comments
 (0)