Skip to content

Commit d9593ea

Browse files
committed
test: add resultModifier test case
1 parent 1ff38c5 commit d9593ea

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

__tests__/_errors.mock.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,14 @@ index2.ts:1:1 - Unexpected error.
144144
${extendedDiagnostics}
145145
${verboseFooter}`;
146146

147-
export default { PRETTY, NOT_PRETTY };
147+
const MULTILINE_SOURCE = `
148+
index.ts(1,1): error TS1000: Unexpected error.
149+
150+
1 unexpected_error() as UnexpectedError<
151+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152+
2 unexpected_error
153+
~~~~~~~~~~~~~~~~~~~~
154+
3 >;
155+
~~~`.trimStart();
156+
157+
export default { PRETTY, NOT_PRETTY, MULTILINE_SOURCE };

__tests__/src/blueprints/Parser.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ describe('blueprint > Parser', () => {
66
let matcher: RegExp;
77
let matcherKeys: string[] = [];
88
let inputModifier: jest.Mock;
9+
let resultModifier: jest.Mock;
910
let parser: Parser;
1011

1112
beforeEach(() => {
1213
input = '12';
1314
matcher = /^(\d)(\d)/g;
1415
matcherKeys = ['first', 'second'];
1516
inputModifier = jest.fn((input: string) => input);
16-
parser = new Parser(matcher, matcherKeys, inputModifier);
17+
resultModifier = jest.fn((result: object) => result);
18+
parser = new Parser(matcher, matcherKeys, inputModifier, resultModifier);
1719
});
1820

1921
describe('instantiation', () => {
@@ -51,5 +53,16 @@ describe('blueprint > Parser', () => {
5153
expect(inputModifier).toHaveBeenCalledTimes(1);
5254
expect(inputModifier).toHaveBeenLastCalledWith(input);
5355
});
56+
57+
it('should call resultModifier correctly', () => {
58+
expect(resultModifier).toHaveBeenCalledTimes(0);
59+
parser.parse(input);
60+
expect(resultModifier).toHaveBeenCalledTimes(1);
61+
expect(resultModifier).toHaveBeenLastCalledWith({
62+
_match: input,
63+
first: '1',
64+
second: '2'
65+
});
66+
});
5467
});
5568
});

__tests__/src/parsers/default-parser.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,32 @@ describe('parsers > defaultParser', () => {
2424
EXPECTED_RESULTS
2525
);
2626
});
27+
28+
it('should return multiline source correctly', () => {
29+
expect(defaultParser.parse(ERROR_MOCKS.MULTILINE_SOURCE)).toEqual([
30+
{
31+
_match: ERROR_MOCKS.MULTILINE_SOURCE,
32+
file: 'index.ts',
33+
errorCode: 'TS1000',
34+
column: '1',
35+
line: '1',
36+
message: 'Unexpected error.',
37+
source: [
38+
'1 unexpected_error() as UnexpectedError<',
39+
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~',
40+
'2 unexpected_error',
41+
' ~~~~~~~~~~~~~~~~~~~~',
42+
'3 >;',
43+
' ~~~'
44+
].join('\n'),
45+
sourceClean: [
46+
'unexpected_error() as UnexpectedError<',
47+
' unexpected_error',
48+
'>;'
49+
].join('\n')
50+
}
51+
]);
52+
});
2753
});
2854

2955
describe('pretty format disabled', () => {

0 commit comments

Comments
 (0)