forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ts
More file actions
55 lines (48 loc) · 1.63 KB
/
setup.ts
File metadata and controls
55 lines (48 loc) · 1.63 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
import * as ts from "typescript";
import * as util from "./util";
declare global {
namespace jest {
interface Matchers<R> {
toThrowExactError(error: Error): R;
toHaveDiagnostics(): R;
}
}
}
expect.extend({
toThrowExactError(callback: () => void, error: Error): jest.CustomMatcherResult {
if (this.isNot) {
return { pass: true, message: () => "Inverted toThrowExactError is not implemented" };
}
let executionError: Error | undefined;
try {
callback();
} catch (err) {
executionError = err;
}
// TODO:
if (util.expectToBeDefined(executionError)) {
expect(executionError.message).toContain(error.message);
}
return { pass: true, message: () => "" };
},
toHaveDiagnostics(diagnostics: ts.Diagnostic[]): jest.CustomMatcherResult {
expect(diagnostics).toBeInstanceOf(Array);
// @ts-ignore
const matcherHint = this.utils.matcherHint("toHaveDiagnostics", undefined, "", this);
const diagnosticMessages = ts.formatDiagnosticsWithColorAndContext(diagnostics, {
getCurrentDirectory: () => "",
getCanonicalFileName: fileName => fileName,
getNewLine: () => "\n",
});
return {
pass: diagnostics.length > 0,
message: () => {
return (
matcherHint +
"\n\n" +
(this.isNot ? diagnosticMessages : `Received: ${this.utils.printReceived(diagnostics)}\n`)
);
},
};
},
});