Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Custom reporters support #1643

Merged
merged 31 commits into from
Sep 13, 2021
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
480da2b
adds support for custom reporters
mad-gooze Sep 5, 2021
f3bd668
fix tests for cspell-types
mad-gooze Sep 6, 2021
b0e2046
CR
mad-gooze Sep 7, 2021
26259c2
Merge remote-tracking branch 'origin/main' into customizable-reporters
mad-gooze Sep 9, 2021
685ea3d
simplify emitters types
mad-gooze Sep 9, 2021
70a7e6b
remove typecast from loadReporters
mad-gooze Sep 9, 2021
7e5a38a
add InMemoryReporter
mad-gooze Sep 9, 2021
0e7917e
update jsdoc
mad-gooze Sep 9, 2021
bf86e41
add ApplicationError
mad-gooze Sep 9, 2021
aeaca39
fix tests
mad-gooze Sep 9, 2021
265d8b4
make only result reporter async
mad-gooze Sep 9, 2021
9607d70
wip tests for cspell-json-reporter
mad-gooze Sep 9, 2021
d4c2158
simplify tests
mad-gooze Sep 10, 2021
b776570
fix lint
mad-gooze Sep 10, 2021
6d5a5a3
fix jest thorw check
mad-gooze Sep 10, 2021
cc431d3
complete tests for cspell-json-reporter
mad-gooze Sep 10, 2021
949cefa
fix lint && add docs
mad-gooze Sep 12, 2021
1c652ba
Merge remote-tracking branch 'origin/main' into customizable-reporters
mad-gooze Sep 12, 2021
fef8915
add getLoggerFromReporter
mad-gooze Sep 12, 2021
b408bb5
fix deps
mad-gooze Sep 12, 2021
eb7db0e
remove paths from snapshots
mad-gooze Sep 12, 2021
fb67ea7
add types for InMemoryReporter
mad-gooze Sep 12, 2021
86728a6
fix deps
mad-gooze Sep 12, 2021
25b84a0
fix ts && lint
mad-gooze Sep 12, 2021
8efbb5b
revert package-locks
mad-gooze Sep 12, 2021
80cee10
cspell-json-reporter: write example output to temp
mad-gooze Sep 12, 2021
524931a
fix tests for node 12
mad-gooze Sep 12, 2021
f055173
create output path if it does not exist
mad-gooze Sep 12, 2021
da53732
add some tests for reporters
mad-gooze Sep 12, 2021
029ac78
fix tests
mad-gooze Sep 12, 2021
ae6c53e
fix lint
mad-gooze Sep 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove paths from snapshots
mad-gooze committed Sep 12, 2021
commit eb7db0eac782352de4677ca9a29f642526745a33
63 changes: 4 additions & 59 deletions packages/cspell-json-reporter/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,55 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getReporter saves additional data 1`] = `
Array [
Array [
"/Users/alex-gusev/cspell/packages/cspell-json-reporter/out.json",
"{
\\"issues\\": [
{
\\"text\\": \\"fulll\\",
\\"offset\\": 13,
\\"line\\": {
\\"text\\": \\"This text is fulll of errrorrrs.\\",
\\"offset\\": 0
},
\\"row\\": 1,
\\"col\\": 14,
\\"doc\\": \\"This text is fulll of errrorrrs.\\",
\\"uri\\": \\"text.txt\\",
\\"context\\": {
\\"text\\": \\"This text is fulll of errrorrrs.\\",
\\"offset\\": 0
}
}
],
\\"info\\": [
{
\\"message\\": \\"some warnings\\",
\\"msgType\\": \\"Warning\\"
}
],
\\"debug\\": [],
\\"error\\": [
{
\\"message\\": \\"something went wrong\\",
\\"error\\": {}
}
],
\\"progress\\": [],
\\"result\\": {
\\"files\\": 1,
\\"filesWithIssues\\": [
\\"text.txt\\"
],
\\"issues\\": 2,
\\"errors\\": 1
}
}",
],
Array [
"/Users/alex-gusev/cspell/packages/cspell-json-reporter/out.json",
"{
"{
\\"issues\\": [
{
\\"text\\": \\"fulll\\",
@@ -115,16 +67,11 @@ Array [
\\"issues\\": 2,
\\"errors\\": 1
}
}",
],
]
}"
`;

exports[`getReporter saves json to file 1`] = `
Array [
Array [
"/Users/alex-gusev/cspell/packages/cspell-json-reporter/out.json",
"{
"{
\\"issues\\": [
{
\\"text\\": \\"fulll\\",
@@ -165,9 +112,7 @@ Array [
\\"issues\\": 2,
\\"errors\\": 1
}
}",
],
]
}"
`;

exports[`getReporter throws for invalid config 1`] = `"cspell-json-reporter settings.outFile must be a string"`;
18 changes: 13 additions & 5 deletions packages/cspell-json-reporter/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getReporter } from '.';
import { CSpellReporter, MessageTypes } from '@cspell/cspell-types';
import * as path from 'path';

function runReporter(reporter: CSpellReporter): void {
reporter.debug('foo');
@@ -40,9 +41,7 @@ function runReporter(reporter: CSpellReporter): void {
});
}

jest.mock('fs/promises', () => ({
writeFile: jest.fn().mockResolvedValue(undefined),
}));
jest.mock('fs/promises');
import * as fs from 'fs/promises';

describe('getReporter', () => {
@@ -53,12 +52,21 @@ describe('getReporter', () => {
it('saves json to file', () => {
const reporter = getReporter({ outFile: 'out.json' });
runReporter(reporter);
expect((fs.writeFile as jest.Mock).mock.calls).toMatchSnapshot();
expect(fs.writeFile).toBeCalledTimes(1);

expect((fs.writeFile as jest.Mock).mock.calls[0][0]).toEqual(path.join(process.cwd(), 'out.json'));
expect((fs.writeFile as jest.Mock).mock.calls[0][1]).toMatchSnapshot();
});

it('saves additional data', () => {
const reporter = getReporter({ outFile: 'out.json', verbose: true, debug: true, progress: true });
runReporter(reporter);
expect((fs.writeFile as jest.Mock).mock.calls).toMatchSnapshot();
expect(fs.writeFile).toBeCalledTimes(1);
expect((fs.writeFile as jest.Mock).mock.calls[0][0]).toEqual(path.join(process.cwd(), 'out.json'));
expect((fs.writeFile as jest.Mock).mock.calls[0][1]).toMatchSnapshot();
});

afterEach(() => {
jest.clearAllMocks();
});
});