Skip to content

Commit

Permalink
Merge pull request #48 from mansona/new-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beaugunderson authored Nov 19, 2024
2 parents d0f5642 + 75b8d3b commit 67b7542
Show file tree
Hide file tree
Showing 5 changed files with 7,358 additions and 1,364 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@ module.exports = {
'no-plusplus': 'off',
'no-restricted-syntax': 'off',
'prettier/prettier': ['error', { singleQuote: true, printWidth: 99 }],
'import/no-extraneous-dependencies': ['error', { devDependencies: ['**/*.test.js'] }],
},
overrides: [{
files: ['*.test.js'],
rules: {
'no-unused-expressions': 'off'
}
}]
};
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ program

// if verifiedOwners is empty, exit with error
if (verifiedOwners.length < 1) {
console.log(`None of the users/teams specified own the path ${checkPath}`);
console.error(`None of the users/teams specified own the path ${checkPath}`);
process.exit(1);
}

Expand Down
77 changes: 77 additions & 0 deletions cli.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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;
});
});
});
Loading

0 comments on commit 67b7542

Please sign in to comment.