-
Notifications
You must be signed in to change notification settings - Fork 7
/
typescript-compile-error.spec.ts
38 lines (31 loc) · 1.33 KB
/
typescript-compile-error.spec.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
31
32
33
34
35
36
37
38
import { describe, expect, it } from "vitest";
import { TypeScriptCompileError } from "./typescript-compile-error";
describe("TypeScriptCompileError", () => {
describe("fromError", () => {
const testError = new Error("Test Error");
it("should create a TypeScriptCompileError from an instance of Error", () => {
const tscError = TypeScriptCompileError.fromError(testError);
expect(tscError.name).toStrictEqual(
TypeScriptCompileError.prototype.constructor.name
);
expect(tscError.message).toContain(
"TypeScriptLoader failed to compile TypeScript"
);
expect(tscError.message).toContain("Test Error");
expect(tscError.stack).toBe(testError.stack);
});
it("should replace the legacy tsc error string", () => {
const testMsg =
"TypeScript compiler encountered syntax errors while transpiling. Errors: ";
const legacyError = new Error(testMsg);
const tscError = TypeScriptCompileError.fromError(legacyError);
expect(tscError).not.toContainEqual(testMsg);
});
it("should replace the tsc error string", () => {
const testMsg = "⨯ Unable to compile TypeScript:";
const newError = new Error(testMsg);
const tscError = TypeScriptCompileError.fromError(newError);
expect(tscError).not.toContainEqual(testMsg);
});
});
});