Skip to content

Commit

Permalink
test: add unit test for convertDiagnostic
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Aug 30, 2022
1 parent b05b1f2 commit 2d3cfe3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions __tests__/diagnostics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,33 @@ import { red } from "colors/safe";

import { makeContext } from "./fixtures/context";
import { setTypescriptModule } from "../src/tsproxy";
import { printDiagnostics } from "../src/diagnostics";
import { convertDiagnostic, printDiagnostics } from "../src/diagnostics";

setTypescriptModule(ts);

const tsDiagnostic = {
file: undefined,
start: undefined,
length: undefined,
messageText: "Compiler option 'include' requires a value of type Array.",
category: ts.DiagnosticCategory.Error,
code: 5024,
reportsUnnecessary: undefined,
reportsDeprecated: undefined,
};

const diagnostic = {
flatMessage: "Compiler option 'include' requires a value of type Array.",
formatted: "\x1B[91merror\x1B[0m\x1B[90m TS5024: \x1B[0mCompiler option 'include' requires a value of type Array.\n",
category: ts.DiagnosticCategory.Error,
code: 5024,
type: 'config'
type: "config",
};

test("convertDiagnostic", () => {
expect(convertDiagnostic("config", [tsDiagnostic])).toStrictEqual([diagnostic]);
});

test("printDiagnostics - categories", () => {
const context = makeContext();

Expand Down

0 comments on commit 2d3cfe3

Please sign in to comment.