Skip to content

Commit

Permalink
test: cspell-tools: Add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Jul 14, 2023
1 parent a67ea47 commit bb22d08
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/cspell-tools/src/__snapshots__/app.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,40 @@ exports[`Validate the application > app no args 1`] = `
"log": "",
}
`;
exports[`Validate the application > app shasum 1`] = `
{
"error": "",
"log": "%s,477e8bc9954033392e432fd66f0d4278884bde38 cities.txt",
}
`;
exports[`Validate the application > app shasum check failed 1`] = `
{
"error": "",
"log": "%s,cities.trie: OK
cities.trie.gz: OK
cities.txt: OK
colors.trie: FAILED
colors.txt: OK
sampleCodeDic.txt: OK
shasum: WARNING: 1 computed checksum did NOT match",
}
`;
exports[`Validate the application > app shasum file not found 1`] = `
{
"error": "",
"log": "%s,477e8bc9954033392e432fd66f0d4278884bde38 cities.txt
shasum: unknown.txt: Unable to read file.",
}
`;
exports[`Validate the application > app shasum update 1`] = `
{
"error": "",
"log": "%s,477e8bc9954033392e432fd66f0d4278884bde38 cities.txt
3a6b55a089d018878e8b904f8f19391f2e30b66c colors.txt
",
}
`;
43 changes: 43 additions & 0 deletions packages/cspell-tools/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,47 @@ describe('Validate the application', () => {
expect(mockedCompressFile).toHaveBeenCalledWith('CHANGELOG.md');
expect(mockedCompressFile).toHaveBeenCalledWith('package.json');
});

test('app shasum', async () => {
const commander = getCommander();
const args = argv('shasum', 'cities.txt', '--root=fixtures/dicts');

await expect(app.run(commander, args)).resolves.toBeUndefined();
expect(consoleSpy.consoleOutput()).toMatchSnapshot();
});

test('app shasum file not found', async () => {
const commander = getCommander();
const args = argv('shasum', 'cities.txt', 'unknown.txt', '--root=fixtures/dicts');

await expect(app.run(commander, args)).rejects.toEqual(
new Commander.CommanderError(1, 'Failed Checksum', 'One or more files had issues.')
);
expect(consoleSpy.consoleOutput()).toMatchSnapshot();
});

test('app shasum check failed', async () => {
const commander = getCommander();
const args = argv('shasum', '--check=fixtures/dicts/_checksum-failed.txt', '--root=fixtures/dicts');

await expect(app.run(commander, args)).rejects.toEqual(
new Commander.CommanderError(1, 'Failed Checksum', 'One or more files had issues.')
);
expect(consoleSpy.consoleOutput()).toMatchSnapshot();
});

test('app shasum update', async () => {
const commander = getCommander();
const checksumFile = pathTemp('checksum.txt');
const args = argv(
'shasum',
'--update',
checksumFile,
'--root=fixtures/dicts',
'--list-file=fixtures/dicts/source-files.txt'
);

await expect(app.run(commander, args)).resolves.toBeUndefined();
expect(consoleSpy.consoleOutput()).toMatchSnapshot();
});
});

0 comments on commit bb22d08

Please sign in to comment.