From 2d3cfe32bd1164b6e9c7985f754e657e7c010002 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Tue, 30 Aug 2022 16:46:08 -0400 Subject: [PATCH] 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 --- __tests__/diagnostics.spec.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/__tests__/diagnostics.spec.ts b/__tests__/diagnostics.spec.ts index 141cc8bf..cd57dcdf 100644 --- a/__tests__/diagnostics.spec.ts +++ b/__tests__/diagnostics.spec.ts @@ -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();