-
Notifications
You must be signed in to change notification settings - Fork 28
/
cli.test.js
88 lines (75 loc) · 2.58 KB
/
cli.test.js
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
88
import { Project } from 'fixturify-project';
import { join } from 'path';
import { describe, it, expect, beforeAll } from 'vitest';
import { execa } from 'execa';
const cliPath = join(__dirname, 'cli.js');
describe('cli', () => {
let project;
beforeAll(async () => {
project = new Project({
files: {
CODEOWNERS: `*.js @beaugunderson
tests/ @mansona`,
'index.js': '// a default file',
tests: {
'index.js': '// a default test file',
},
},
});
await project.write();
});
describe('audit', () => {
it('audits the files', async () => {
const result = await execa({ cwd: project.baseDir })`${cliPath} audit`;
expect(result.exitCode).to.equal(0);
expect(result.stdout).to.toMatchInlineSnapshot(`
"CODEOWNERS nobody
index.js @beaugunderson
package.json nobody
tests nobody
tests/index.js @mansona"
`);
});
it('audits the files with --unowned', async () => {
const result = await execa({ cwd: project.baseDir })`${cliPath} audit --unowned`;
expect(result.exitCode).to.equal(0);
expect(result.stdout).to.toMatchInlineSnapshot(`
"CODEOWNERS
package.json
tests"
`);
});
});
describe('verify', () => {
it('verifies codeowners for a path', async () => {
const result = await execa({
cwd: project.baseDir,
})`${cliPath} verify index.js @beaugunderson`;
expect(result.exitCode).to.equal(0);
expect(result.stdout).to.toMatchInlineSnapshot(`"index.js @beaugunderson"`);
});
it('shows an error if you pass the wrong user', async () => {
let result;
try {
result = await execa({ cwd: project.baseDir })`${cliPath} verify index.js @mansona`;
} catch (error) {
expect(error.exitCode).to.equal(1);
expect(error.stderr).to.toMatchInlineSnapshot(
`"None of the users/teams specified own the path index.js"`
);
expect(error.stdout).to.be.empty;
}
// this verifies that the command actually failed and we hit the try/catch above
expect(result).to.be.undefined;
});
});
describe('list', () => {
it('shows the codeowner for a file', async () => {
const result = await execa({
cwd: project.baseDir,
})`${cliPath} list index.js`;
expect(result.exitCode).to.equal(0);
expect(result.stdout).to.toMatchInlineSnapshot(`"@beaugunderson"`);
});
});
});