Skip to content

Commit 928a4e7

Browse files
committed
resolveJsonModule as baseline test
1 parent 4b13406 commit 928a4e7

12 files changed

+623
-115
lines changed
Lines changed: 50 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: with resolveJsonModule option on project resolveJsonModuleAndComposite", () => {
33
let projFs: vfs.FileSystem;
4-
const allExpectedOutputs = ["/src/dist/src/index.js", "/src/dist/src/index.d.ts", "/src/dist/src/hello.json"];
54
before(() => {
65
projFs = loadProjectFromDisk("tests/projects/resolveJsonModuleAndComposite");
76
});
@@ -10,108 +9,64 @@ namespace ts {
109
projFs = undefined!; // Release the contents
1110
});
1211

13-
function verifyProjectWithResolveJsonModule(configFile: string, ...expectedDiagnosticMessages: fakes.ExpectedDiagnostic[]) {
14-
const fs = projFs.shadow();
15-
verifyProjectWithResolveJsonModuleWithFs(fs, configFile, allExpectedOutputs, ...expectedDiagnosticMessages);
16-
}
17-
18-
function verifyProjectWithResolveJsonModuleWithFs(fs: vfs.FileSystem, configFile: string, allExpectedOutputs: readonly string[], ...expectedDiagnosticMessages: fakes.ExpectedDiagnostic[]) {
19-
const host = fakes.SolutionBuilderHost.create(fs);
20-
const builder = createSolutionBuilder(host, [configFile], { dry: false, force: false, verbose: false });
21-
builder.build();
22-
host.assertDiagnosticMessages(...expectedDiagnosticMessages);
23-
if (!expectedDiagnosticMessages.length) {
24-
// Check for outputs. Not an exhaustive list
25-
verifyOutputsPresent(fs, allExpectedOutputs);
26-
}
27-
}
28-
29-
it("with resolveJsonModule and include only", () => {
30-
verifyProjectWithResolveJsonModule(
31-
"/src/tsconfig_withInclude.json",
32-
{
33-
message: [
34-
Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern,
35-
"/src/src/hello.json",
36-
"/src/tsconfig_withInclude.json"
37-
],
38-
location: expectedLocationIndexOf(projFs, "/src/src/index.ts", `"./hello.json"`)
39-
}
40-
);
12+
verifyTsc({
13+
scenario: "resolveJsonModule",
14+
subScenario: "include only",
15+
fs: () => projFs,
16+
commandLineArgs: ["--b", "/src/tsconfig_withInclude.json"],
4117
});
4218

43-
it("with resolveJsonModule and include of *.json along with other include", () => {
44-
verifyProjectWithResolveJsonModule("/src/tsconfig_withIncludeOfJson.json");
19+
verifyTsc({
20+
scenario: "resolveJsonModule",
21+
subScenario: "include of json along with other include",
22+
fs: () => projFs,
23+
commandLineArgs: ["--b", "/src/tsconfig_withIncludeOfJson.json"],
4524
});
4625

47-
it("with resolveJsonModule and include of *.json along with other include and file name matches ts file", () => {
48-
const fs = projFs.shadow();
49-
fs.rimrafSync("/src/src/hello.json");
50-
fs.writeFileSync("/src/src/index.json", JSON.stringify({ hello: "world" }));
51-
fs.writeFileSync("/src/src/index.ts", `import hello from "./index.json"
26+
verifyTsc({
27+
scenario: "resolveJsonModule",
28+
subScenario: "include of json along with other include and file name matches ts file",
29+
fs: () => projFs,
30+
commandLineArgs: ["--b", "/src/tsconfig_withIncludeOfJson.json"],
31+
modifyFs: fs => {
32+
fs.rimrafSync("/src/src/hello.json");
33+
fs.writeFileSync("/src/src/index.json", JSON.stringify({ hello: "world" }));
34+
fs.writeFileSync("/src/src/index.ts", `import hello from "./index.json"
5235
5336
export default hello.hello`);
54-
const allExpectedOutputs = ["/src/dist/src/index.js", "/src/dist/src/index.d.ts", "/src/dist/src/index.json"];
55-
verifyProjectWithResolveJsonModuleWithFs(
56-
fs,
57-
"/src/tsconfig_withIncludeOfJson.json",
58-
allExpectedOutputs,
59-
errorDiagnostic([Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files, "/src/dist/src/index.d.ts"])
60-
);
37+
},
6138
});
6239

63-
it("with resolveJsonModule and files containing json file", () => {
64-
verifyProjectWithResolveJsonModule("/src/tsconfig_withFiles.json");
40+
verifyTsc({
41+
scenario: "resolveJsonModule",
42+
subScenario: "files containing json file",
43+
fs: () => projFs,
44+
commandLineArgs: ["--b", "/src/tsconfig_withFiles.json"],
6545
});
6646

67-
it("with resolveJsonModule and include and files", () => {
68-
verifyProjectWithResolveJsonModule("/src/tsconfig_withIncludeAndFiles.json");
47+
verifyTsc({
48+
scenario: "resolveJsonModule",
49+
subScenario: "include and files",
50+
fs: () => projFs,
51+
commandLineArgs: ["--b", "/src/tsconfig_withIncludeAndFiles.json"],
6952
});
7053

71-
it("with resolveJsonModule and sourceMap", () => {
72-
const { fs, tick } = getFsWithTime(projFs);
73-
const configFile = "src/tsconfig_withFiles.json";
74-
replaceText(fs, configFile, `"composite": true,`, `"composite": true, "sourceMap": true,`);
75-
const host = fakes.SolutionBuilderHost.create(fs);
76-
let builder = createSolutionBuilder(host, [configFile], { verbose: true });
77-
builder.build();
78-
host.assertDiagnosticMessages(
79-
getExpectedDiagnosticForProjectsInBuild(configFile),
80-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, configFile, "src/dist/src/index.js"],
81-
[Diagnostics.Building_project_0, `/${configFile}`]
82-
);
83-
verifyOutputsPresent(fs, [...allExpectedOutputs, "/src/dist/src/index.js.map"]);
84-
host.clearDiagnostics();
85-
builder = createSolutionBuilder(host, [configFile], { verbose: true });
86-
tick();
87-
builder.build();
88-
host.assertDiagnosticMessages(
89-
getExpectedDiagnosticForProjectsInBuild(configFile),
90-
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, configFile, "src/src/index.ts", "src/dist/src/index.js"]
91-
);
54+
verifyTscIncrementalEdits({
55+
scenario: "resolveJsonModule",
56+
subScenario: "sourcemap",
57+
fs: () => projFs,
58+
commandLineArgs: ["--b", "src/tsconfig_withFiles.json", "--verbose"],
59+
modifyFs: fs => replaceText(fs, "src/tsconfig_withFiles.json", `"composite": true,`, `"composite": true, "sourceMap": true,`),
60+
incrementalScenarios: [noChangeRun]
9261
});
9362

94-
it("with resolveJsonModule and without outDir", () => {
95-
const { fs, tick } = getFsWithTime(projFs);
96-
const configFile = "src/tsconfig_withFiles.json";
97-
replaceText(fs, configFile, `"outDir": "dist",`, "");
98-
const host = fakes.SolutionBuilderHost.create(fs);
99-
let builder = createSolutionBuilder(host, [configFile], { verbose: true });
100-
builder.build();
101-
host.assertDiagnosticMessages(
102-
getExpectedDiagnosticForProjectsInBuild(configFile),
103-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, configFile, "src/src/index.js"],
104-
[Diagnostics.Building_project_0, `/${configFile}`]
105-
);
106-
verifyOutputsPresent(fs, ["/src/src/index.js", "/src/src/index.d.ts"]);
107-
host.clearDiagnostics();
108-
builder = createSolutionBuilder(host, [configFile], { verbose: true });
109-
tick();
110-
builder.build();
111-
host.assertDiagnosticMessages(
112-
getExpectedDiagnosticForProjectsInBuild(configFile),
113-
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, configFile, "src/src/index.ts", "src/src/index.js"]
114-
);
63+
verifyTscIncrementalEdits({
64+
scenario: "resolveJsonModule",
65+
subScenario: "without outDir",
66+
fs: () => projFs,
67+
commandLineArgs: ["--b", "src/tsconfig_withFiles.json", "--verbose"],
68+
modifyFs: fs => replaceText(fs, "src/tsconfig_withFiles.json", `"outDir": "dist",`, ""),
69+
incrementalScenarios: [noChangeRun]
11570
});
11671
});
11772

@@ -125,32 +80,12 @@ export default hello.hello`);
12580
projFs = undefined!; // Release the contents
12681
});
12782

128-
it("when importing json module from project reference", () => {
129-
const expectedOutput = "/src/main/index.js";
130-
const { fs, tick } = getFsWithTime(projFs);
131-
const configFile = "src/tsconfig.json";
132-
const stringsConfigFile = "src/strings/tsconfig.json";
133-
const mainConfigFile = "src/main/tsconfig.json";
134-
const host = fakes.SolutionBuilderHost.create(fs);
135-
let builder = createSolutionBuilder(host, [configFile], { verbose: true });
136-
builder.build();
137-
host.assertDiagnosticMessages(
138-
getExpectedDiagnosticForProjectsInBuild(stringsConfigFile, mainConfigFile, configFile),
139-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, stringsConfigFile, "src/strings/tsconfig.tsbuildinfo"],
140-
[Diagnostics.Building_project_0, `/${stringsConfigFile}`],
141-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, mainConfigFile, "src/main/index.js"],
142-
[Diagnostics.Building_project_0, `/${mainConfigFile}`],
143-
);
144-
verifyOutputsPresent(fs, [expectedOutput]);
145-
host.clearDiagnostics();
146-
builder = createSolutionBuilder(host, [configFile], { verbose: true });
147-
tick();
148-
builder.build();
149-
host.assertDiagnosticMessages(
150-
getExpectedDiagnosticForProjectsInBuild(stringsConfigFile, mainConfigFile, configFile),
151-
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, stringsConfigFile, "src/strings/foo.json", "src/strings/tsconfig.tsbuildinfo"],
152-
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, mainConfigFile, "src/main/index.ts", "src/main/index.js"],
153-
);
83+
verifyTscIncrementalEdits({
84+
scenario: "resolveJsonModule",
85+
subScenario: "importing json module from project reference",
86+
fs: () => projFs,
87+
commandLineArgs: ["--b", "src/tsconfig.json", "--verbose"],
88+
incrementalScenarios: [noChangeRun]
15489
});
15590
});
15691
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//// [/lib/initial-buildOutput.txt]
2+
/lib/tsc --b /src/tsconfig_withFiles.json
3+
exitCode:: ExitStatus.Success
4+
5+
6+
//// [/src/dist/src/hello.d.ts]
7+
export declare const hello: string;
8+
9+
10+
//// [/src/dist/src/hello.json]
11+
{
12+
"hello": "world"
13+
}
14+
15+
16+
//// [/src/dist/src/index.d.ts]
17+
declare const _default: string;
18+
export default _default;
19+
20+
21+
//// [/src/dist/src/index.js]
22+
"use strict";
23+
var __importDefault = (this && this.__importDefault) || function (mod) {
24+
return (mod && mod.__esModule) ? mod : { "default": mod };
25+
};
26+
exports.__esModule = true;
27+
var hello_json_1 = __importDefault(require("./hello.json"));
28+
exports["default"] = hello_json_1["default"].hello;
29+
30+
31+
//// [/src/dist/tsconfig_withFiles.tsbuildinfo]
32+
{
33+
"program": {
34+
"fileInfos": {
35+
"../../lib/lib.d.ts": {
36+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
37+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };"
38+
},
39+
"../src/hello.json": {
40+
"version": "6651571919-{\n \"hello\": \"world\"\n}",
41+
"signature": "-4341462827-export declare const hello: string;\r\n"
42+
},
43+
"../src/index.ts": {
44+
"version": "-27703454282-import hello from \"./hello.json\"\n\nexport default hello.hello",
45+
"signature": "-1680156224-declare const _default: string;\r\nexport default _default;\r\n"
46+
}
47+
},
48+
"options": {
49+
"composite": true,
50+
"moduleResolution": 2,
51+
"module": 1,
52+
"resolveJsonModule": true,
53+
"esModuleInterop": true,
54+
"allowSyntheticDefaultImports": true,
55+
"outDir": "./",
56+
"skipDefaultLibCheck": true,
57+
"configFilePath": "../tsconfig_withFiles.json"
58+
},
59+
"referencedMap": {
60+
"../src/index.ts": [
61+
"../src/hello.json"
62+
]
63+
},
64+
"exportedModulesMap": {},
65+
"semanticDiagnosticsPerFile": [
66+
"../../lib/lib.d.ts",
67+
"../src/hello.json",
68+
"../src/index.ts"
69+
]
70+
},
71+
"version": "FakeTSVersion"
72+
}
73+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//// [/lib/initial-buildOutput.txt]
2+
/lib/tsc --b src/tsconfig.json --verbose
3+
12:01:00 AM - Projects in this build:
4+
* src/strings/tsconfig.json
5+
* src/main/tsconfig.json
6+
* src/tsconfig.json
7+
8+
12:01:00 AM - Project 'src/strings/tsconfig.json' is out of date because output file 'src/strings/tsconfig.tsbuildinfo' does not exist
9+
10+
12:01:00 AM - Building project '/src/strings/tsconfig.json'...
11+
12+
12:01:00 AM - Project 'src/main/tsconfig.json' is out of date because output file 'src/main/index.js' does not exist
13+
14+
12:01:00 AM - Building project '/src/main/tsconfig.json'...
15+
16+
exitCode:: ExitStatus.Success
17+
18+
19+
//// [/src/main/index.d.ts]
20+
export {};
21+
22+
23+
//// [/src/main/index.js]
24+
"use strict";
25+
Object.defineProperty(exports, "__esModule", { value: true });
26+
var foo_json_1 = require("../strings/foo.json");
27+
console.log(foo_json_1.foo);
28+
29+
30+
//// [/src/main/tsconfig.tsbuildinfo]
31+
{
32+
"program": {
33+
"fileInfos": {
34+
"../../lib/lib.d.ts": {
35+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
36+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };"
37+
},
38+
"../strings/foo.json": {
39+
"version": "-1457151099-export declare const foo: string;\r\n",
40+
"signature": "-1457151099-export declare const foo: string;\r\n"
41+
},
42+
"./index.ts": {
43+
"version": "-4651661680-import { foo } from '../strings/foo.json';\n\nconsole.log(foo);",
44+
"signature": "-4882119183-export {};\r\n"
45+
}
46+
},
47+
"options": {
48+
"target": 1,
49+
"module": 1,
50+
"rootDir": "..",
51+
"composite": true,
52+
"resolveJsonModule": true,
53+
"strict": true,
54+
"esModuleInterop": true,
55+
"configFilePath": "./tsconfig.json"
56+
},
57+
"referencedMap": {
58+
"./index.ts": [
59+
"../strings/foo.d.ts"
60+
]
61+
},
62+
"exportedModulesMap": {},
63+
"semanticDiagnosticsPerFile": [
64+
"../../lib/lib.d.ts",
65+
"../strings/foo.json",
66+
"./index.ts"
67+
]
68+
},
69+
"version": "FakeTSVersion"
70+
}
71+
72+
//// [/src/strings/foo.d.ts]
73+
export declare const foo: string;
74+
75+
76+
//// [/src/strings/tsconfig.tsbuildinfo]
77+
{
78+
"program": {
79+
"fileInfos": {
80+
"../../lib/lib.d.ts": {
81+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
82+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };"
83+
},
84+
"./foo.json": {
85+
"version": "4395333385-{\n \"foo\": \"bar baz\"\n}",
86+
"signature": "-1457151099-export declare const foo: string;\r\n"
87+
}
88+
},
89+
"options": {
90+
"target": 1,
91+
"module": 1,
92+
"rootDir": "..",
93+
"composite": true,
94+
"resolveJsonModule": true,
95+
"strict": true,
96+
"esModuleInterop": true,
97+
"configFilePath": "./tsconfig.json"
98+
},
99+
"referencedMap": {},
100+
"exportedModulesMap": {},
101+
"semanticDiagnosticsPerFile": [
102+
"../../lib/lib.d.ts",
103+
"./foo.json"
104+
]
105+
},
106+
"version": "FakeTSVersion"
107+
}
108+

0 commit comments

Comments
 (0)