Skip to content

Commit 2d3cfe3

Browse files
committed
test: add unit test for convertDiagnostic
- this was previously only covered in integration tests - since unit tests don't currently touch `index` or `tscache`, and `convertDiagnostic` was previously in `tscache` - another reason why consolidating these functions into one file made sense
1 parent b05b1f2 commit 2d3cfe3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

__tests__/diagnostics.spec.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,33 @@ import { red } from "colors/safe";
44

55
import { makeContext } from "./fixtures/context";
66
import { setTypescriptModule } from "../src/tsproxy";
7-
import { printDiagnostics } from "../src/diagnostics";
7+
import { convertDiagnostic, printDiagnostics } from "../src/diagnostics";
88

99
setTypescriptModule(ts);
1010

11+
const tsDiagnostic = {
12+
file: undefined,
13+
start: undefined,
14+
length: undefined,
15+
messageText: "Compiler option 'include' requires a value of type Array.",
16+
category: ts.DiagnosticCategory.Error,
17+
code: 5024,
18+
reportsUnnecessary: undefined,
19+
reportsDeprecated: undefined,
20+
};
21+
1122
const diagnostic = {
1223
flatMessage: "Compiler option 'include' requires a value of type Array.",
1324
formatted: "\x1B[91merror\x1B[0m\x1B[90m TS5024: \x1B[0mCompiler option 'include' requires a value of type Array.\n",
1425
category: ts.DiagnosticCategory.Error,
1526
code: 5024,
16-
type: 'config'
27+
type: "config",
1728
};
1829

30+
test("convertDiagnostic", () => {
31+
expect(convertDiagnostic("config", [tsDiagnostic])).toStrictEqual([diagnostic]);
32+
});
33+
1934
test("printDiagnostics - categories", () => {
2035
const context = makeContext();
2136

0 commit comments

Comments
 (0)