forked from ezolenko/rollup-plugin-typescript2
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse-tsconfig.spec.ts
67 lines (49 loc) · 1.93 KB
/
parse-tsconfig.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { test, expect } from "@jest/globals";
import * as path from "path";
import { normalizePath as normalize } from "@rollup/pluginutils";
import { makeOptions } from "./fixtures/options";
import { makeContext } from "./fixtures/context";
import { parseTsConfig } from "../src/parse-tsconfig";
const local = (x: string) => normalize(path.resolve(__dirname, x));
const defaultOpts = makeOptions("", "");
test("parseTsConfig", () => {
const context = makeContext();
parseTsConfig(context, defaultOpts);
expect(context.error).not.toBeCalled();
});
test("parseTsConfig - incompatible module", () => {
const context = makeContext();
parseTsConfig(context, {
...defaultOpts,
tsconfigOverride: { compilerOptions: { module: "none" } },
});
expect(context.error).toHaveBeenLastCalledWith(expect.stringContaining("Incompatible tsconfig option. Module resolves to 'None'. This is incompatible with Rollup, please use"));
});
test("parseTsConfig - tsconfig errors", () => {
const context = makeContext();
parseTsConfig(context, {
...defaultOpts,
tsconfigOverride: {
include: "should-be-an-array",
},
});
expect(context.error).toHaveBeenLastCalledWith(expect.stringContaining("Compiler option 'include' requires a value of type Array"));
});
test("parseTsConfig - failed to open", () => {
const context = makeContext();
const nonExistentTsConfig = "non-existent-tsconfig";
parseTsConfig(context, {
...defaultOpts,
tsconfig: nonExistentTsConfig,
})
expect(context.error).toHaveBeenLastCalledWith(expect.stringContaining(`failed to open '${nonExistentTsConfig}`));
});
test("parseTsConfig - failed to parse", () => {
const context = makeContext();
const notTsConfigPath = local("fixtures/options.ts"); // a TS file should fail to parse
parseTsConfig(context, {
...defaultOpts,
tsconfig: notTsConfigPath,
})
expect(context.error).toHaveBeenLastCalledWith(expect.stringContaining(`failed to parse '${notTsConfigPath}'`));
});