-
Notifications
You must be signed in to change notification settings - Fork 9
/
test-utils.ts
30 lines (27 loc) · 980 Bytes
/
test-utils.ts
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
import { posix, relative } from 'path';
import * as ts from 'typescript';
export function typescriptDiagnostics(filename: string) {
const program = ts.createProgram([filename], {
target: ts.ScriptTarget.ESNext,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
jsx: ts.JsxEmit.Preserve,
strict: true,
baseUrl: __dirname,
paths: {
'@glitz/*': ['./packages/*/src'],
'@glitz/type': ['./packages/type'],
},
noEmit: true,
});
const diagnostics = ts.getPreEmitDiagnostics(program);
return diagnostics
.filter(diagnostic => diagnostic.file && diagnostic.start)
.map(diagnostic => {
const { line, character } = diagnostic.file!.getLineAndCharacterOfPosition(diagnostic.start!);
const path = relative(__dirname, diagnostic.file!.fileName);
return `${posix.join(...path.split('\\'))} ${line}:${character} - ${ts.flattenDiagnosticMessageText(
diagnostic.messageText,
'\n',
)}`;
});
}