forked from nonara/ts-patch
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransformer-extras.test.ts
More file actions
89 lines (80 loc) · 2.76 KB
/
Copy pathtransformer-extras.test.ts
File metadata and controls
89 lines (80 loc) · 2.76 KB
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
89
import { prepareTestProject } from '../src/project';
import { execSync } from 'child_process';
import path from 'path';
/* ****************************************************************************************************************** *
* Tests
* ****************************************************************************************************************** */
describe('Transformer Extras addDiagnostics', () => {
let projectPath: string;
let output: string[];
beforeAll(() => {
const prepRes = prepareTestProject({ projectName: 'transformer-extras' });
projectPath = prepRes.tmpProjectPath;
let commandOutput: string;
try {
commandOutput = execSync('ts-node src/compiler.ts', {
cwd: projectPath,
env: {
...process.env,
PATH: `${projectPath}/node_modules/.bin${path.delimiter}${process.env.PATH}`
}
}).toString();
}
catch (e) {
const err = new Error(e.stdout.toString() + '\n' + e.stderr.toString());
console.error(err);
throw e;
}
output = commandOutput.trim().split('\n');
});
test('Provide emit result diagnostics and semantic diagnostics and merge it with original diagnostics', () => {
const [ emitResultDiagnosticsText, semanticDiagnosticsText ] = output;
const emitResultDiagnostics = JSON.parse(emitResultDiagnosticsText.split('emitResultDiagnostics:')[1]);
const semanticDiagnostics = JSON.parse(semanticDiagnosticsText.split('semanticDiagnostics:')[1]);
const filePath = path.join(projectPath, 'src/index.ts');
const expectedEmitResultDiagnostics = [
{
file: expect.stringContaining(filePath),
code: 42,
start: 0,
length: 1,
messageText: 'It\'s a warning message!',
category: 0
}, {
file: expect.stringContaining(filePath),
code: 42,
start: 1,
length: 2,
messageText: 'It\'s an error message!',
category: 1
}, {
file: expect.stringContaining(filePath),
code: 42,
start: 2,
length: 3,
messageText: 'It\'s a suggestion message!',
category: 2
}, {
file: expect.stringContaining(filePath),
code: 42,
start: 3,
length: 4,
messageText: 'It\'s a message!',
category: 3
}
];
const expectedSemanticDiagnostics = [
{
file: expect.stringContaining(filePath),
code: 2322,
category: 1,
length: 1,
messageText: 'Type \'number\' is not assignable to type \'string\'.',
start: 13,
},
...expectedEmitResultDiagnostics,
]
expect(emitResultDiagnostics).toEqual(expectedEmitResultDiagnostics);
expect(semanticDiagnostics).toEqual(expectedSemanticDiagnostics);
});
});