Repository navigation
Expand file tree
/
Copy pathhtml.integration.test.ts
More file actions
48 lines (39 loc) · 2 KB
/
Copy pathhtml.integration.test.ts
File metadata and controls
48 lines (39 loc) · 2 KB
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
import path from "path";
import ts from "typescript";
describe("HTML contracts", () => {
const projectDir = path.resolve(__dirname, "../../..");
const fixture = path.join(__dirname, "fixtures/html/options.ts");
test.each(["source", "package"])(
"checks static entrypoint and full configuration options through the %s API",
mode => {
const config = ts.readConfigFile(path.join(projectDir, "tsconfig.json"), ts.sys.readFile);
const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, projectDir);
expect(config.error).toBeUndefined();
expect(parsed.errors).toEqual([]);
const options: ts.CompilerOptions = {
...(mode === "source" ? parsed.options : {}),
module: ts.ModuleKind.ESNext,
moduleResolution: ts.ModuleResolutionKind.Bundler,
target: ts.ScriptTarget.ESNext,
jsx: ts.JsxEmit.ReactJSX,
strict: true,
noEmit: true,
skipLibCheck: mode === "source",
types: ["node", "chrome"],
};
const host = ts.createCompilerHost(options);
const program = ts.createProgram([fixture], options, host);
const diagnostics = ts.getPreEmitDiagnostics(program).map(diagnostic => {
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
const position = diagnostic.file?.getLineAndCharacterOfPosition(diagnostic.start ?? 0);
return `${diagnostic.file?.fileName ?? "compiler"}:${(position?.line ?? 0) + 1}: ${message}`;
});
expect(diagnostics).toEqual([]);
const apiFile = ts.resolveModuleName("adnbn", fixture, options, host).resolvedModule?.resolvedFileName;
expect(apiFile).toBe(
path.join(projectDir, mode === "source" ? "src/index.ts" : "dist/index.d.ts").replace(/\\/g, "/")
);
},
30_000
);
});