mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 07:29:16 -05:00
resolveJsonModule as baseline test
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
namespace ts {
|
||||
describe("unittests:: tsbuild:: with resolveJsonModule option on project resolveJsonModuleAndComposite", () => {
|
||||
let projFs: vfs.FileSystem;
|
||||
const allExpectedOutputs = ["/src/dist/src/index.js", "/src/dist/src/index.d.ts", "/src/dist/src/hello.json"];
|
||||
before(() => {
|
||||
projFs = loadProjectFromDisk("tests/projects/resolveJsonModuleAndComposite");
|
||||
});
|
||||
@@ -10,108 +9,64 @@ namespace ts {
|
||||
projFs = undefined!; // Release the contents
|
||||
});
|
||||
|
||||
function verifyProjectWithResolveJsonModule(configFile: string, ...expectedDiagnosticMessages: fakes.ExpectedDiagnostic[]) {
|
||||
const fs = projFs.shadow();
|
||||
verifyProjectWithResolveJsonModuleWithFs(fs, configFile, allExpectedOutputs, ...expectedDiagnosticMessages);
|
||||
}
|
||||
|
||||
function verifyProjectWithResolveJsonModuleWithFs(fs: vfs.FileSystem, configFile: string, allExpectedOutputs: readonly string[], ...expectedDiagnosticMessages: fakes.ExpectedDiagnostic[]) {
|
||||
const host = fakes.SolutionBuilderHost.create(fs);
|
||||
const builder = createSolutionBuilder(host, [configFile], { dry: false, force: false, verbose: false });
|
||||
builder.build();
|
||||
host.assertDiagnosticMessages(...expectedDiagnosticMessages);
|
||||
if (!expectedDiagnosticMessages.length) {
|
||||
// Check for outputs. Not an exhaustive list
|
||||
verifyOutputsPresent(fs, allExpectedOutputs);
|
||||
}
|
||||
}
|
||||
|
||||
it("with resolveJsonModule and include only", () => {
|
||||
verifyProjectWithResolveJsonModule(
|
||||
"/src/tsconfig_withInclude.json",
|
||||
{
|
||||
message: [
|
||||
Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern,
|
||||
"/src/src/hello.json",
|
||||
"/src/tsconfig_withInclude.json"
|
||||
],
|
||||
location: expectedLocationIndexOf(projFs, "/src/src/index.ts", `"./hello.json"`)
|
||||
}
|
||||
);
|
||||
verifyTsc({
|
||||
scenario: "resolveJsonModule",
|
||||
subScenario: "include only",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig_withInclude.json"],
|
||||
});
|
||||
|
||||
it("with resolveJsonModule and include of *.json along with other include", () => {
|
||||
verifyProjectWithResolveJsonModule("/src/tsconfig_withIncludeOfJson.json");
|
||||
verifyTsc({
|
||||
scenario: "resolveJsonModule",
|
||||
subScenario: "include of json along with other include",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig_withIncludeOfJson.json"],
|
||||
});
|
||||
|
||||
it("with resolveJsonModule and include of *.json along with other include and file name matches ts file", () => {
|
||||
const fs = projFs.shadow();
|
||||
fs.rimrafSync("/src/src/hello.json");
|
||||
fs.writeFileSync("/src/src/index.json", JSON.stringify({ hello: "world" }));
|
||||
fs.writeFileSync("/src/src/index.ts", `import hello from "./index.json"
|
||||
verifyTsc({
|
||||
scenario: "resolveJsonModule",
|
||||
subScenario: "include of json along with other include and file name matches ts file",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig_withIncludeOfJson.json"],
|
||||
modifyFs: fs => {
|
||||
fs.rimrafSync("/src/src/hello.json");
|
||||
fs.writeFileSync("/src/src/index.json", JSON.stringify({ hello: "world" }));
|
||||
fs.writeFileSync("/src/src/index.ts", `import hello from "./index.json"
|
||||
|
||||
export default hello.hello`);
|
||||
const allExpectedOutputs = ["/src/dist/src/index.js", "/src/dist/src/index.d.ts", "/src/dist/src/index.json"];
|
||||
verifyProjectWithResolveJsonModuleWithFs(
|
||||
fs,
|
||||
"/src/tsconfig_withIncludeOfJson.json",
|
||||
allExpectedOutputs,
|
||||
errorDiagnostic([Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files, "/src/dist/src/index.d.ts"])
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
it("with resolveJsonModule and files containing json file", () => {
|
||||
verifyProjectWithResolveJsonModule("/src/tsconfig_withFiles.json");
|
||||
verifyTsc({
|
||||
scenario: "resolveJsonModule",
|
||||
subScenario: "files containing json file",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig_withFiles.json"],
|
||||
});
|
||||
|
||||
it("with resolveJsonModule and include and files", () => {
|
||||
verifyProjectWithResolveJsonModule("/src/tsconfig_withIncludeAndFiles.json");
|
||||
verifyTsc({
|
||||
scenario: "resolveJsonModule",
|
||||
subScenario: "include and files",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig_withIncludeAndFiles.json"],
|
||||
});
|
||||
|
||||
it("with resolveJsonModule and sourceMap", () => {
|
||||
const { fs, tick } = getFsWithTime(projFs);
|
||||
const configFile = "src/tsconfig_withFiles.json";
|
||||
replaceText(fs, configFile, `"composite": true,`, `"composite": true, "sourceMap": true,`);
|
||||
const host = fakes.SolutionBuilderHost.create(fs);
|
||||
let builder = createSolutionBuilder(host, [configFile], { verbose: true });
|
||||
builder.build();
|
||||
host.assertDiagnosticMessages(
|
||||
getExpectedDiagnosticForProjectsInBuild(configFile),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, configFile, "src/dist/src/index.js"],
|
||||
[Diagnostics.Building_project_0, `/${configFile}`]
|
||||
);
|
||||
verifyOutputsPresent(fs, [...allExpectedOutputs, "/src/dist/src/index.js.map"]);
|
||||
host.clearDiagnostics();
|
||||
builder = createSolutionBuilder(host, [configFile], { verbose: true });
|
||||
tick();
|
||||
builder.build();
|
||||
host.assertDiagnosticMessages(
|
||||
getExpectedDiagnosticForProjectsInBuild(configFile),
|
||||
[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"]
|
||||
);
|
||||
verifyTscIncrementalEdits({
|
||||
scenario: "resolveJsonModule",
|
||||
subScenario: "sourcemap",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "src/tsconfig_withFiles.json", "--verbose"],
|
||||
modifyFs: fs => replaceText(fs, "src/tsconfig_withFiles.json", `"composite": true,`, `"composite": true, "sourceMap": true,`),
|
||||
incrementalScenarios: [noChangeRun]
|
||||
});
|
||||
|
||||
it("with resolveJsonModule and without outDir", () => {
|
||||
const { fs, tick } = getFsWithTime(projFs);
|
||||
const configFile = "src/tsconfig_withFiles.json";
|
||||
replaceText(fs, configFile, `"outDir": "dist",`, "");
|
||||
const host = fakes.SolutionBuilderHost.create(fs);
|
||||
let builder = createSolutionBuilder(host, [configFile], { verbose: true });
|
||||
builder.build();
|
||||
host.assertDiagnosticMessages(
|
||||
getExpectedDiagnosticForProjectsInBuild(configFile),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, configFile, "src/src/index.js"],
|
||||
[Diagnostics.Building_project_0, `/${configFile}`]
|
||||
);
|
||||
verifyOutputsPresent(fs, ["/src/src/index.js", "/src/src/index.d.ts"]);
|
||||
host.clearDiagnostics();
|
||||
builder = createSolutionBuilder(host, [configFile], { verbose: true });
|
||||
tick();
|
||||
builder.build();
|
||||
host.assertDiagnosticMessages(
|
||||
getExpectedDiagnosticForProjectsInBuild(configFile),
|
||||
[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"]
|
||||
);
|
||||
verifyTscIncrementalEdits({
|
||||
scenario: "resolveJsonModule",
|
||||
subScenario: "without outDir",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "src/tsconfig_withFiles.json", "--verbose"],
|
||||
modifyFs: fs => replaceText(fs, "src/tsconfig_withFiles.json", `"outDir": "dist",`, ""),
|
||||
incrementalScenarios: [noChangeRun]
|
||||
});
|
||||
});
|
||||
|
||||
@@ -125,32 +80,12 @@ export default hello.hello`);
|
||||
projFs = undefined!; // Release the contents
|
||||
});
|
||||
|
||||
it("when importing json module from project reference", () => {
|
||||
const expectedOutput = "/src/main/index.js";
|
||||
const { fs, tick } = getFsWithTime(projFs);
|
||||
const configFile = "src/tsconfig.json";
|
||||
const stringsConfigFile = "src/strings/tsconfig.json";
|
||||
const mainConfigFile = "src/main/tsconfig.json";
|
||||
const host = fakes.SolutionBuilderHost.create(fs);
|
||||
let builder = createSolutionBuilder(host, [configFile], { verbose: true });
|
||||
builder.build();
|
||||
host.assertDiagnosticMessages(
|
||||
getExpectedDiagnosticForProjectsInBuild(stringsConfigFile, mainConfigFile, configFile),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, stringsConfigFile, "src/strings/tsconfig.tsbuildinfo"],
|
||||
[Diagnostics.Building_project_0, `/${stringsConfigFile}`],
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, mainConfigFile, "src/main/index.js"],
|
||||
[Diagnostics.Building_project_0, `/${mainConfigFile}`],
|
||||
);
|
||||
verifyOutputsPresent(fs, [expectedOutput]);
|
||||
host.clearDiagnostics();
|
||||
builder = createSolutionBuilder(host, [configFile], { verbose: true });
|
||||
tick();
|
||||
builder.build();
|
||||
host.assertDiagnosticMessages(
|
||||
getExpectedDiagnosticForProjectsInBuild(stringsConfigFile, mainConfigFile, configFile),
|
||||
[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"],
|
||||
[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"],
|
||||
);
|
||||
verifyTscIncrementalEdits({
|
||||
scenario: "resolveJsonModule",
|
||||
subScenario: "importing json module from project reference",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "src/tsconfig.json", "--verbose"],
|
||||
incrementalScenarios: [noChangeRun]
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user