mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Updates to unittests to make them more readable (#56214)
This commit is contained in:
1 parent
11a04ed908
commit
781cc19b32
1709 files changed
+69678
-40003
No files matched your search
@@ -1,5 +1,8 @@
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
|
||||
describe("unittests:: config:: commandLineParsing:: parseCommandLine", () => {
|
||||
function assertParseResult(subScenario: string, commandLine: string[], workerDiagnostic?: () => ts.ParseCommandLineWorkerDiagnostics) {
|
||||
@@ -8,9 +11,9 @@ describe("unittests:: config:: commandLineParsing:: parseCommandLine", () => {
|
||||
baseline.push(commandLine.join(" "));
|
||||
const parsed = ts.parseCommandLineWorker(workerDiagnostic?.() || ts.compilerOptionsDidYouMeanDiagnostics, commandLine);
|
||||
baseline.push("CompilerOptions::");
|
||||
baseline.push(JSON.stringify(parsed.options, /*replacer*/ undefined, " "));
|
||||
baseline.push(jsonToReadableText(parsed.options));
|
||||
baseline.push("WatchOptions::");
|
||||
baseline.push(JSON.stringify(parsed.watchOptions, /*replacer*/ undefined, " "));
|
||||
baseline.push(jsonToReadableText(parsed.watchOptions));
|
||||
baseline.push("FileNames::");
|
||||
baseline.push(parsed.fileNames.join());
|
||||
baseline.push("Errors::");
|
||||
@@ -200,9 +203,9 @@ describe("unittests:: config:: commandLineParsing:: parseBuildOptions", () => {
|
||||
baseline.push(commandLine.join(" "));
|
||||
const parsed = ts.parseBuildCommand(commandLine);
|
||||
baseline.push("buildOptions::");
|
||||
baseline.push(JSON.stringify(parsed.buildOptions, /*replacer*/ undefined, " "));
|
||||
baseline.push(jsonToReadableText(parsed.buildOptions));
|
||||
baseline.push("WatchOptions::");
|
||||
baseline.push(JSON.stringify(parsed.watchOptions, /*replacer*/ undefined, " "));
|
||||
baseline.push(jsonToReadableText(parsed.watchOptions));
|
||||
baseline.push("Projects::");
|
||||
baseline.push(parsed.projects.join());
|
||||
baseline.push("Errors::");
|
||||
|
||||
@@ -2,6 +2,9 @@ import * as fakes from "../../_namespaces/fakes";
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineParseConfig,
|
||||
baselineParseConfigHost,
|
||||
@@ -12,122 +15,122 @@ function createFileSystem(ignoreCase: boolean, cwd: string, root: string) {
|
||||
cwd,
|
||||
files: {
|
||||
[root]: {
|
||||
"dev/node_modules/@foo/tsconfig/package.json": JSON.stringify({
|
||||
"dev/node_modules/@foo/tsconfig/package.json": jsonToReadableText({
|
||||
name: "@foo/tsconfig",
|
||||
version: "1.0.0",
|
||||
exports: {
|
||||
".": "./src/tsconfig.json",
|
||||
},
|
||||
}),
|
||||
"dev/node_modules/@foo/tsconfig/src/tsconfig.json": JSON.stringify({
|
||||
"dev/node_modules/@foo/tsconfig/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: true,
|
||||
},
|
||||
}),
|
||||
"dev/tsconfig.extendsFoo.json": JSON.stringify({
|
||||
"dev/tsconfig.extendsFoo.json": jsonToReadableText({
|
||||
extends: "@foo/tsconfig",
|
||||
files: [
|
||||
"main.ts",
|
||||
],
|
||||
}),
|
||||
"dev/node_modules/config-box/package.json": JSON.stringify({
|
||||
"dev/node_modules/config-box/package.json": jsonToReadableText({
|
||||
name: "config-box",
|
||||
version: "1.0.0",
|
||||
tsconfig: "./strict.json",
|
||||
}),
|
||||
"dev/node_modules/config-box/strict.json": JSON.stringify({
|
||||
"dev/node_modules/config-box/strict.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: true,
|
||||
},
|
||||
}),
|
||||
"dev/node_modules/config-box/unstrict.json": JSON.stringify({
|
||||
"dev/node_modules/config-box/unstrict.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: false,
|
||||
},
|
||||
}),
|
||||
"dev/tsconfig.extendsBox.json": JSON.stringify({
|
||||
"dev/tsconfig.extendsBox.json": jsonToReadableText({
|
||||
extends: "config-box",
|
||||
files: [
|
||||
"main.ts",
|
||||
],
|
||||
}),
|
||||
"dev/tsconfig.extendsStrict.json": JSON.stringify({
|
||||
"dev/tsconfig.extendsStrict.json": jsonToReadableText({
|
||||
extends: "config-box/strict",
|
||||
files: [
|
||||
"main.ts",
|
||||
],
|
||||
}),
|
||||
"dev/tsconfig.extendsUnStrict.json": JSON.stringify({
|
||||
"dev/tsconfig.extendsUnStrict.json": jsonToReadableText({
|
||||
extends: "config-box/unstrict",
|
||||
files: [
|
||||
"main.ts",
|
||||
],
|
||||
}),
|
||||
"dev/tsconfig.extendsStrictExtension.json": JSON.stringify({
|
||||
"dev/tsconfig.extendsStrictExtension.json": jsonToReadableText({
|
||||
extends: "config-box/strict.json",
|
||||
files: [
|
||||
"main.ts",
|
||||
],
|
||||
}),
|
||||
"dev/node_modules/config-box-implied/package.json": JSON.stringify({
|
||||
"dev/node_modules/config-box-implied/package.json": jsonToReadableText({
|
||||
name: "config-box-implied",
|
||||
version: "1.0.0",
|
||||
}),
|
||||
"dev/node_modules/config-box-implied/tsconfig.json": JSON.stringify({
|
||||
"dev/node_modules/config-box-implied/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: true,
|
||||
},
|
||||
}),
|
||||
"dev/node_modules/config-box-implied/unstrict/tsconfig.json": JSON.stringify({
|
||||
"dev/node_modules/config-box-implied/unstrict/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: false,
|
||||
},
|
||||
}),
|
||||
"dev/tsconfig.extendsBoxImplied.json": JSON.stringify({
|
||||
"dev/tsconfig.extendsBoxImplied.json": jsonToReadableText({
|
||||
extends: "config-box-implied",
|
||||
files: [
|
||||
"main.ts",
|
||||
],
|
||||
}),
|
||||
"dev/tsconfig.extendsBoxImpliedUnstrict.json": JSON.stringify({
|
||||
"dev/tsconfig.extendsBoxImpliedUnstrict.json": jsonToReadableText({
|
||||
extends: "config-box-implied/unstrict",
|
||||
files: [
|
||||
"main.ts",
|
||||
],
|
||||
}),
|
||||
"dev/tsconfig.extendsBoxImpliedUnstrictExtension.json": JSON.stringify({
|
||||
"dev/tsconfig.extendsBoxImpliedUnstrictExtension.json": jsonToReadableText({
|
||||
extends: "config-box-implied/unstrict/tsconfig",
|
||||
files: [
|
||||
"main.ts",
|
||||
],
|
||||
}),
|
||||
"dev/tsconfig.extendsBoxImpliedPath.json": JSON.stringify({
|
||||
"dev/tsconfig.extendsBoxImpliedPath.json": jsonToReadableText({
|
||||
extends: "config-box-implied/tsconfig.json",
|
||||
files: [
|
||||
"main.ts",
|
||||
],
|
||||
}),
|
||||
"dev/tsconfig.json": JSON.stringify({
|
||||
"dev/tsconfig.json": jsonToReadableText({
|
||||
extends: "./configs/base",
|
||||
files: [
|
||||
"main.ts",
|
||||
"supplemental.ts",
|
||||
],
|
||||
}),
|
||||
"dev/tsconfig.nostrictnull.json": JSON.stringify({
|
||||
"dev/tsconfig.nostrictnull.json": jsonToReadableText({
|
||||
extends: "./tsconfig",
|
||||
compilerOptions: {
|
||||
strictNullChecks: false,
|
||||
},
|
||||
}),
|
||||
"dev/configs/base.json": JSON.stringify({
|
||||
"dev/configs/base.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
allowJs: true,
|
||||
noImplicitAny: true,
|
||||
strictNullChecks: true,
|
||||
},
|
||||
}),
|
||||
"dev/configs/tests.json": JSON.stringify({
|
||||
"dev/configs/tests.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
preserveConstEnums: true,
|
||||
removeComments: false,
|
||||
@@ -141,55 +144,55 @@ function createFileSystem(ignoreCase: boolean, cwd: string, root: string) {
|
||||
"../tests/**/*.ts",
|
||||
],
|
||||
}),
|
||||
"dev/circular.json": JSON.stringify({
|
||||
"dev/circular.json": jsonToReadableText({
|
||||
extends: "./circular2",
|
||||
compilerOptions: {
|
||||
module: "amd",
|
||||
},
|
||||
}),
|
||||
"dev/circular2.json": JSON.stringify({
|
||||
"dev/circular2.json": jsonToReadableText({
|
||||
extends: "./circular",
|
||||
compilerOptions: {
|
||||
module: "commonjs",
|
||||
},
|
||||
}),
|
||||
"dev/missing.json": JSON.stringify({
|
||||
"dev/missing.json": jsonToReadableText({
|
||||
extends: "./missing2",
|
||||
compilerOptions: {
|
||||
types: [],
|
||||
},
|
||||
}),
|
||||
"dev/failure.json": JSON.stringify({
|
||||
"dev/failure.json": jsonToReadableText({
|
||||
extends: "./failure2.json",
|
||||
compilerOptions: {
|
||||
typeRoots: [],
|
||||
},
|
||||
}),
|
||||
"dev/failure2.json": JSON.stringify({
|
||||
"dev/failure2.json": jsonToReadableText({
|
||||
excludes: ["*.js"],
|
||||
}),
|
||||
"dev/configs/first.json": JSON.stringify({
|
||||
"dev/configs/first.json": jsonToReadableText({
|
||||
extends: "./base",
|
||||
compilerOptions: {
|
||||
module: "commonjs",
|
||||
},
|
||||
files: ["../main.ts"],
|
||||
}),
|
||||
"dev/configs/second.json": JSON.stringify({
|
||||
"dev/configs/second.json": jsonToReadableText({
|
||||
extends: "./base",
|
||||
compilerOptions: {
|
||||
module: "amd",
|
||||
},
|
||||
include: ["../supplemental.*"],
|
||||
}),
|
||||
"dev/configs/third.json": JSON.stringify({
|
||||
"dev/configs/third.json": jsonToReadableText({
|
||||
extends: "./second",
|
||||
compilerOptions: {
|
||||
module: null, // eslint-disable-line no-null/no-null
|
||||
},
|
||||
include: ["../supplemental.*"],
|
||||
}),
|
||||
"dev/configs/fourth.json": JSON.stringify({
|
||||
"dev/configs/fourth.json": jsonToReadableText({
|
||||
extends: "./third",
|
||||
compilerOptions: {
|
||||
module: "system",
|
||||
@@ -197,35 +200,35 @@ function createFileSystem(ignoreCase: boolean, cwd: string, root: string) {
|
||||
include: null, // eslint-disable-line no-null/no-null
|
||||
files: ["../main.ts"],
|
||||
}),
|
||||
"dev/configs/fifth.json": JSON.stringify({
|
||||
"dev/configs/fifth.json": jsonToReadableText({
|
||||
extends: "./fourth",
|
||||
include: ["../tests/utils.ts"],
|
||||
files: [],
|
||||
}),
|
||||
"dev/extends.json": JSON.stringify({ extends: 42 }),
|
||||
"dev/extends2.json": JSON.stringify({ extends: "configs/base" }),
|
||||
"dev/extends3.json": JSON.stringify({ extends: "" }),
|
||||
"dev/extends4.json": JSON.stringify({ extends: [""] }),
|
||||
"dev/extends.json": jsonToReadableText({ extends: 42 }),
|
||||
"dev/extends2.json": jsonToReadableText({ extends: "configs/base" }),
|
||||
"dev/extends3.json": jsonToReadableText({ extends: "" }),
|
||||
"dev/extends4.json": jsonToReadableText({ extends: [""] }),
|
||||
"dev/main.ts": "",
|
||||
"dev/supplemental.ts": "",
|
||||
"dev/tests/unit/spec.ts": "",
|
||||
"dev/tests/utils.ts": "",
|
||||
"dev/tests/scenarios/first.json": "",
|
||||
"dev/tests/baselines/first/output.ts": "",
|
||||
"dev/configs/extendsArrayFirst.json": JSON.stringify({
|
||||
"dev/configs/extendsArrayFirst.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
allowJs: true,
|
||||
noImplicitAny: true,
|
||||
strictNullChecks: true,
|
||||
},
|
||||
}),
|
||||
"dev/configs/extendsArraySecond.json": JSON.stringify({
|
||||
"dev/configs/extendsArraySecond.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "amd",
|
||||
},
|
||||
include: ["../supplemental.*"],
|
||||
}),
|
||||
"dev/configs/extendsArrayThird.json": JSON.stringify({
|
||||
"dev/configs/extendsArrayThird.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: null, // eslint-disable-line no-null/no-null
|
||||
noImplicitAny: false,
|
||||
@@ -233,7 +236,7 @@ function createFileSystem(ignoreCase: boolean, cwd: string, root: string) {
|
||||
extends: "./extendsArrayFirst",
|
||||
include: ["../supplemental.*"],
|
||||
}),
|
||||
"dev/configs/extendsArrayFourth.json": JSON.stringify({
|
||||
"dev/configs/extendsArrayFourth.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "system",
|
||||
strictNullChecks: false,
|
||||
@@ -241,17 +244,17 @@ function createFileSystem(ignoreCase: boolean, cwd: string, root: string) {
|
||||
include: null, // eslint-disable-line no-null/no-null
|
||||
files: ["../main.ts"],
|
||||
}),
|
||||
"dev/configs/extendsArrayFifth.json": JSON.stringify({
|
||||
"dev/configs/extendsArrayFifth.json": jsonToReadableText({
|
||||
extends: ["./extendsArrayFirst", "./extendsArraySecond", "./extendsArrayThird", "./extendsArrayFourth"],
|
||||
files: [],
|
||||
}),
|
||||
"dev/extendsArrayFails.json": JSON.stringify({
|
||||
"dev/extendsArrayFails.json": jsonToReadableText({
|
||||
extends: ["./missingFile"],
|
||||
compilerOptions: {
|
||||
types: [],
|
||||
},
|
||||
}),
|
||||
"dev/extendsArrayFails2.json": JSON.stringify({ extends: [42] }),
|
||||
"dev/extendsArrayFails2.json": jsonToReadableText({ extends: [42] }),
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -314,7 +317,7 @@ describe("unittests:: config:: configurationExtension", () => {
|
||||
configFileName: entry,
|
||||
baselineParsed: (baseline, parsed) => {
|
||||
baseline.push("CompilerOptions::");
|
||||
baseline.push(JSON.stringify(parsed.options, undefined, " "));
|
||||
baseline.push(jsonToReadableText(parsed.options));
|
||||
baseline.push("FileNames::");
|
||||
baseline.push(parsed.fileNames.join());
|
||||
},
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import * as fakes from "../../_namespaces/fakes";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineParseConfig,
|
||||
} from "./helpers";
|
||||
@@ -8,7 +11,7 @@ describe("unittests:: config:: convertCompilerOptionsFromJson", () => {
|
||||
function baselineCompilerOptions(subScenario: string, json: any, configFileName: string) {
|
||||
baselineCompilerOptionsJsonText(
|
||||
subScenario,
|
||||
JSON.stringify(json, undefined, " "),
|
||||
jsonToReadableText(json),
|
||||
configFileName,
|
||||
/*skipJson*/ false,
|
||||
);
|
||||
@@ -36,7 +39,7 @@ describe("unittests:: config:: convertCompilerOptionsFromJson", () => {
|
||||
jsonText,
|
||||
configFileName,
|
||||
basePath: "/apath",
|
||||
baselineParsed: (baseline, parsed) => baseline.push("CompilerOptions::", JSON.stringify(parsed.options, undefined, " ")),
|
||||
baselineParsed: (baseline, parsed) => baseline.push("CompilerOptions::", jsonToReadableText(parsed.options)),
|
||||
}],
|
||||
skipJson,
|
||||
});
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import * as fakes from "../../_namespaces/fakes";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineParseConfig,
|
||||
} from "./helpers";
|
||||
@@ -10,7 +13,7 @@ describe("unittests:: config:: convertTypeAcquisitionFromJson", () => {
|
||||
scenario: "convertTypeAcquisitionFromJson",
|
||||
subScenario,
|
||||
input: () => {
|
||||
const jsonText = JSON.stringify(json, undefined, " ");
|
||||
const jsonText = jsonToReadableText(json);
|
||||
return [{
|
||||
createHost: () =>
|
||||
new fakes.ParseConfigHost(
|
||||
@@ -29,7 +32,7 @@ describe("unittests:: config:: convertTypeAcquisitionFromJson", () => {
|
||||
jsonText,
|
||||
configFileName,
|
||||
basePath: "/apath",
|
||||
baselineParsed: (baseline, parsed) => baseline.push("TypeAcquisition::", JSON.stringify(parsed.typeAcquisition, undefined, " ")),
|
||||
baselineParsed: (baseline, parsed) => baseline.push("TypeAcquisition::", jsonToReadableText(parsed.typeAcquisition)),
|
||||
}];
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import * as fakes from "../../_namespaces/fakes";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineParseConfig,
|
||||
} from "./helpers";
|
||||
@@ -162,7 +165,7 @@ const caseInsensitiveHostWithSameFileNamesWithDifferentExtensions = new fakes.Pa
|
||||
);
|
||||
|
||||
function baselineMatches(subScenario: string, json: any, host: fakes.ParseConfigHost, basePath: string) {
|
||||
const jsonText = JSON.stringify(json, undefined, " ");
|
||||
const jsonText = jsonToReadableText(json);
|
||||
baselineParseConfig({
|
||||
scenario: "matchFiles",
|
||||
subScenario,
|
||||
@@ -176,15 +179,11 @@ function baselineMatches(subScenario: string, json: any, host: fakes.ParseConfig
|
||||
if (parsed.wildcardDirectories) ts.getOwnKeys(parsed.wildcardDirectories).forEach(dir => wildcardDirectories![dir] = `WatchDirectoryFlags.${(ts as any).WatchDirectoryFlags[parsed.wildcardDirectories![dir]]}`);
|
||||
baseline.push(
|
||||
"Result",
|
||||
JSON.stringify(
|
||||
{
|
||||
...parsed,
|
||||
errors: undefined,
|
||||
wildcardDirectories,
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
jsonToReadableText({
|
||||
...parsed,
|
||||
errors: undefined,
|
||||
wildcardDirectories,
|
||||
}),
|
||||
);
|
||||
},
|
||||
}],
|
||||
|
||||
@@ -2,6 +2,9 @@ import * as fakes from "../../_namespaces/fakes";
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineParseConfig,
|
||||
} from "./helpers";
|
||||
@@ -20,7 +23,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
|
||||
for (const jsonText of jsonTexts()) {
|
||||
baseline.push("Input::", jsonText);
|
||||
const parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText);
|
||||
baseline.push("Config::", JSON.stringify(parsed.config, /*replacer*/ undefined, " "));
|
||||
baseline.push("Config::", jsonToReadableText(parsed.config));
|
||||
baseline.push("Errors::");
|
||||
baseline.push(formatErrors(parsed.error ? [parsed.error] : ts.emptyArray));
|
||||
baseline.push("");
|
||||
@@ -232,7 +235,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
|
||||
baseline.push("Initial::", content);
|
||||
const result = ts.parseJsonText("config.json", content);
|
||||
const configJsonObject = ts.convertToObject(result, result.parseDiagnostics);
|
||||
baseline.push("Result::", JSON.stringify(configJsonObject, undefined, " "));
|
||||
baseline.push("Result::", jsonToReadableText(configJsonObject));
|
||||
baseline.push("Errors::", formatErrors(result.parseDiagnostics));
|
||||
Harness.Baseline.runBaseline(`config/tsconfigParsing/parse and re-emit tsconfig.json file with diagnostics.js`, baseline.join("\n"));
|
||||
});
|
||||
@@ -320,7 +323,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
|
||||
}], /*skipJson*/ true);
|
||||
|
||||
baselinedParsed("generates errors when files is not string", () => [{
|
||||
jsonText: JSON.stringify({
|
||||
jsonText: jsonToReadableText({
|
||||
files: [{
|
||||
compilerOptions: {
|
||||
experimentalDecorators: true,
|
||||
@@ -334,7 +337,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
|
||||
}]);
|
||||
|
||||
baselinedParsed("generates errors when include is not string", () => [{
|
||||
jsonText: JSON.stringify({
|
||||
jsonText: jsonToReadableText({
|
||||
include: [
|
||||
["./**/*.ts"],
|
||||
],
|
||||
@@ -345,7 +348,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
|
||||
}]);
|
||||
|
||||
baselinedParsed("generates errors when commandline option is in tsconfig", () => [{
|
||||
jsonText: JSON.stringify({
|
||||
jsonText: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
help: true,
|
||||
},
|
||||
@@ -382,7 +385,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
|
||||
|
||||
baselineWildcards("parses wildcard directories even when parent directories have dots", () => [{
|
||||
configFileName: "/foo.bar/tsconfig.json",
|
||||
jsonText: JSON.stringify({
|
||||
jsonText: jsonToReadableText({
|
||||
include: ["src"],
|
||||
}),
|
||||
basePath: "/foo.bar",
|
||||
@@ -390,7 +393,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
|
||||
|
||||
baselineWildcards("correctly parses wild card directories from implicit glob when two keys differ only in directory seperator", () => [{
|
||||
configFileName: "/foo.bar/tsconfig.json",
|
||||
jsonText: JSON.stringify({
|
||||
jsonText: jsonToReadableText({
|
||||
include: ["./", "./**/*.json"],
|
||||
}),
|
||||
basePath: "/foo",
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import * as fakes from "../../_namespaces/fakes";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineParseConfig,
|
||||
} from "./helpers";
|
||||
@@ -18,7 +21,7 @@ describe("unittests:: config:: tsconfigParsingWatchOptions:: parseConfigFileText
|
||||
subScenario,
|
||||
input: () =>
|
||||
scenario().map(({ json, additionalFiles, existingWatchOptions }) => {
|
||||
const jsonText = JSON.stringify(json, undefined, " ");
|
||||
const jsonText = jsonToReadableText(json);
|
||||
return {
|
||||
createHost: () =>
|
||||
new fakes.ParseConfigHost(
|
||||
@@ -39,7 +42,7 @@ describe("unittests:: config:: tsconfigParsingWatchOptions:: parseConfigFileText
|
||||
existingWatchOptions,
|
||||
baselineParsed: (baseline, parsed) => {
|
||||
baseline.push(`Result: WatchOptions::`);
|
||||
baseline.push(JSON.stringify(parsed.watchOptions, undefined, " "));
|
||||
baseline.push(jsonToReadableText(parsed.watchOptions));
|
||||
},
|
||||
};
|
||||
}),
|
||||
@@ -77,7 +80,7 @@ describe("unittests:: config:: tsconfigParsingWatchOptions:: parseConfigFileText
|
||||
},
|
||||
},
|
||||
additionalFiles: {
|
||||
"/base.json": JSON.stringify({
|
||||
"/base.json": jsonToReadableText({
|
||||
watchOptions: {
|
||||
watchFile: "UseFsEventsOnParentDirectory",
|
||||
watchDirectory: "FixedPollingInterval",
|
||||
@@ -90,7 +93,7 @@ describe("unittests:: config:: tsconfigParsingWatchOptions:: parseConfigFileText
|
||||
extends: "./base.json",
|
||||
},
|
||||
additionalFiles: {
|
||||
"/base.json": JSON.stringify({
|
||||
"/base.json": jsonToReadableText({
|
||||
watchOptions: {
|
||||
watchFile: "UseFsEventsOnParentDirectory",
|
||||
watchDirectory: "FixedPollingInterval",
|
||||
|
||||
@@ -167,3 +167,7 @@ export function updateProgramText(files: readonly NamedSourceText[], fileName: s
|
||||
const file = ts.find(files, f => f.name === fileName)!;
|
||||
file.text = file.text.updateProgram(newProgramText);
|
||||
}
|
||||
|
||||
export function jsonToReadableText(json: any) {
|
||||
return JSON.stringify(json, undefined, 2);
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import * as fakes from "../../_namespaces/fakes";
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
TscCompileSystem,
|
||||
} from "./tsc";
|
||||
@@ -54,8 +57,8 @@ export function baselinePrograms(baseline: string[], programs: readonly CommandL
|
||||
function baselineProgram(baseline: string[], [program, builderProgram]: CommandLineProgram, oldProgram: CommandLineProgram | undefined, baselineDependencies: boolean | undefined) {
|
||||
if (program !== oldProgram?.[0]) {
|
||||
const options = program.getCompilerOptions();
|
||||
baseline.push(`Program root files: ${JSON.stringify(program.getRootFileNames())}`);
|
||||
baseline.push(`Program options: ${JSON.stringify(options)}`);
|
||||
baseline.push(`Program root files: ${jsonToReadableText(program.getRootFileNames())}`);
|
||||
baseline.push(`Program options: ${jsonToReadableText(options)}`);
|
||||
baseline.push(`Program structureReused: ${(ts as any).StructureIsReused[program.structureIsReused]}`);
|
||||
baseline.push("Program files::");
|
||||
for (const file of program.getSourceFiles()) {
|
||||
@@ -275,7 +278,7 @@ function generateBuildInfoProgramBaseline(sys: ts.System, buildInfoPath: string,
|
||||
size: ts.getBuildInfoText({ ...buildInfo, version }).length,
|
||||
};
|
||||
// For now its just JSON.stringify
|
||||
sys.writeFile(`${buildInfoPath}.readable.baseline.txt`, JSON.stringify(result, /*replacer*/ undefined, 2));
|
||||
sys.writeFile(`${buildInfoPath}.readable.baseline.txt`, jsonToReadableText(result));
|
||||
|
||||
function toFileName(fileId: ts.ProgramBuildInfoFileId) {
|
||||
return buildInfo.program!.fileNames[fileId - 1];
|
||||
|
||||
@@ -25,3 +25,7 @@ interface Symbol {
|
||||
export interface FsContents {
|
||||
[path: string]: string;
|
||||
}
|
||||
|
||||
export function libPath(forLib: string) {
|
||||
return `${ts.getDirectoryPath(libFile.path)}/lib.${forLib}.d.ts`;
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
FsContents,
|
||||
libContent,
|
||||
} from "./contents";
|
||||
import {
|
||||
loadProjectFromFiles,
|
||||
} from "./vfs";
|
||||
import {
|
||||
createWatchedSystem,
|
||||
libFile,
|
||||
} from "./virtualFileSystemWithWatch";
|
||||
|
||||
export function getFsContentsForDemoProjectReferencesCoreConfig(additional?: object) {
|
||||
return jsonToReadableText({
|
||||
extends: "../tsconfig-base.json",
|
||||
compilerOptions: {
|
||||
outDir: "../lib/core",
|
||||
rootDir: ".",
|
||||
},
|
||||
...additional,
|
||||
});
|
||||
}
|
||||
export function getFsContentsForDemoProjectReferences(): FsContents {
|
||||
return {
|
||||
"/user/username/projects/demo/animals/animal.ts": dedent`
|
||||
export type Size = "small" | "medium" | "large";
|
||||
export default interface Animal {
|
||||
size: Size;
|
||||
}
|
||||
`,
|
||||
"/user/username/projects/demo/animals/dog.ts": dedent`
|
||||
import Animal from '.';
|
||||
import { makeRandomName } from '../core/utilities';
|
||||
|
||||
export interface Dog extends Animal {
|
||||
woof(): void;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export function createDog(): Dog {
|
||||
return ({
|
||||
size: "medium",
|
||||
woof: function(this: Dog) {
|
||||
console.log(\`\${ this.name } says "Woof"!\`);
|
||||
},
|
||||
name: makeRandomName()
|
||||
});
|
||||
}
|
||||
`,
|
||||
"/user/username/projects/demo/animals/index.ts": dedent`
|
||||
import Animal from './animal';
|
||||
|
||||
export default Animal;
|
||||
import { createDog, Dog } from './dog';
|
||||
export { createDog, Dog };
|
||||
`,
|
||||
"/user/username/projects/demo/animals/tsconfig.json": jsonToReadableText({
|
||||
extends: "../tsconfig-base.json",
|
||||
compilerOptions: {
|
||||
outDir: "../lib/animals",
|
||||
rootDir: ".",
|
||||
},
|
||||
references: [
|
||||
{ path: "../core" },
|
||||
],
|
||||
}),
|
||||
"/user/username/projects/demo/core/utilities.ts": dedent`
|
||||
|
||||
export function makeRandomName() {
|
||||
return "Bob!?! ";
|
||||
}
|
||||
|
||||
export function lastElementOf<T>(arr: T[]): T | undefined {
|
||||
if (arr.length === 0) return undefined;
|
||||
return arr[arr.length - 1];
|
||||
}
|
||||
`,
|
||||
"/user/username/projects/demo/core/tsconfig.json": getFsContentsForDemoProjectReferencesCoreConfig(),
|
||||
"/user/username/projects/demo/zoo/zoo.ts": dedent`
|
||||
import { Dog, createDog } from '../animals/index';
|
||||
|
||||
export function createZoo(): Array<Dog> {
|
||||
return [
|
||||
createDog()
|
||||
];
|
||||
}
|
||||
`,
|
||||
"/user/username/projects/demo/zoo/tsconfig.json": jsonToReadableText({
|
||||
extends: "../tsconfig-base.json",
|
||||
compilerOptions: {
|
||||
outDir: "../lib/zoo",
|
||||
rootDir: ".",
|
||||
},
|
||||
references: [
|
||||
{
|
||||
path: "../animals",
|
||||
},
|
||||
],
|
||||
}),
|
||||
"/user/username/projects/demo/tsconfig-base.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
declaration: true,
|
||||
target: "es5",
|
||||
module: "commonjs",
|
||||
strict: true,
|
||||
noUnusedLocals: true,
|
||||
noUnusedParameters: true,
|
||||
noImplicitReturns: true,
|
||||
noFallthroughCasesInSwitch: true,
|
||||
composite: true,
|
||||
},
|
||||
}),
|
||||
"/user/username/projects/demo/tsconfig.json": jsonToReadableText({
|
||||
files: [],
|
||||
references: [
|
||||
{
|
||||
path: "./core",
|
||||
},
|
||||
{
|
||||
path: "./animals",
|
||||
},
|
||||
{
|
||||
path: "./zoo",
|
||||
},
|
||||
],
|
||||
}),
|
||||
[libFile.path]: libContent,
|
||||
};
|
||||
}
|
||||
|
||||
export function getFsForDemoProjectReferences() {
|
||||
return loadProjectFromFiles(
|
||||
getFsContentsForDemoProjectReferences(),
|
||||
{
|
||||
cwd: "/user/username/projects/demo",
|
||||
executingFilePath: libFile.path,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function getSysForDemoProjectReferences() {
|
||||
return createWatchedSystem(
|
||||
getFsContentsForDemoProjectReferences(),
|
||||
{
|
||||
currentDirectory: "/user/username/projects/demo",
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
createServerHost,
|
||||
createWatchedSystem,
|
||||
@@ -10,20 +13,20 @@ import {
|
||||
|
||||
export function getSymlinkedExtendsSys(forTsserver?: true): TestServerHost {
|
||||
return (!forTsserver ? createWatchedSystem : createServerHost)({
|
||||
"/users/user/projects/myconfigs/node_modules/@something/tsconfig-node/tsconfig.json": JSON.stringify({
|
||||
"/users/user/projects/myconfigs/node_modules/@something/tsconfig-node/tsconfig.json": jsonToReadableText({
|
||||
extends: "@something/tsconfig-base/tsconfig.json",
|
||||
compilerOptions: {
|
||||
removeComments: true,
|
||||
},
|
||||
}),
|
||||
"/users/user/projects/myconfigs/node_modules/@something/tsconfig-base/tsconfig.json": JSON.stringify({
|
||||
"/users/user/projects/myconfigs/node_modules/@something/tsconfig-base/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
}),
|
||||
"/users/user/projects/myproject/src/index.ts": dedent`
|
||||
// some comment
|
||||
export const x = 10;
|
||||
`,
|
||||
"/users/user/projects/myproject/src/tsconfig.json": JSON.stringify({
|
||||
"/users/user/projects/myproject/src/tsconfig.json": jsonToReadableText({
|
||||
extends: "@something/tsconfig-node/tsconfig.json",
|
||||
}),
|
||||
"/users/user/projects/myproject/node_modules/@something/tsconfig-node": {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
FsContents,
|
||||
libContent,
|
||||
@@ -24,23 +27,23 @@ function getFsContentsForLibResolution(libRedirection?: boolean): FsContents {
|
||||
/// <reference lib="scripthost"/>
|
||||
/// <reference lib="es5"/>
|
||||
`,
|
||||
"/home/src/projects/project1/tsconfig.json": JSON.stringify({
|
||||
"/home/src/projects/project1/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, typeRoots: ["./typeroot1"], lib: ["es5", "dom"], traceResolution: true },
|
||||
}),
|
||||
"/home/src/projects/project1/typeroot1/sometype/index.d.ts": `export type TheNum = "type1";`,
|
||||
"/home/src/projects/project2/utils.d.ts": `export const y = 10;`,
|
||||
"/home/src/projects/project2/index.ts": `export const y = 10`,
|
||||
"/home/src/projects/project2/tsconfig.json": JSON.stringify({
|
||||
"/home/src/projects/project2/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true },
|
||||
}),
|
||||
"/home/src/projects/project3/utils.d.ts": `export const y = 10;`,
|
||||
"/home/src/projects/project3/index.ts": `export const z = 10`,
|
||||
"/home/src/projects/project3/tsconfig.json": JSON.stringify({
|
||||
"/home/src/projects/project3/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true },
|
||||
}),
|
||||
"/home/src/projects/project4/utils.d.ts": `export const y = 10;`,
|
||||
"/home/src/projects/project4/index.ts": `export const z = 10`,
|
||||
"/home/src/projects/project4/tsconfig.json": JSON.stringify({
|
||||
"/home/src/projects/project4/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, lib: ["esnext", "dom", "webworker"], traceResolution: true },
|
||||
}),
|
||||
"/home/src/lib/lib.es5.d.ts": libContent,
|
||||
@@ -79,7 +82,7 @@ export function getSysForLibResolution(libRedirection?: true) {
|
||||
);
|
||||
}
|
||||
|
||||
export function getServerHosForLibResolution(libRedirection?: true) {
|
||||
export function getServerHostForLibResolution(libRedirection?: true) {
|
||||
return createServerHost(
|
||||
getFsContentsForLibResolution(libRedirection),
|
||||
{
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
FsContents,
|
||||
libContent,
|
||||
} from "./contents";
|
||||
import {
|
||||
loadProjectFromFiles,
|
||||
} from "./vfs";
|
||||
import {
|
||||
createWatchedSystem,
|
||||
libFile,
|
||||
} from "./virtualFileSystemWithWatch";
|
||||
|
||||
export function getFsContentsForNoEmitOnError(): FsContents {
|
||||
return {
|
||||
"/user/username/projects/noEmitOnError/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "./dev-build",
|
||||
noEmitOnError: true,
|
||||
},
|
||||
}),
|
||||
"/user/username/projects/noEmitOnError/shared/types/db.ts": dedent`
|
||||
export interface A {
|
||||
name: string;
|
||||
}
|
||||
`,
|
||||
"/user/username/projects/noEmitOnError/src/main.ts": dedent`
|
||||
import { A } from "../shared/types/db";
|
||||
const a = {
|
||||
lastName: 'sdsd'
|
||||
;
|
||||
`,
|
||||
"/user/username/projects/noEmitOnError/src/other.ts": dedent`
|
||||
console.log("hi");
|
||||
export { }
|
||||
`,
|
||||
[libFile.path]: libContent,
|
||||
};
|
||||
}
|
||||
|
||||
export function getFsForNoEmitOnError() {
|
||||
return loadProjectFromFiles(
|
||||
getFsContentsForNoEmitOnError(),
|
||||
{
|
||||
cwd: "/user/username/projects/noEmitOnError",
|
||||
executingFilePath: libFile.path,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function getSysForNoEmitOnError() {
|
||||
return createWatchedSystem(
|
||||
getFsContentsForNoEmitOnError(),
|
||||
{
|
||||
currentDirectory: "/user/username/projects/noEmitOnError",
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
FsContents,
|
||||
} from "./contents";
|
||||
@@ -9,41 +12,33 @@ import {
|
||||
} from "./virtualFileSystemWithWatch";
|
||||
|
||||
export function getFsConentsForNode10ResultAtTypesPackageJson(packageName: string, addTypesCondition: boolean) {
|
||||
return JSON.stringify(
|
||||
{
|
||||
name: `@types/${packageName}`,
|
||||
version: "1.0.0",
|
||||
types: "index.d.ts",
|
||||
exports: {
|
||||
".": {
|
||||
...(addTypesCondition ? { types: "./index.d.ts" } : {}),
|
||||
require: "./index.d.ts",
|
||||
},
|
||||
return jsonToReadableText({
|
||||
name: `@types/${packageName}`,
|
||||
version: "1.0.0",
|
||||
types: "index.d.ts",
|
||||
exports: {
|
||||
".": {
|
||||
...(addTypesCondition ? { types: "./index.d.ts" } : {}),
|
||||
require: "./index.d.ts",
|
||||
},
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function getFsContentsForNode10ResultPackageJson(packageName: string, addTypes: boolean, addTypesCondition: boolean) {
|
||||
return JSON.stringify(
|
||||
{
|
||||
name: packageName,
|
||||
version: "1.0.0",
|
||||
main: "index.js",
|
||||
...(addTypes ? { types: "index.d.ts" } : {}),
|
||||
exports: {
|
||||
".": {
|
||||
...(addTypesCondition ? { types: "./index.d.ts" } : {}),
|
||||
import: "./index.mjs",
|
||||
require: "./index.js",
|
||||
},
|
||||
return jsonToReadableText({
|
||||
name: packageName,
|
||||
version: "1.0.0",
|
||||
main: "index.js",
|
||||
...(addTypes ? { types: "index.d.ts" } : {}),
|
||||
exports: {
|
||||
".": {
|
||||
...(addTypesCondition ? { types: "./index.d.ts" } : {}),
|
||||
import: "./index.mjs",
|
||||
require: "./index.js",
|
||||
},
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function getFsContentsForNode10ResultDts(packageName: string) {
|
||||
@@ -84,7 +79,7 @@ export function getFsContentsForNode10Result(): FsContents {
|
||||
import { foo2 } from "foo2";
|
||||
import { bar2 } from "bar2";
|
||||
`,
|
||||
"/home/src/projects/project/tsconfig.json": JSON.stringify({
|
||||
"/home/src/projects/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
moduleResolution: "node16",
|
||||
traceResolution: true,
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
FsContents,
|
||||
} from "./contents";
|
||||
import {
|
||||
loadProjectFromFiles,
|
||||
} from "./vfs";
|
||||
import {
|
||||
createServerHost,
|
||||
createWatchedSystem,
|
||||
libFile,
|
||||
} from "./virtualFileSystemWithWatch";
|
||||
|
||||
export function getFsContentsForSampleProjectReferencesLogicConfig() {
|
||||
return jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
declaration: true,
|
||||
sourceMap: true,
|
||||
forceConsistentCasingInFileNames: true,
|
||||
skipDefaultLibCheck: true,
|
||||
},
|
||||
references: [
|
||||
{ path: "../core" },
|
||||
],
|
||||
});
|
||||
}
|
||||
export function getFsContentsForSampleProjectReferences(): FsContents {
|
||||
return {
|
||||
[libFile.path]: libFile.content,
|
||||
"/user/username/projects/sample1/core/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
declaration: true,
|
||||
declarationMap: true,
|
||||
skipDefaultLibCheck: true,
|
||||
},
|
||||
}),
|
||||
"/user/username/projects/sample1/core/index.ts": dedent`
|
||||
export const someString: string = "HELLO WORLD";
|
||||
export function leftPad(s: string, n: number) { return s + n; }
|
||||
export function multiply(a: number, b: number) { return a * b; }
|
||||
`,
|
||||
"/user/username/projects/sample1/core/some_decl.d.ts": `declare const dts: any;`,
|
||||
"/user/username/projects/sample1/core/anotherModule.ts": `export const World = "hello";`,
|
||||
"/user/username/projects/sample1/logic/tsconfig.json": getFsContentsForSampleProjectReferencesLogicConfig(),
|
||||
"/user/username/projects/sample1/logic/index.ts": dedent`
|
||||
import * as c from '../core/index';
|
||||
export function getSecondsInDay() {
|
||||
return c.multiply(10, 15);
|
||||
}
|
||||
import * as mod from '../core/anotherModule';
|
||||
export const m = mod;
|
||||
`,
|
||||
"/user/username/projects/sample1/tests/tsconfig.json": jsonToReadableText({
|
||||
references: [
|
||||
{ path: "../core" },
|
||||
{ path: "../logic" },
|
||||
],
|
||||
files: ["index.ts"],
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
declaration: true,
|
||||
forceConsistentCasingInFileNames: true,
|
||||
skipDefaultLibCheck: true,
|
||||
},
|
||||
}),
|
||||
"/user/username/projects/sample1/tests/index.ts": dedent`
|
||||
import * as c from '../core/index';
|
||||
import * as logic from '../logic/index';
|
||||
|
||||
c.leftPad("", 10);
|
||||
logic.getSecondsInDay();
|
||||
|
||||
import * as mod from '../core/anotherModule';
|
||||
export const m = mod;
|
||||
`,
|
||||
};
|
||||
}
|
||||
|
||||
export function getFsForSampleProjectReferences() {
|
||||
return loadProjectFromFiles(
|
||||
getFsContentsForSampleProjectReferences(),
|
||||
{
|
||||
cwd: "/user/username/projects/sample1",
|
||||
executingFilePath: libFile.path,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function getSysForSampleProjectReferences() {
|
||||
return createWatchedSystem(
|
||||
getFsContentsForSampleProjectReferences(),
|
||||
{
|
||||
currentDirectory: "/user/username/projects/sample1",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function getServerHostForSampleProjectReferences() {
|
||||
return createServerHost(
|
||||
getFsContentsForSampleProjectReferences(),
|
||||
{
|
||||
currentDirectory: "/user/username/projects/sample1",
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
import * as fakes from "../../_namespaces/fakes";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
commandLineCallbacks,
|
||||
} from "./baseline";
|
||||
@@ -9,11 +12,7 @@ import {
|
||||
} from "./tsc";
|
||||
import {
|
||||
changeToHostTrackingWrittenFiles,
|
||||
createWatchedSystem,
|
||||
FileOrFolderOrSymLink,
|
||||
FileOrFolderOrSymLinkMap,
|
||||
TestServerHost,
|
||||
TestServerHostCreationParameters,
|
||||
} from "./virtualFileSystemWithWatch";
|
||||
|
||||
export function createSolutionBuilderHostForBaseline(
|
||||
@@ -37,7 +36,7 @@ export function createSolutionBuilder(system: TestServerHost, rootNames: readonl
|
||||
export function ensureErrorFreeBuild(host: TestServerHost, rootNames: readonly string[]) {
|
||||
// ts build should succeed
|
||||
solutionBuildWithBaseline(host, rootNames);
|
||||
assert.equal(host.getOutput().length, 0, JSON.stringify(host.getOutput(), /*replacer*/ undefined, " "));
|
||||
assert.equal(host.getOutput().length, 0, jsonToReadableText(host.getOutput()));
|
||||
}
|
||||
|
||||
export function solutionBuildWithBaseline(sys: TestServerHost, solutionRoots: readonly string[], originalRead?: TestServerHost["readFile"]) {
|
||||
@@ -59,7 +58,3 @@ export function solutionBuildWithBaseline(sys: TestServerHost, solutionRoots: re
|
||||
sys.writtenFiles = undefined;
|
||||
return sys;
|
||||
}
|
||||
|
||||
export function createSystemWithSolutionBuild(solutionRoots: readonly string[], files: FileOrFolderOrSymLinkMap | readonly FileOrFolderOrSymLink[], params?: TestServerHostCreationParameters) {
|
||||
return solutionBuildWithBaseline(createWatchedSystem(files, params), solutionRoots);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
FsContents,
|
||||
libContent,
|
||||
} from "./contents";
|
||||
import {
|
||||
libFile,
|
||||
} from "./virtualFileSystemWithWatch";
|
||||
|
||||
export function getFsContentsForTransitiveReferencesRefsAdts() {
|
||||
return dedent`
|
||||
export class X {}
|
||||
export class A {}
|
||||
`;
|
||||
}
|
||||
|
||||
export function getFsContentsForTransitiveReferencesBConfig() {
|
||||
return jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
baseUrl: "./",
|
||||
paths: {
|
||||
"@ref/*": ["./*"],
|
||||
},
|
||||
},
|
||||
files: ["b.ts"],
|
||||
references: [{ path: "tsconfig.a.json" }],
|
||||
});
|
||||
}
|
||||
|
||||
export function getFsContentsForTransitiveReferencesAConfig() {
|
||||
return jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
files: ["a.ts"],
|
||||
});
|
||||
}
|
||||
|
||||
export function getFsContentsForTransitiveReferences(): FsContents {
|
||||
return {
|
||||
"/user/username/projects/transitiveReferences/refs/a.d.ts": getFsContentsForTransitiveReferencesRefsAdts(),
|
||||
"/user/username/projects/transitiveReferences/a.ts": dedent`
|
||||
export class A {}
|
||||
`,
|
||||
"/user/username/projects/transitiveReferences/b.ts": dedent`
|
||||
import {A} from '@ref/a';
|
||||
export const b = new A();
|
||||
`,
|
||||
"/user/username/projects/transitiveReferences/c.ts": dedent`
|
||||
import {b} from './b';
|
||||
import {X} from "@ref/a";
|
||||
b;
|
||||
X;
|
||||
`,
|
||||
"/user/username/projects/transitiveReferences/tsconfig.a.json": getFsContentsForTransitiveReferencesAConfig(),
|
||||
"/user/username/projects/transitiveReferences/tsconfig.b.json": getFsContentsForTransitiveReferencesBConfig(),
|
||||
"/user/username/projects/transitiveReferences/tsconfig.c.json": jsonToReadableText({
|
||||
files: ["c.ts"],
|
||||
compilerOptions: {
|
||||
baseUrl: "./",
|
||||
paths: {
|
||||
"@ref/*": ["./refs/*"],
|
||||
},
|
||||
},
|
||||
references: [{ path: "tsconfig.b.json" }],
|
||||
}),
|
||||
[libFile.path]: libContent,
|
||||
};
|
||||
}
|
||||
@@ -2,6 +2,9 @@ import * as fakes from "../../_namespaces/fakes";
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselinePrograms,
|
||||
CommandLineCallbacks,
|
||||
@@ -136,13 +139,15 @@ export function testTscCompile(input: TestTscCompile) {
|
||||
makeSystemReadyForBaseline(sys);
|
||||
actualReadFileMap = {};
|
||||
const originalReadFile = sys.readFile;
|
||||
sys.readFile = path => {
|
||||
// Dont record libs
|
||||
if (path.startsWith("/src/")) {
|
||||
actualReadFileMap![path] = (ts.getProperty(actualReadFileMap!, path) || 0) + 1;
|
||||
}
|
||||
return originalReadFile.call(sys, path);
|
||||
};
|
||||
if (input.baselineReadFileCalls) {
|
||||
sys.readFile = path => {
|
||||
// Dont record libs
|
||||
if (!path.startsWith(ts.getDirectoryPath(sys.getExecutingFilePath()))) {
|
||||
actualReadFileMap![path] = (ts.getProperty(actualReadFileMap!, path) || 0) + 1;
|
||||
}
|
||||
return originalReadFile.call(sys, path);
|
||||
};
|
||||
}
|
||||
|
||||
const result = commandLineCallbacks(sys, originalReadFile);
|
||||
ts.executeCommandLine(
|
||||
@@ -164,7 +169,7 @@ export function testTscCompile(input: TestTscCompile) {
|
||||
sys.write(baseline.join("\n"));
|
||||
}
|
||||
if (baselineReadFileCalls) {
|
||||
sys.write(`readFiles:: ${JSON.stringify(actualReadFileMap, /*replacer*/ undefined, " ")} `);
|
||||
sys.write(`readFiles:: ${jsonToReadableText(actualReadFileMap)} `);
|
||||
}
|
||||
if (baselineSourceMap) generateSourceMapBaselineFiles(sys);
|
||||
actualReadFileMap = undefined;
|
||||
@@ -302,9 +307,9 @@ function verifyTscEditDiscrepancies({
|
||||
if (!incrementalFileInfo || !cleanFileInfo || incrementalFileInfo.signature !== cleanFileInfo.signature && (!dtsForKey || incrementalFileInfo.signature !== dtsForKey.signature)) {
|
||||
return [
|
||||
`Incremental signature is neither dts signature nor file version for File:: ${key}`,
|
||||
`Incremental:: ${JSON.stringify(incrementalFileInfo, /*replacer*/ undefined, 2)}`,
|
||||
`Clean:: ${JSON.stringify(cleanFileInfo, /*replacer*/ undefined, 2)}`,
|
||||
`Dts Signature:: $${JSON.stringify(dtsForKey?.signature)}`,
|
||||
`Incremental:: ${jsonToReadableText(incrementalFileInfo)}`,
|
||||
`Clean:: ${jsonToReadableText(cleanFileInfo)}`,
|
||||
`Dts Signature:: $${jsonToReadableText(dtsForKey?.signature)}`,
|
||||
];
|
||||
}
|
||||
},
|
||||
@@ -324,9 +329,9 @@ function verifyTscEditDiscrepancies({
|
||||
) {
|
||||
return [
|
||||
`Incremental Reference set is neither from dts nor files reference map for File:: ${key}::`,
|
||||
`Incremental:: ${JSON.stringify(incrementalReferenceSet, /*replacer*/ undefined, 2)}`,
|
||||
`Clean:: ${JSON.stringify(cleanReferenceSet, /*replacer*/ undefined, 2)}`,
|
||||
`DtsExportsMap:: ${JSON.stringify(dtsForKey?.exportedModules, /*replacer*/ undefined, 2)}`,
|
||||
`Incremental:: ${jsonToReadableText(incrementalReferenceSet)}`,
|
||||
`Clean:: ${jsonToReadableText(cleanReferenceSet)}`,
|
||||
`DtsExportsMap:: ${jsonToReadableText(dtsForKey?.exportedModules)}`,
|
||||
];
|
||||
}
|
||||
},
|
||||
@@ -405,9 +410,9 @@ function verifyTscEditDiscrepancies({
|
||||
addBaseline(
|
||||
message,
|
||||
"CleanBuild:",
|
||||
ts.isString(expected) ? expected : JSON.stringify(expected),
|
||||
ts.isString(expected) ? expected : jsonToReadableText(expected),
|
||||
"IncrementalBuild:",
|
||||
ts.isString(actual) ? actual : JSON.stringify(actual),
|
||||
ts.isString(actual) ? actual : jsonToReadableText(actual),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -437,25 +442,21 @@ function getBuildInfoForIncrementalCorrectnessCheck(text: string | undefined): {
|
||||
}
|
||||
}
|
||||
return {
|
||||
buildInfo: JSON.stringify(
|
||||
{
|
||||
...readableBuildInfo,
|
||||
program: readableBuildInfo.program && {
|
||||
...readableBuildInfo.program,
|
||||
fileNames: undefined,
|
||||
fileNamesList: undefined,
|
||||
fileInfos: sanitizedFileInfos,
|
||||
// Ignore noEmit since that shouldnt be reason to emit the tsbuild info and presence of it in the buildinfo file does not matter
|
||||
options: { ...readableBuildInfo.program.options, noEmit: undefined },
|
||||
exportedModulesMap: undefined,
|
||||
affectedFilesPendingEmit: undefined,
|
||||
latestChangedDtsFile: readableBuildInfo.program.latestChangedDtsFile ? "FakeFileName" : undefined,
|
||||
},
|
||||
size: undefined, // Size doesnt need to be equal
|
||||
buildInfo: jsonToReadableText({
|
||||
...readableBuildInfo,
|
||||
program: readableBuildInfo.program && {
|
||||
...readableBuildInfo.program,
|
||||
fileNames: undefined,
|
||||
fileNamesList: undefined,
|
||||
fileInfos: sanitizedFileInfos,
|
||||
// Ignore noEmit since that shouldnt be reason to emit the tsbuild info and presence of it in the buildinfo file does not matter
|
||||
options: { ...readableBuildInfo.program.options, noEmit: undefined },
|
||||
exportedModulesMap: undefined,
|
||||
affectedFilesPendingEmit: undefined,
|
||||
latestChangedDtsFile: readableBuildInfo.program.latestChangedDtsFile ? "FakeFileName" : undefined,
|
||||
},
|
||||
/*replacer*/ undefined,
|
||||
2,
|
||||
),
|
||||
size: undefined, // Size doesnt need to be equal
|
||||
}),
|
||||
readableBuildInfo,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ import {
|
||||
ActionWatchTypingLocations,
|
||||
stringifyIndented,
|
||||
} from "../../_namespaces/ts.server";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
patchHostTimeouts,
|
||||
TestSessionAndServiceHost,
|
||||
@@ -93,16 +96,13 @@ function getTypesRegistryFileLocation(globalTypingsCacheLocation: string): strin
|
||||
return ts.combinePaths(ts.normalizeSlashes(globalTypingsCacheLocation), `node_modules/${typesRegistryPackageName}/index.json`);
|
||||
}
|
||||
|
||||
export interface FileWithPackageName extends File {
|
||||
package: string;
|
||||
}
|
||||
export type InstallActionThrowingError = string;
|
||||
export type InstallActionWithTypingFiles = [installedTypings: string[] | string, typingFiles: File[]];
|
||||
export type CustomInstallAction = (
|
||||
installer: TestTypingsInstallerWorker,
|
||||
requestId: number,
|
||||
packageNames: string[],
|
||||
cb: ts.server.typingsInstaller.RequestCompletedAction,
|
||||
) => void;
|
||||
|
||||
export type InstallAction = InstallActionThrowingError | InstallActionWithTypingFiles | CustomInstallAction;
|
||||
export type InstallActionWithFilteredTypings = [typingFiles: FileWithPackageName[]];
|
||||
export type InstallAction = InstallActionThrowingError | InstallActionWithTypingFiles | InstallActionWithFilteredTypings;
|
||||
export class TestTypingsInstallerWorker extends ts.server.typingsInstaller.TypingsInstaller {
|
||||
readonly typesRegistry: Map<string, ts.MapLike<string>>;
|
||||
protected projectService!: ts.server.ProjectService;
|
||||
@@ -139,17 +139,13 @@ export class TestTypingsInstallerWorker extends ts.server.typingsInstaller.Typin
|
||||
}
|
||||
installTypingHost.ensureFileOrFolder({
|
||||
path: getTypesRegistryFileLocation(globalTypingsCacheLocation),
|
||||
content: JSON.stringify(
|
||||
createTypesRegistryFileContent(
|
||||
typesRegistry ?
|
||||
ts.isString(typesRegistry) ?
|
||||
[typesRegistry] :
|
||||
typesRegistry :
|
||||
ts.emptyArray,
|
||||
),
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
content: jsonToReadableText(createTypesRegistryFileContent(
|
||||
typesRegistry ?
|
||||
ts.isString(typesRegistry) ?
|
||||
[typesRegistry] :
|
||||
typesRegistry :
|
||||
ts.emptyArray,
|
||||
)),
|
||||
});
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`TI:: Updated ${typesRegistryPackageName} npm package`);
|
||||
@@ -167,7 +163,7 @@ export class TestTypingsInstallerWorker extends ts.server.typingsInstaller.Typin
|
||||
this.postExecActions = [];
|
||||
for (const action of actionsToRun) {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`#${action.requestId} with arguments'${JSON.stringify(action.packageNames)}':: ${action.success}`);
|
||||
this.log.writeLine(`#${action.requestId} with arguments'${jsonToReadableText(action.packageNames)}':: ${action.success}`);
|
||||
}
|
||||
action.callback(action.success);
|
||||
}
|
||||
@@ -183,7 +179,7 @@ export class TestTypingsInstallerWorker extends ts.server.typingsInstaller.Typin
|
||||
|
||||
installWorker(requestId: number, packageNames: string[], _cwd: string, cb: ts.server.typingsInstaller.RequestCompletedAction): void {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`#${requestId} with arguments'${JSON.stringify(packageNames)}'.`);
|
||||
this.log.writeLine(`#${requestId} with arguments'${jsonToReadableText(packageNames)}'.`);
|
||||
}
|
||||
if (!this.installAction) {
|
||||
this.addPostExecAction("success", requestId, packageNames, cb);
|
||||
@@ -191,7 +187,7 @@ export class TestTypingsInstallerWorker extends ts.server.typingsInstaller.Typin
|
||||
else if (ts.isString(this.installAction)) {
|
||||
assert(false, this.installAction);
|
||||
}
|
||||
else if (ts.isArray(this.installAction)) {
|
||||
else if (this.installAction.length === 2) {
|
||||
this.executeInstallWithTypingFiles(
|
||||
requestId,
|
||||
packageNames,
|
||||
@@ -201,7 +197,14 @@ export class TestTypingsInstallerWorker extends ts.server.typingsInstaller.Typin
|
||||
);
|
||||
}
|
||||
else {
|
||||
this.installAction(this, requestId, packageNames, cb);
|
||||
const typingFiles = this.installAction[0].filter(f => packageNames.includes(ts.server.typingsInstaller.typingsName(f.package)));
|
||||
this.executeInstallWithTypingFiles(
|
||||
requestId,
|
||||
packageNames,
|
||||
typingFiles.map(f => f.package),
|
||||
typingFiles,
|
||||
cb,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +308,7 @@ function createNpmPackageJsonString(installedTypings: string[]): string {
|
||||
for (const typing of installedTypings) {
|
||||
dependencies[typing] = "1.0.0";
|
||||
}
|
||||
return JSON.stringify({ dependencies });
|
||||
return jsonToReadableText({ dependencies });
|
||||
}
|
||||
function createTypesRegistryFileContent(list: readonly string[]): TypesRegistryFile {
|
||||
const versionMap = {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import {
|
||||
getDirectoryPath,
|
||||
} from "../../_namespaces/ts";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import * as vpath from "../../_namespaces/vpath";
|
||||
import {
|
||||
libContent,
|
||||
} from "./contents";
|
||||
@@ -21,19 +19,6 @@ function valueOfFsOptions(options: FsOptionsOrLibContentsToAppend | undefined, k
|
||||
options?.[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load project from disk into /src folder
|
||||
*/
|
||||
export function loadProjectFromDisk(
|
||||
root: string,
|
||||
options?: FsOptionsOrLibContentsToAppend,
|
||||
): vfs.FileSystem {
|
||||
const resolver = vfs.createResolver(Harness.IO);
|
||||
return loadProjectFromFiles({
|
||||
["/src"]: new vfs.Mount(vpath.resolve(Harness.IO.getWorkspaceRoot(), root), resolver),
|
||||
}, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* All the files must be in /src
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
createWatchUtils,
|
||||
} from "../../../harness/watchUtils";
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import {
|
||||
clear,
|
||||
clone,
|
||||
@@ -1110,14 +1109,3 @@ export function changeToHostTrackingWrittenFiles(inputHost: TestServerHost) {
|
||||
};
|
||||
return host;
|
||||
}
|
||||
|
||||
export function getTsBuildProjectFilePath(project: string, file: string) {
|
||||
return `/user/username/projects/${project}/${file}`;
|
||||
}
|
||||
|
||||
export function getTsBuildProjectFile(project: string, file: string): File {
|
||||
return {
|
||||
path: getTsBuildProjectFilePath(project, file),
|
||||
content: Harness.IO.readFile(`${Harness.IO.getWorkspaceRoot()}/tests/projects/${project}/${file}`)!,
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
import * as Harness from "../_namespaces/Harness";
|
||||
import * as ts from "../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "./helpers";
|
||||
|
||||
interface File {
|
||||
name: string;
|
||||
@@ -84,7 +87,7 @@ describe("unittests:: moduleResolution:: Node module resolution - relative paths
|
||||
const moduleFile = { name: moduleFileNameNoExt + ext };
|
||||
baselines.push(`Resolving "${moduleName}" from ${containingFile.name} when module has extension: ${ext}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const resolution = ts.nodeModuleNameResolver(moduleName, containingFile.name, {}, createModuleResolutionHost(baselines, hasDirectoryExists, containingFile, moduleFile));
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
}
|
||||
@@ -104,11 +107,11 @@ describe("unittests:: moduleResolution:: Node module resolution - relative paths
|
||||
|
||||
function test(hasDirectoryExists: boolean) {
|
||||
const containingFile = { name: containingFileName };
|
||||
const packageJson = { name: packageJsonFileName, content: JSON.stringify({ typings: fieldRef }) };
|
||||
const packageJson = { name: packageJsonFileName, content: jsonToReadableText({ typings: fieldRef }) };
|
||||
const moduleFile = { name: moduleFileName };
|
||||
baselines.push(`Resolving "${moduleName}" from ${containingFile.name} with typings: ${fieldRef}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const resolution = ts.nodeModuleNameResolver(moduleName, containingFile.name, {}, createModuleResolutionHost(baselines, hasDirectoryExists, containingFile, packageJson, moduleFile));
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
}
|
||||
@@ -128,15 +131,15 @@ describe("unittests:: moduleResolution:: Node module resolution - relative paths
|
||||
test(/*hasDirectoryExists*/ false);
|
||||
function test(hasDirectoryExists: boolean) {
|
||||
const containingFile = { name: "/a/b.ts" };
|
||||
const packageJson = { name: "/node_modules/b/package.json", content: JSON.stringify({ typings }) };
|
||||
const packageJson = { name: "/node_modules/b/package.json", content: jsonToReadableText({ typings }) };
|
||||
const moduleFile = { name: "/a/b.d.ts" };
|
||||
|
||||
const indexPath = "/node_modules/b/index.d.ts";
|
||||
const indexFile = { name: indexPath };
|
||||
|
||||
baselines.push(`Resolving "b" from ${containingFile.name} with typings: ${JSON.stringify(typings)}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
baselines.push(`Resolving "b" from ${containingFile.name} with typings: ${jsonToReadableText(typings)}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const resolution = ts.nodeModuleNameResolver("b", containingFile.name, {}, createModuleResolutionHost(baselines, hasDirectoryExists, containingFile, packageJson, moduleFile, indexFile));
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
}
|
||||
@@ -149,11 +152,11 @@ describe("unittests:: moduleResolution:: Node module resolution - relative paths
|
||||
|
||||
function test(hasDirectoryExists: boolean) {
|
||||
const containingFile = { name: "/a/b/c.ts" };
|
||||
const packageJson = { name: "/a/b/foo/package.json", content: JSON.stringify({ main: "/c/d" }) };
|
||||
const packageJson = { name: "/a/b/foo/package.json", content: jsonToReadableText({ main: "/c/d" }) };
|
||||
const indexFile = { name: "/a/b/foo/index.d.ts" };
|
||||
baselines.push(`Resolving "./foo" from ${containingFile.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const resolution = ts.nodeModuleNameResolver("./foo", containingFile.name, {}, createModuleResolutionHost(baselines, hasDirectoryExists, containingFile, packageJson, indexFile));
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
});
|
||||
@@ -265,7 +268,7 @@ describe("unittests:: moduleResolution:: Node module resolution - non-relative p
|
||||
const moduleFile = { name: "/a/b/node_modules/foo.ts" };
|
||||
baselines.push(`Resolving "foo" from ${containingFile.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const resolution = ts.nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(baselines, hasDirectoryExists, containingFile, moduleFile));
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
});
|
||||
@@ -281,7 +284,7 @@ describe("unittests:: moduleResolution:: Node module resolution - non-relative p
|
||||
const moduleFile = { name: "/a/b/node_modules/foo.d.ts" };
|
||||
baselines.push(`Resolving "foo" from ${containingFile.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const resolution = ts.nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(baselines, hasDirectoryExists, containingFile, moduleFile));
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
});
|
||||
@@ -297,7 +300,7 @@ describe("unittests:: moduleResolution:: Node module resolution - non-relative p
|
||||
const moduleFile: File = { name: "/a/node_modules/foo/index.d.ts" };
|
||||
baselines.push(`Resolving "foo" from ${containingFile.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const resolution = ts.nodeModuleNameResolver("foo", containingFile.name, {}, createModuleResolutionHost(baselines, hasDirectoryExists, containingFile, moduleFile));
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
});
|
||||
@@ -314,11 +317,11 @@ describe("unittests:: moduleResolution:: Node module resolution - non-relative p
|
||||
baselines,
|
||||
/*hasDirectoryExists*/ true,
|
||||
{ name: realFileName, symlinks: [symlinkFileName] },
|
||||
{ name: "/app/node_modules/linked/package.json", content: '{"version": "0.0.0", "main": "./index"}' },
|
||||
{ name: "/app/node_modules/linked/package.json", content: jsonToReadableText({ version: "0.0.0", main: "./index" }) },
|
||||
);
|
||||
baselines.push(`Resolving "linked" from /app/app.ts when preserveSymlinks is ${preserveSymlinks}`);
|
||||
const resolution = ts.nodeModuleNameResolver("linked", "/app/app.ts", { preserveSymlinks }, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
});
|
||||
@@ -334,24 +337,24 @@ describe("unittests:: moduleResolution:: Node module resolution - non-relative p
|
||||
},
|
||||
{
|
||||
name: "/sub/node_modules/a/package.json",
|
||||
content: '{"version": "0.0.0", "main": "./index"}',
|
||||
content: jsonToReadableText({ version: "0.0.0", main: "./index" }),
|
||||
},
|
||||
);
|
||||
const compilerOptions: ts.CompilerOptions = { moduleResolution: ts.ModuleResolutionKind.Node10 };
|
||||
const cache = ts.createModuleResolutionCache("/", f => f);
|
||||
baselines.push(`Resolving "a" from /sub/dir/foo.ts`);
|
||||
let resolution = ts.resolveModuleName("a", "/sub/dir/foo.ts", compilerOptions, host, cache);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
|
||||
baselines.push(`Resolving "a" from /sub/foo.ts`);
|
||||
resolution = ts.resolveModuleName("a", "/sub/foo.ts", compilerOptions, host, cache);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
|
||||
baselines.push(`Resolving "a" from /foo.ts`);
|
||||
resolution = ts.resolveModuleName("a", "/foo.ts", compilerOptions, host, cache);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
runBaseline("non relative uses originalPath for caching", baselines);
|
||||
});
|
||||
@@ -362,7 +365,7 @@ describe("unittests:: moduleResolution:: Node module resolution - non-relative p
|
||||
baselines,
|
||||
/*hasDirectoryExists*/ true,
|
||||
{ name: "/linked/index.d.ts", symlinks: ["/app/node_modules/linked/index.d.ts"] },
|
||||
{ name: "/app/node_modules/linked/package.json", content: '{"version": "0.0.0", "main": "./index"}' },
|
||||
{ name: "/app/node_modules/linked/package.json", content: jsonToReadableText({ version: "0.0.0", main: "./index" }) },
|
||||
);
|
||||
const cache = ts.createModuleResolutionCache("/", f => f);
|
||||
const compilerOptions: ts.CompilerOptions = { moduleResolution: ts.ModuleResolutionKind.Node10 };
|
||||
@@ -373,7 +376,7 @@ describe("unittests:: moduleResolution:: Node module resolution - non-relative p
|
||||
function baselineResolution(containingFile: string) {
|
||||
baselines.push(`Resolving "linked" from ${containingFile}`);
|
||||
const resolution = ts.resolveModuleName("linked", containingFile, compilerOptions, host, cache);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(resolution, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(resolution)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
});
|
||||
@@ -657,19 +660,19 @@ describe("unittests:: moduleResolution:: baseUrl augmented module resolution", (
|
||||
{
|
||||
baselines.push(`Resolving "folder2/file2" from ${file1.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const result = ts.resolveModuleName("folder2/file2", file1.name, options, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(result, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(result)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
{
|
||||
baselines.push(`Resolving "./file3" from ${file2.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const result = ts.resolveModuleName("./file3", file2.name, options, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(result, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(result)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
{
|
||||
baselines.push(`Resolving "/root/folder1/file1" from ${file2.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const result = ts.resolveModuleName("/root/folder1/file1", file2.name, options, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(result, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(result)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
}
|
||||
@@ -687,7 +690,7 @@ describe("unittests:: moduleResolution:: baseUrl augmented module resolution", (
|
||||
const main: File = { name: "/root/a/b/main.ts" };
|
||||
const m1: File = { name: "/root/m1.ts" }; // load file as module
|
||||
const m2: File = { name: "/root/m2/index.d.ts" }; // load folder as module
|
||||
const m3: File = { name: "/root/m3/package.json", content: JSON.stringify({ typings: "dist/typings.d.ts" }) };
|
||||
const m3: File = { name: "/root/m3/package.json", content: jsonToReadableText({ typings: "dist/typings.d.ts" }) };
|
||||
const m3Typings: File = { name: "/root/m3/dist/typings.d.ts" };
|
||||
const m4: File = { name: "/root/node_modules/m4.ts" }; // fallback to node
|
||||
|
||||
@@ -702,7 +705,7 @@ describe("unittests:: moduleResolution:: baseUrl augmented module resolution", (
|
||||
function check(name: string, caller: File) {
|
||||
baselines.push(`Resolving "${name}" from ${caller.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const result = ts.resolveModuleName(name, caller.name, options, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(result, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(result)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
}
|
||||
@@ -728,7 +731,7 @@ describe("unittests:: moduleResolution:: baseUrl augmented module resolution", (
|
||||
function check(name: string, caller: File) {
|
||||
baselines.push(`Resolving "${name}" from ${caller.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const result = ts.resolveModuleName(name, caller.name, options, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(result, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(result)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
}
|
||||
@@ -746,7 +749,7 @@ describe("unittests:: moduleResolution:: baseUrl augmented module resolution", (
|
||||
const file1: File = { name: "/root/folder1/file1.ts" };
|
||||
const file2: File = { name: "/root/generated/folder1/file2.ts" }; // load remapped file as module
|
||||
const file3: File = { name: "/root/generated/folder2/file3/index.d.ts" }; // load folder a module
|
||||
const file4Typings: File = { name: "/root/generated/folder2/file4/package.json", content: JSON.stringify({ typings: "dist/types.d.ts" }) };
|
||||
const file4Typings: File = { name: "/root/generated/folder2/file4/package.json", content: jsonToReadableText({ typings: "dist/types.d.ts" }) };
|
||||
const file4: File = { name: "/root/generated/folder2/file4/dist/types.d.ts" }; // load file pointed by typings
|
||||
const file5: File = { name: "/root/someanotherfolder/file5/index.d.ts" }; // load remapped module from folder
|
||||
const file6: File = { name: "/root/node_modules/file6.ts" }; // fallback to node
|
||||
@@ -780,7 +783,7 @@ describe("unittests:: moduleResolution:: baseUrl augmented module resolution", (
|
||||
function check(name: string) {
|
||||
baselines.push(`Resolving "${name}" from ${main.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const result = ts.resolveModuleName(name, main.name, options, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(result, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(result)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
}
|
||||
@@ -825,7 +828,7 @@ describe("unittests:: moduleResolution:: baseUrl augmented module resolution", (
|
||||
function check(name: string) {
|
||||
baselines.push(`Resolving "${name}" from ${main.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const result = ts.resolveModuleName(name, main.name, options, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(result, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(result)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
}
|
||||
@@ -857,7 +860,7 @@ describe("unittests:: moduleResolution:: baseUrl augmented module resolution", (
|
||||
function check(name: string, container: File) {
|
||||
baselines.push(`Resolving "${name}" from ${container.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const result = ts.resolveModuleName(name, container.name, options, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(result, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(result)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
}
|
||||
@@ -889,7 +892,7 @@ describe("unittests:: moduleResolution:: baseUrl augmented module resolution", (
|
||||
function check(name: string, container: File) {
|
||||
baselines.push(`Resolving "${name}" from ${container.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const result = ts.resolveModuleName(name, container.name, options, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(result, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(result)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
}
|
||||
@@ -903,7 +906,7 @@ describe("unittests:: moduleResolution:: baseUrl augmented module resolution", (
|
||||
|
||||
function test(hasDirectoryExists: boolean) {
|
||||
const app: File = { name: "/root/src/app.ts" };
|
||||
const libsPackage: File = { name: "/root/src/libs/guid/package.json", content: JSON.stringify({ typings: "dist/guid.d.ts" }) };
|
||||
const libsPackage: File = { name: "/root/src/libs/guid/package.json", content: jsonToReadableText({ typings: "dist/guid.d.ts" }) };
|
||||
const libsTypings: File = { name: "/root/src/libs/guid/dist/guid.d.ts" };
|
||||
const host = createModuleResolutionHost(baselines, hasDirectoryExists, app, libsPackage, libsTypings);
|
||||
const options: ts.CompilerOptions = {
|
||||
@@ -915,7 +918,7 @@ describe("unittests:: moduleResolution:: baseUrl augmented module resolution", (
|
||||
};
|
||||
baselines.push(`Resolving "libs/guid" from ${app.name}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const result = ts.resolveModuleName("libs/guid", app.name, options, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(result, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(result)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
});
|
||||
@@ -939,7 +942,7 @@ describe("unittests:: moduleResolution:: Type reference directive resolution: ",
|
||||
const host = createModuleResolutionHost(baselines, hasDirectoryExists, ...[initialFile, targetFile].concat(...otherFiles));
|
||||
baselines.push(`Resolving "${typeDirective}" from ${initialFile.name} typesRoots: ${typesRoot ? `[${typesRoot}]` : undefined}${hasDirectoryExists ? "" : " with host that doesnt have directoryExists"}`);
|
||||
const result = ts.resolveTypeReferenceDirective(typeDirective, initialFile.name, typesRoot ? { typeRoots: [typesRoot] } : {}, host);
|
||||
baselines.push(`Resolution:: ${JSON.stringify(result, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`Resolution:: ${jsonToReadableText(result)}`);
|
||||
baselines.push("");
|
||||
}
|
||||
|
||||
@@ -957,7 +960,7 @@ describe("unittests:: moduleResolution:: Type reference directive resolution: ",
|
||||
{
|
||||
const f1 = { name: "/root/src/app.ts" };
|
||||
const f2 = { name: "/root/src/types/lib/typings/lib.d.ts" };
|
||||
const packageFile = { name: "/root/src/types/lib/package.json", content: JSON.stringify({ types: "typings/lib.d.ts" }) };
|
||||
const packageFile = { name: "/root/src/types/lib/package.json", content: jsonToReadableText({ types: "typings/lib.d.ts" }) };
|
||||
test(baselines, /*typesRoot*/ "/root/src/types", /* typeDirective */ "lib", f1, f2, packageFile);
|
||||
}
|
||||
{
|
||||
@@ -968,7 +971,7 @@ describe("unittests:: moduleResolution:: Type reference directive resolution: ",
|
||||
{
|
||||
const f1 = { name: "/root/src/app.ts" };
|
||||
const f2 = { name: "/root/src/node_modules/lib/typings/lib.d.ts" };
|
||||
const packageFile = { name: "/root/src/node_modules/lib/package.json", content: JSON.stringify({ types: "typings/lib.d.ts" }) };
|
||||
const packageFile = { name: "/root/src/node_modules/lib/package.json", content: jsonToReadableText({ types: "typings/lib.d.ts" }) };
|
||||
test(baselines, /*typesRoot*/ "/root/src/types", /* typeDirective */ "lib", f1, f2, packageFile);
|
||||
}
|
||||
{
|
||||
@@ -979,7 +982,7 @@ describe("unittests:: moduleResolution:: Type reference directive resolution: ",
|
||||
{
|
||||
const f1 = { name: "/root/src/app.ts" };
|
||||
const f2 = { name: "/root/src/node_modules/@types/lib/typings/lib.d.ts" };
|
||||
const packageFile = { name: "/root/src/node_modules/@types/lib/package.json", content: JSON.stringify({ types: "typings/lib.d.ts" }) };
|
||||
const packageFile = { name: "/root/src/node_modules/@types/lib/package.json", content: jsonToReadableText({ types: "typings/lib.d.ts" }) };
|
||||
test(baselines, /*typesRoot*/ "/root/src/types", /* typeDirective */ "lib", f1, f2, packageFile);
|
||||
}
|
||||
runBaseline("type reference from primary location", baselines);
|
||||
@@ -999,7 +1002,7 @@ describe("unittests:: moduleResolution:: Type reference directive resolution: ",
|
||||
{
|
||||
const f1 = { name: "/root/src/app.ts" };
|
||||
const f2 = { name: "/root/node_modules/lib/typings/lib.d.ts" };
|
||||
const packageFile = { name: "/root/node_modules/lib/package.json", content: JSON.stringify({ typings: "typings/lib.d.ts" }) };
|
||||
const packageFile = { name: "/root/node_modules/lib/package.json", content: jsonToReadableText({ typings: "typings/lib.d.ts" }) };
|
||||
test(baselines, /*typesRoot*/ "/root/src/types", /* typeDirective */ "lib", f1, f2, packageFile);
|
||||
}
|
||||
{
|
||||
@@ -1010,7 +1013,7 @@ describe("unittests:: moduleResolution:: Type reference directive resolution: ",
|
||||
{
|
||||
const f1 = { name: "/root/src/app.ts" };
|
||||
const f2 = { name: "/root/node_modules/@types/lib/typings/lib.d.ts" };
|
||||
const packageFile = { name: "/root/node_modules/@types/lib/package.json", content: JSON.stringify({ typings: "typings/lib.d.ts" }) };
|
||||
const packageFile = { name: "/root/node_modules/@types/lib/package.json", content: jsonToReadableText({ typings: "typings/lib.d.ts" }) };
|
||||
test(baselines, /*typesRoot*/ "/root/src/types", /* typeDirective */ "lib", f1, f2, packageFile);
|
||||
}
|
||||
runBaseline("type reference from secondary location", baselines);
|
||||
|
||||
@@ -3,6 +3,9 @@ import * as fakes from "../_namespaces/fakes";
|
||||
import * as Harness from "../_namespaces/Harness";
|
||||
import * as ts from "../_namespaces/ts";
|
||||
import * as vfs from "../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "./helpers";
|
||||
|
||||
function verifyMissingFilePaths(missingPaths: readonly ts.Path[], expected: readonly string[]) {
|
||||
assert.isDefined(missingPaths);
|
||||
@@ -145,7 +148,7 @@ describe("unittests:: Program.isSourceFileFromExternalLibrary", () => {
|
||||
// In this example '/node_modules/foo/index.d.ts' will redirect to '/node_modules/bar/node_modules/foo/index.d.ts'.
|
||||
const a = new documents.TextDocument("/a.ts", 'import * as bar from "bar"; import * as foo from "foo";');
|
||||
const bar = new documents.TextDocument("/node_modules/bar/index.d.ts", 'import * as foo from "foo";');
|
||||
const fooPackageJsonText = '{ "name": "foo", "version": "1.2.3" }';
|
||||
const fooPackageJsonText = jsonToReadableText({ name: "foo", version: "1.2.3" });
|
||||
const fooIndexText = "export const x: number;";
|
||||
const barFooPackage = new documents.TextDocument("/node_modules/bar/node_modules/foo/package.json", fooPackageJsonText);
|
||||
const barFooIndex = new documents.TextDocument("/node_modules/bar/node_modules/foo/index.d.ts", fooIndexText);
|
||||
@@ -177,7 +180,7 @@ describe("unittests:: Program.isSourceFileFromExternalLibrary", () => {
|
||||
describe("unittests:: Program.getNodeCount / Program.getIdentifierCount", () => {
|
||||
it("works on projects that have .json files", () => {
|
||||
const main = new documents.TextDocument("/main.ts", 'export { version } from "./package.json";');
|
||||
const pkg = new documents.TextDocument("/package.json", '{"version": "1.0.0"}');
|
||||
const pkg = new documents.TextDocument("/package.json", jsonToReadableText({ version: "1.0.0" }));
|
||||
|
||||
const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false, { documents: [main, pkg], cwd: "/" });
|
||||
const program = ts.createProgram(["/main.ts"], { resolveJsonModule: true }, new fakes.CompilerHost(fs, { newLine: ts.NewLineKind.LineFeed }));
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as ts from "../_namespaces/ts";
|
||||
import * as Utils from "../_namespaces/Utils";
|
||||
import {
|
||||
createTestCompilerHost,
|
||||
jsonToReadableText,
|
||||
NamedSourceText,
|
||||
newLine,
|
||||
newProgram,
|
||||
@@ -36,7 +37,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
addedHeader = true;
|
||||
baselines.push(`${cacheType}:`);
|
||||
}
|
||||
baselines.push(`${key}: ${mode ? ts.getNameOfCompilerOptionValue(mode, ts.moduleOptionDeclaration.type) + ": " : ""}${JSON.stringify(resolved, /*replacer*/ undefined, 2)}`);
|
||||
baselines.push(`${key}: ${mode ? ts.getNameOfCompilerOptionValue(mode, ts.moduleOptionDeclaration.type) + ": " : ""}${jsonToReadableText(resolved)}`);
|
||||
}
|
||||
}
|
||||
function baselineProgram(baselines: string[], program: ts.Program, host?: TestCompilerHost) {
|
||||
@@ -52,7 +53,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
host.getTrace().forEach(trace => baselines.push(Utils.sanitizeTraceResolutionLogEntry(trace)));
|
||||
host.clearTrace();
|
||||
baselines.push("");
|
||||
baselines.push(`MissingPaths:: ${JSON.stringify(program.getMissingFilePaths())}`);
|
||||
baselines.push(`MissingPaths:: ${jsonToReadableText(program.getMissingFilePaths())}`);
|
||||
baselines.push("");
|
||||
baselines.push(ts.formatDiagnostics(program.getSemanticDiagnostics(), {
|
||||
getCurrentDirectory: () => program.getCurrentDirectory(),
|
||||
@@ -103,7 +104,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
{ name: "/a.ts", text: SourceText.New("", "import {b} from 'b'", "var a = b;") },
|
||||
{ name: "/node_modules/b/index.d.ts", text: SourceText.New("", "export * from './internal';", "") },
|
||||
{ name: "/node_modules/b/internal.d.ts", text: SourceText.New("", "", "export const b = 1;") },
|
||||
{ name: "/node_modules/b/package.json", text: SourceText.New("", "", JSON.stringify({ name: "b", version: "1.2.3" })) },
|
||||
{ name: "/node_modules/b/package.json", text: SourceText.New("", "", jsonToReadableText({ name: "b", version: "1.2.3" })) },
|
||||
];
|
||||
|
||||
const options: ts.CompilerOptions = { target, moduleResolution: ts.ModuleResolutionKind.Node10 };
|
||||
@@ -462,7 +463,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
},
|
||||
{
|
||||
name: axPackage,
|
||||
text: SourceText.New("", "", JSON.stringify({ name: "x", version: "1.2.3" })),
|
||||
text: SourceText.New("", "", jsonToReadableText({ name: "x", version: "1.2.3" })),
|
||||
},
|
||||
{
|
||||
name: "/node_modules/b/index.d.ts",
|
||||
@@ -474,7 +475,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
},
|
||||
{
|
||||
name: bxPackage,
|
||||
text: SourceText.New("", "", JSON.stringify({ name: "x", version: options ? options.bVersion : "1.2.3" })),
|
||||
text: SourceText.New("", "", jsonToReadableText({ name: "x", version: options ? options.bVersion : "1.2.3" })),
|
||||
},
|
||||
{
|
||||
name: root,
|
||||
@@ -513,7 +514,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
|
||||
const program2 = updateRedirectProgram(program1, files => {
|
||||
updateProgramText(files, axIndex, "export default class X { private x: number; private y: number; }");
|
||||
updateProgramText(files, axPackage, JSON.stringify('{ name: "x", version: "1.2.4" }'));
|
||||
updateProgramText(files, axPackage, jsonToReadableText('{ name: "x", version: "1.2.4" }'));
|
||||
}, useGetSourceFileByPath);
|
||||
baselineProgram(baselines, program2);
|
||||
runRedirectsBaseline("target changes", useGetSourceFileByPath, baselines);
|
||||
@@ -526,7 +527,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
|
||||
const program2 = updateRedirectProgram(program1, files => {
|
||||
updateProgramText(files, bxIndex, "export default class X { private x: number; private y: number; }");
|
||||
updateProgramText(files, bxPackage, JSON.stringify({ name: "x", version: "1.2.4" }));
|
||||
updateProgramText(files, bxPackage, jsonToReadableText({ name: "x", version: "1.2.4" }));
|
||||
}, useGetSourceFileByPath);
|
||||
baselineProgram(baselines, program2);
|
||||
runRedirectsBaseline("underlying changes", useGetSourceFileByPath, baselines);
|
||||
@@ -539,7 +540,7 @@ describe("unittests:: Reuse program structure:: General", () => {
|
||||
|
||||
const program2 = updateRedirectProgram(program1, files => {
|
||||
updateProgramText(files, bxIndex, "export default class X { private x: number; }");
|
||||
updateProgramText(files, bxPackage, JSON.stringify({ name: "x", version: "1.2.3" }));
|
||||
updateProgramText(files, bxPackage, jsonToReadableText({ name: "x", version: "1.2.3" }));
|
||||
}, useGetSourceFileByPath);
|
||||
baselineProgram(baselines, program2);
|
||||
runRedirectsBaseline(`previous duplicate packages`, useGetSourceFileByPath, baselines);
|
||||
@@ -584,7 +585,7 @@ describe("unittests:: Reuse program structure:: isProgramUptoDate", () => {
|
||||
function duplicate(options: ts.CompilerOptions): ts.CompilerOptions;
|
||||
function duplicate(fileNames: string[]): string[];
|
||||
function duplicate(filesOrOptions: ts.CompilerOptions | string[]) {
|
||||
return JSON.parse(JSON.stringify(filesOrOptions));
|
||||
return JSON.parse(jsonToReadableText(filesOrOptions));
|
||||
}
|
||||
|
||||
describe("should return true when there is no change in compiler options and", () => {
|
||||
@@ -646,7 +647,7 @@ describe("unittests:: Reuse program structure:: isProgramUptoDate", () => {
|
||||
};
|
||||
const configFile: File = {
|
||||
path: "/src/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions }),
|
||||
content: jsonToReadableText({ compilerOptions }),
|
||||
};
|
||||
const es5Lib: File = {
|
||||
path: "/compiler/lib.es5.d.ts",
|
||||
@@ -692,7 +693,7 @@ describe("unittests:: Reuse program structure:: isProgramUptoDate", () => {
|
||||
};
|
||||
const configFile: File = {
|
||||
path: "/src/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions }),
|
||||
content: jsonToReadableText({ compilerOptions }),
|
||||
};
|
||||
|
||||
verifyProgram([app, module1, module2, module3, libFile, configFile], [app.path], compilerOptions, configFile.path);
|
||||
@@ -730,7 +731,7 @@ describe("unittests:: Reuse program structure:: isProgramUptoDate", () => {
|
||||
};
|
||||
const configFile: File = {
|
||||
path: "/src/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions, include: ["packages/**/*.ts"] }),
|
||||
content: jsonToReadableText({ compilerOptions, include: ["packages/**/*.ts"] }),
|
||||
};
|
||||
verifyProgramWithConfigFile(createWatchedSystem([app, module1, module2, module3, libFile, configFile]), configFile.path);
|
||||
});
|
||||
|
||||
@@ -3,6 +3,9 @@ import {
|
||||
} from "chai";
|
||||
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
createServerHost,
|
||||
File,
|
||||
@@ -152,7 +155,7 @@ export function Component(x: Config): any;`,
|
||||
function setup(useSourceOfProjectReferenceRedirect: (() => boolean) | undefined) {
|
||||
const config1: File = {
|
||||
path: `/user/username/projects/myproject/projects/project1/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "none",
|
||||
composite: true,
|
||||
@@ -170,7 +173,7 @@ export function Component(x: Config): any;`,
|
||||
};
|
||||
const config2: File = {
|
||||
path: `/user/username/projects/myproject/projects/project2/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "none",
|
||||
composite: true,
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
|
||||
describe("unittests:: services:: PreProcessFile:", () => {
|
||||
function test(sourceText: string, readImportFile: boolean, detectJavaScriptImports: boolean, expectedPreProcess: ts.PreProcessedFileInfo): void {
|
||||
@@ -18,7 +21,7 @@ describe("unittests:: services:: PreProcessFile:", () => {
|
||||
if (expected === actual) {
|
||||
return;
|
||||
}
|
||||
assert.deepEqual(actual, expected, `Expected [${kind}] ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
||||
assert.deepEqual(actual, expected, `Expected [${kind}] ${jsonToReadableText(expected)}, got ${jsonToReadableText(actual)}`);
|
||||
}
|
||||
|
||||
describe("Test preProcessFiles,", () => {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
@@ -11,7 +17,7 @@ import {
|
||||
addTripleSlashRef,
|
||||
appendText,
|
||||
enableStrict,
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
removeRest,
|
||||
replaceText,
|
||||
} from "../helpers/vfs";
|
||||
@@ -19,7 +25,45 @@ import {
|
||||
describe("unittests:: tsbuild:: outFile:: on amd modules with --out", () => {
|
||||
let outFileFs: vfs.FileSystem;
|
||||
before(() => {
|
||||
outFileFs = loadProjectFromDisk("tests/projects/amdModulesWithOut");
|
||||
outFileFs = loadProjectFromFiles({
|
||||
"/src/app/file3.ts": dedent`
|
||||
export const z = 30;
|
||||
import { x } from "file1";
|
||||
`,
|
||||
"/src/app/file4.ts": `const myVar = 30;`,
|
||||
"/src/app/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
ignoreDeprecations: "5.0",
|
||||
target: "es5",
|
||||
module: "amd",
|
||||
composite: true,
|
||||
strict: false,
|
||||
sourceMap: true,
|
||||
declarationMap: true,
|
||||
outFile: "module.js",
|
||||
},
|
||||
exclude: ["module.d.ts"],
|
||||
references: [
|
||||
{ path: "../lib", prepend: true },
|
||||
],
|
||||
}),
|
||||
"/src/lib/file0.ts": `const myGlob = 20;`,
|
||||
"/src/lib/file1.ts": `export const x = 10;`,
|
||||
"/src/lib/file2.ts": `export const y = 20;`,
|
||||
"/src/lib/global.ts": `const globalConst = 10;`,
|
||||
"/src/lib/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
target: "es5",
|
||||
module: "amd",
|
||||
composite: true,
|
||||
sourceMap: true,
|
||||
declarationMap: true,
|
||||
strict: false,
|
||||
outFile: "module.js",
|
||||
},
|
||||
exclude: ["module.d.ts"],
|
||||
}),
|
||||
});
|
||||
});
|
||||
after(() => {
|
||||
outFileFs = undefined!;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import {
|
||||
noop,
|
||||
} from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
noChangeRun,
|
||||
verifyTsc,
|
||||
@@ -18,7 +21,7 @@ describe("unittests:: tsbuild - clean::", () => {
|
||||
loadProjectFromFiles({
|
||||
"/src/index.js": "",
|
||||
"/src/bar.ts": "",
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { allowJs: true },
|
||||
}),
|
||||
}),
|
||||
@@ -30,7 +33,7 @@ describe("unittests:: tsbuild - clean::", () => {
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/src/main.tsx": "export const x = 10;",
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { declaration: true },
|
||||
include: ["src/**/*.tsx", "src/**/*.ts"],
|
||||
}),
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
compilerOptionsToConfigJson,
|
||||
} from "../helpers/contents";
|
||||
@@ -71,7 +74,7 @@ describe("unittests:: tsbuild:: commandLine::", () => {
|
||||
}
|
||||
function fs(options: ts.CompilerOptions) {
|
||||
return loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions: compilerOptionsToConfigJson(options) }),
|
||||
"/src/project/tsconfig.json": jsonToReadableText({ compilerOptions: compilerOptionsToConfigJson(options) }),
|
||||
"/src/project/a.ts": `export const a = 10;const aLocal = 10;`,
|
||||
"/src/project/b.ts": `export const b = 10;const bLocal = 10;`,
|
||||
"/src/project/c.ts": `import { a } from "./a";export const c = a;`,
|
||||
@@ -168,14 +171,14 @@ describe("unittests:: tsbuild:: commandLine::", () => {
|
||||
describe("emitDeclarationOnly::", () => {
|
||||
function fs(options: ts.CompilerOptions) {
|
||||
return loadProjectFromFiles({
|
||||
"/src/project1/src/tsconfig.json": JSON.stringify({
|
||||
"/src/project1/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: compilerOptionsToConfigJson(options),
|
||||
}),
|
||||
"/src/project1/src/a.ts": `export const a = 10;const aLocal = 10;`,
|
||||
"/src/project1/src/b.ts": `export const b = 10;const bLocal = 10;`,
|
||||
"/src/project1/src/c.ts": `import { a } from "./a";export const c = a;`,
|
||||
"/src/project1/src/d.ts": `import { b } from "./b";export const d = b;`,
|
||||
"/src/project2/src/tsconfig.json": JSON.stringify({
|
||||
"/src/project2/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: compilerOptionsToConfigJson(options),
|
||||
references: [{ path: "../../project1/src" }],
|
||||
}),
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
noChangeRun,
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
appendText,
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
replaceText,
|
||||
} from "../helpers/vfs";
|
||||
@@ -16,7 +18,30 @@ describe("unittests:: tsbuild:: configFileErrors:: when tsconfig extends the mis
|
||||
verifyTsc({
|
||||
scenario: "configFileErrors",
|
||||
subScenario: "when tsconfig extends the missing file",
|
||||
fs: () => loadProjectFromDisk("tests/projects/missingExtendedConfig"),
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/tsconfig.first.json": jsonToReadableText({
|
||||
extends: "./foobar.json",
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
},
|
||||
}),
|
||||
"/src/tsconfig.second.json": jsonToReadableText({
|
||||
extends: "./foobar.json",
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
},
|
||||
}),
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
},
|
||||
references: [
|
||||
{ path: "./tsconfig.first.json" },
|
||||
{ path: "./tsconfig.second.json" },
|
||||
],
|
||||
}),
|
||||
}),
|
||||
commandLineArgs: ["--b", "/src/tsconfig.json"],
|
||||
});
|
||||
});
|
||||
@@ -66,7 +91,7 @@ describe("unittests:: tsbuild:: configFileErrors:: reports syntax errors in conf
|
||||
edit: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true, declaration: true },
|
||||
files: ["a.ts", "b.ts"],
|
||||
}),
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
@@ -8,18 +11,18 @@ import {
|
||||
describe("unittests:: tsbuild:: configFileExtends:: when tsconfig extends another config", () => {
|
||||
function getConfigExtendsWithIncludeFs() {
|
||||
return loadProjectFromFiles({
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
references: [
|
||||
{ path: "./shared/tsconfig.json" },
|
||||
{ path: "./webpack/tsconfig.json" },
|
||||
],
|
||||
files: [],
|
||||
}),
|
||||
"/src/shared/tsconfig-base.json": JSON.stringify({
|
||||
"/src/shared/tsconfig-base.json": jsonToReadableText({
|
||||
include: ["./typings-base/"],
|
||||
}),
|
||||
"/src/shared/typings-base/globals.d.ts": `type Unrestricted = any;`,
|
||||
"/src/shared/tsconfig.json": JSON.stringify({
|
||||
"/src/shared/tsconfig.json": jsonToReadableText({
|
||||
extends: "./tsconfig-base.json",
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
@@ -29,7 +32,7 @@ describe("unittests:: tsbuild:: configFileExtends:: when tsconfig extends anothe
|
||||
files: ["./index.ts"],
|
||||
}),
|
||||
"/src/shared/index.ts": `export const a: Unrestricted = 1;`,
|
||||
"/src/webpack/tsconfig.json": JSON.stringify({
|
||||
"/src/webpack/tsconfig.json": jsonToReadableText({
|
||||
extends: "../shared/tsconfig-base.json",
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
noChangeOnlyRuns,
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
replaceText,
|
||||
} from "../helpers/vfs";
|
||||
@@ -12,7 +14,53 @@ describe("unittests:: tsbuild:: when containerOnly project is referenced", () =>
|
||||
verifyTsc({
|
||||
scenario: "containerOnlyReferenced",
|
||||
subScenario: "verify that subsequent builds after initial build doesnt build anything",
|
||||
fs: () => loadProjectFromDisk("tests/projects/containerOnlyReferenced"),
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/src/folder/index.ts": `export const x = 10;`,
|
||||
"/src/src/folder/tsconfig.json": jsonToReadableText({
|
||||
files: ["index.ts"],
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
},
|
||||
}),
|
||||
"/src/src/folder2/index.ts": `export const x = 10;`,
|
||||
"/src/src/folder2/tsconfig.json": jsonToReadableText({
|
||||
files: ["index.ts"],
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
},
|
||||
}),
|
||||
"/src/src/tsconfig.json": jsonToReadableText({
|
||||
files: [],
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
},
|
||||
references: [
|
||||
{ path: "./folder" },
|
||||
{ path: "./folder2" },
|
||||
],
|
||||
}),
|
||||
"/src/tests/index.ts": `export const x = 10;`,
|
||||
"/src/tests/tsconfig.json": jsonToReadableText({
|
||||
files: ["index.ts"],
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
},
|
||||
references: [
|
||||
{ path: "../src" },
|
||||
],
|
||||
}),
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
files: [],
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
},
|
||||
references: [
|
||||
{ path: "./src" },
|
||||
{ path: "./tests" },
|
||||
],
|
||||
}),
|
||||
}),
|
||||
commandLineArgs: ["--b", "/src", "--verbose"],
|
||||
edits: noChangeOnlyRuns,
|
||||
});
|
||||
@@ -22,21 +70,21 @@ describe("unittests:: tsbuild:: when containerOnly project is referenced", () =>
|
||||
subScenario: "when solution is referenced indirectly",
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project1/tsconfig.json": JSON.stringify({
|
||||
"/src/project1/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
references: [],
|
||||
}),
|
||||
"/src/project2/tsconfig.json": JSON.stringify({
|
||||
"/src/project2/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
references: [],
|
||||
}),
|
||||
"/src/project2/src/b.ts": "export const b = 10;",
|
||||
"/src/project3/tsconfig.json": JSON.stringify({
|
||||
"/src/project3/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
references: [{ path: "../project1" }, { path: "../project2" }],
|
||||
}),
|
||||
"/src/project3/src/c.ts": "export const c = 10;",
|
||||
"/src/project4/tsconfig.json": JSON.stringify({
|
||||
"/src/project4/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
references: [{ path: "../project3" }],
|
||||
}),
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import * as Utils from "../../_namespaces/Utils";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
FileSet,
|
||||
} from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
@@ -8,40 +15,40 @@ import {
|
||||
} from "../helpers/vfs";
|
||||
|
||||
describe("unittests:: tsbuild:: declarationEmit", () => {
|
||||
function getFiles(): vfs.FileSet {
|
||||
function getFiles(): FileSet {
|
||||
return {
|
||||
"/src/solution/tsconfig.base.json": JSON.stringify({
|
||||
"/src/solution/tsconfig.base.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
rootDir: "./",
|
||||
outDir: "lib",
|
||||
},
|
||||
}),
|
||||
"/src/solution/tsconfig.json": JSON.stringify({
|
||||
"/src/solution/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
references: [{ path: "./src" }],
|
||||
include: [],
|
||||
}),
|
||||
"/src/solution/src/tsconfig.json": JSON.stringify({
|
||||
"/src/solution/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
references: [{ path: "./subProject" }, { path: "./subProject2" }],
|
||||
include: [],
|
||||
}),
|
||||
"/src/solution/src/subProject/tsconfig.json": JSON.stringify({
|
||||
"/src/solution/src/subProject/tsconfig.json": jsonToReadableText({
|
||||
extends: "../../tsconfig.base.json",
|
||||
compilerOptions: { composite: true },
|
||||
references: [{ path: "../common" }],
|
||||
include: ["./index.ts"],
|
||||
}),
|
||||
"/src/solution/src/subProject/index.ts": Utils.dedent`
|
||||
"/src/solution/src/subProject/index.ts": dedent`
|
||||
import { Nominal } from '../common/nominal';
|
||||
export type MyNominal = Nominal<string, 'MyNominal'>;`,
|
||||
"/src/solution/src/subProject2/tsconfig.json": JSON.stringify({
|
||||
"/src/solution/src/subProject2/tsconfig.json": jsonToReadableText({
|
||||
extends: "../../tsconfig.base.json",
|
||||
compilerOptions: { composite: true },
|
||||
references: [{ path: "../subProject" }],
|
||||
include: ["./index.ts"],
|
||||
}),
|
||||
"/src/solution/src/subProject2/index.ts": Utils.dedent`
|
||||
"/src/solution/src/subProject2/index.ts": dedent`
|
||||
import { MyNominal } from '../subProject/index';
|
||||
const variable = {
|
||||
key: 'value' as MyNominal,
|
||||
@@ -49,15 +56,15 @@ const variable = {
|
||||
export function getVar(): keyof typeof variable {
|
||||
return 'key';
|
||||
}`,
|
||||
"/src/solution/src/common/tsconfig.json": JSON.stringify({
|
||||
"/src/solution/src/common/tsconfig.json": jsonToReadableText({
|
||||
extends: "../../tsconfig.base.json",
|
||||
compilerOptions: { composite: true },
|
||||
include: ["./nominal.ts"],
|
||||
}),
|
||||
"/src/solution/src/common/nominal.ts": Utils.dedent`
|
||||
"/src/solution/src/common/nominal.ts": dedent`
|
||||
/// <reference path="./types.d.ts" />
|
||||
export declare type Nominal<T, Name extends string> = MyNominal<T, Name>;`,
|
||||
"/src/solution/src/common/types.d.ts": Utils.dedent`
|
||||
"/src/solution/src/common/types.d.ts": dedent`
|
||||
declare type MyNominal<T, Name extends string> = T & {
|
||||
specialKey: Name;
|
||||
};`,
|
||||
@@ -76,7 +83,7 @@ declare type MyNominal<T, Name extends string> = T & {
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
...getFiles(),
|
||||
"/src/solution/tsconfig.json": JSON.stringify({
|
||||
"/src/solution/tsconfig.json": jsonToReadableText({
|
||||
extends: "./tsconfig.base.json",
|
||||
compilerOptions: { composite: true },
|
||||
include: ["./src/**/*.ts"],
|
||||
@@ -90,32 +97,32 @@ declare type MyNominal<T, Name extends string> = T & {
|
||||
subScenario: "when declaration file used inferred type from referenced project",
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
baseUrl: ".",
|
||||
paths: { "@fluentui/*": ["packages/*/src"] },
|
||||
},
|
||||
}),
|
||||
"/src/packages/pkg1/src/index.ts": Utils.dedent`
|
||||
"/src/packages/pkg1/src/index.ts": dedent`
|
||||
export interface IThing {
|
||||
a: string;
|
||||
}
|
||||
export interface IThings {
|
||||
thing1: IThing;
|
||||
}`,
|
||||
"/src/packages/pkg1/tsconfig.json": JSON.stringify({
|
||||
"/src/packages/pkg1/tsconfig.json": jsonToReadableText({
|
||||
extends: "../../tsconfig",
|
||||
compilerOptions: { outDir: "lib" },
|
||||
include: ["src"],
|
||||
}),
|
||||
"/src/packages/pkg2/src/index.ts": Utils.dedent`
|
||||
"/src/packages/pkg2/src/index.ts": dedent`
|
||||
import { IThings } from '@fluentui/pkg1';
|
||||
export function fn4() {
|
||||
const a: IThings = { thing1: { a: 'b' } };
|
||||
return a.thing1;
|
||||
}`,
|
||||
"/src/packages/pkg2/tsconfig.json": JSON.stringify({
|
||||
"/src/packages/pkg2/tsconfig.json": jsonToReadableText({
|
||||
extends: "../../tsconfig",
|
||||
compilerOptions: { outDir: "lib" },
|
||||
include: ["src"],
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
getFsContentsForDemoProjectReferencesCoreConfig,
|
||||
getFsForDemoProjectReferences,
|
||||
} from "../helpers/demoProjectReferences";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
loadProjectFromDisk,
|
||||
prependText,
|
||||
replaceText,
|
||||
} from "../helpers/vfs";
|
||||
|
||||
describe("unittests:: tsbuild:: on demo project", () => {
|
||||
let projFs: vfs.FileSystem;
|
||||
before(() => {
|
||||
projFs = loadProjectFromDisk("tests/projects/demo");
|
||||
projFs = getFsForDemoProjectReferences();
|
||||
});
|
||||
|
||||
after(() => {
|
||||
@@ -22,36 +24,33 @@ describe("unittests:: tsbuild:: on demo project", () => {
|
||||
scenario: "demo",
|
||||
subScenario: "in master branch with everything setup correctly and reports no error",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig.json", "--verbose"],
|
||||
commandLineArgs: ["--b", "--verbose"],
|
||||
});
|
||||
|
||||
verifyTsc({
|
||||
scenario: "demo",
|
||||
subScenario: "in circular branch reports the error about it by stopping build",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig.json", "--verbose"],
|
||||
commandLineArgs: ["--b", "--verbose"],
|
||||
modifyFs: fs =>
|
||||
replaceText(
|
||||
fs,
|
||||
"/src/core/tsconfig.json",
|
||||
"}",
|
||||
`},
|
||||
"references": [
|
||||
{
|
||||
"path": "../zoo"
|
||||
}
|
||||
]`,
|
||||
fs.writeFileSync(
|
||||
"core/tsconfig.json",
|
||||
getFsContentsForDemoProjectReferencesCoreConfig({
|
||||
references: [{
|
||||
path: "../zoo",
|
||||
}],
|
||||
}),
|
||||
),
|
||||
});
|
||||
verifyTsc({
|
||||
scenario: "demo",
|
||||
subScenario: "in bad-ref branch reports the error about files not in rootDir at the import location",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig.json", "--verbose"],
|
||||
commandLineArgs: ["--b", "--verbose"],
|
||||
modifyFs: fs =>
|
||||
prependText(
|
||||
fs,
|
||||
"/src/core/utilities.ts",
|
||||
"core/utilities.ts",
|
||||
`import * as A from '../animals';
|
||||
`,
|
||||
),
|
||||
|
||||
@@ -1,16 +1,66 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
replaceText,
|
||||
} from "../helpers/vfs";
|
||||
|
||||
describe("unittests:: tsbuild:: on project with emitDeclarationOnly set to true", () => {
|
||||
let projFs: vfs.FileSystem;
|
||||
before(() => {
|
||||
projFs = loadProjectFromDisk("tests/projects/emitDeclarationOnly");
|
||||
projFs = loadProjectFromFiles({
|
||||
"/src/src/a.ts": dedent`
|
||||
import { B } from "./b";
|
||||
|
||||
export interface A {
|
||||
b: B;
|
||||
}
|
||||
`,
|
||||
"/src/src/b.ts": dedent`
|
||||
import { C } from "./c";
|
||||
|
||||
export interface B {
|
||||
b: C;
|
||||
}
|
||||
`,
|
||||
"/src/src/c.ts": dedent`
|
||||
import { A } from "./a";
|
||||
|
||||
export interface C {
|
||||
a: A;
|
||||
}
|
||||
`,
|
||||
"/src/src/index.ts": dedent`
|
||||
export { A } from "./a";
|
||||
export { B } from "./b";
|
||||
export { C } from "./c";
|
||||
`,
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
incremental: true,
|
||||
target: "es5",
|
||||
module: "commonjs",
|
||||
declaration: true,
|
||||
declarationMap: true,
|
||||
sourceMap: true,
|
||||
outDir: "./lib",
|
||||
composite: true,
|
||||
strict: true,
|
||||
esModuleInterop: true,
|
||||
alwaysStrict: true,
|
||||
rootDir: "src",
|
||||
emitDeclarationOnly: true,
|
||||
},
|
||||
}),
|
||||
});
|
||||
});
|
||||
after(() => {
|
||||
projFs = undefined!;
|
||||
|
||||
@@ -1,31 +1,60 @@
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
} from "../helpers/vfs";
|
||||
|
||||
describe("unittests:: tsbuild - empty files option in tsconfig", () => {
|
||||
let projFs: vfs.FileSystem;
|
||||
before(() => {
|
||||
projFs = loadProjectFromDisk("tests/projects/empty-files");
|
||||
});
|
||||
after(() => {
|
||||
projFs = undefined!;
|
||||
});
|
||||
|
||||
verifyTsc({
|
||||
scenario: "emptyFiles",
|
||||
subScenario: "has empty files diagnostic when files is empty and no references are provided",
|
||||
fs: () => projFs,
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/no-references/tsconfig.json": jsonToReadableText({
|
||||
references: [],
|
||||
files: [],
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
declaration: true,
|
||||
forceConsistentCasingInFileNames: true,
|
||||
skipDefaultLibCheck: true,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
commandLineArgs: ["--b", "/src/no-references"],
|
||||
});
|
||||
|
||||
verifyTsc({
|
||||
scenario: "emptyFiles",
|
||||
subScenario: "does not have empty files diagnostic when files is empty and references are provided",
|
||||
fs: () => projFs,
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/core/index.ts": "export function multiply(a: number, b: number) { return a * b; }",
|
||||
"/src/core/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
declaration: true,
|
||||
declarationMap: true,
|
||||
skipDefaultLibCheck: true,
|
||||
},
|
||||
}),
|
||||
"/src/with-references/tsconfig.json": jsonToReadableText({
|
||||
references: [
|
||||
{ path: "../core" },
|
||||
],
|
||||
files: [],
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
declaration: true,
|
||||
forceConsistentCasingInFileNames: true,
|
||||
skipDefaultLibCheck: true,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
commandLineArgs: ["--b", "/src/with-references"],
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,9 @@ import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
compilerOptionsToConfigJson,
|
||||
} from "../helpers/contents";
|
||||
@@ -25,7 +28,7 @@ describe("unittests:: tsbuild:: fileDelete::", () => {
|
||||
export function child2() {
|
||||
}
|
||||
`,
|
||||
"/src/child/tsconfig.json": JSON.stringify({
|
||||
"/src/child/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: compilerOptionsToConfigJson(childOptions),
|
||||
}),
|
||||
...(mainOptions ? {
|
||||
@@ -35,7 +38,7 @@ describe("unittests:: tsbuild:: fileDelete::", () => {
|
||||
child();
|
||||
}
|
||||
`,
|
||||
"/src/main/tsconfig.json": JSON.stringify({
|
||||
"/src/main/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: compilerOptionsToConfigJson(mainOptions),
|
||||
references: [{ path: "../child" }],
|
||||
}),
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import * as fakes from "../../_namespaces/fakes";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
|
||||
describe("unittests:: tsbuild - graph-ordering", () => {
|
||||
let host: fakes.SolutionBuilderHost | undefined;
|
||||
@@ -80,15 +83,11 @@ describe("unittests:: tsbuild - graph-ordering", () => {
|
||||
fileSystem.mkdirpSync(`/project/${proj}`);
|
||||
fileSystem.writeFileSync(`/project/${proj}/${proj}.ts`, "export {}");
|
||||
const configFileName = getProjectFileName(proj);
|
||||
const configContent = JSON.stringify(
|
||||
{
|
||||
compilerOptions: { composite: true },
|
||||
files: [`./${proj}.ts`],
|
||||
references: deps.filter(d => d[0] === proj).map(d => ({ path: `../${d[1]}` })),
|
||||
},
|
||||
undefined,
|
||||
2,
|
||||
);
|
||||
const configContent = jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
files: [`./${proj}.ts`],
|
||||
references: deps.filter(d => d[0] === proj).map(d => ({ path: `../${d[1]}` })),
|
||||
});
|
||||
fileSystem.writeFileSync(configFileName, configContent);
|
||||
projFileNames.push(configFileName);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,74 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
appendText,
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
replaceText,
|
||||
} from "../helpers/vfs";
|
||||
|
||||
describe("unittests:: tsbuild:: inferredTypeFromTransitiveModule::", () => {
|
||||
let projFs: vfs.FileSystem;
|
||||
before(() => {
|
||||
projFs = loadProjectFromDisk("tests/projects/inferredTypeFromTransitiveModule");
|
||||
projFs = loadProjectFromFiles({
|
||||
"/src/bar.ts": dedent`
|
||||
interface RawAction {
|
||||
(...args: any[]): Promise<any> | void;
|
||||
}
|
||||
interface ActionFactory {
|
||||
<T extends RawAction>(target: T): T;
|
||||
}
|
||||
declare function foo<U extends any[] = any[]>(): ActionFactory;
|
||||
export default foo()(function foobar(param: string): void {
|
||||
});
|
||||
`,
|
||||
"/src/bundling.ts": dedent`
|
||||
export class LazyModule<TModule> {
|
||||
constructor(private importCallback: () => Promise<TModule>) {}
|
||||
}
|
||||
|
||||
export class LazyAction<
|
||||
TAction extends (...args: any[]) => any,
|
||||
TModule
|
||||
> {
|
||||
constructor(_lazyModule: LazyModule<TModule>, _getter: (module: TModule) => TAction) {
|
||||
}
|
||||
}
|
||||
`,
|
||||
"/src/global.d.ts": dedent`
|
||||
interface PromiseConstructor {
|
||||
new <T>(): Promise<T>;
|
||||
}
|
||||
declare var Promise: PromiseConstructor;
|
||||
interface Promise<T> {
|
||||
}
|
||||
`,
|
||||
"/src/index.ts": dedent`
|
||||
import { LazyAction, LazyModule } from './bundling';
|
||||
const lazyModule = new LazyModule(() =>
|
||||
import('./lazyIndex')
|
||||
);
|
||||
export const lazyBar = new LazyAction(lazyModule, m => m.bar);
|
||||
`,
|
||||
"/src/lazyIndex.ts": dedent`
|
||||
export { default as bar } from './bar';
|
||||
`,
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
target: "es5",
|
||||
declaration: true,
|
||||
outDir: "obj",
|
||||
incremental: true,
|
||||
},
|
||||
}),
|
||||
});
|
||||
});
|
||||
after(() => {
|
||||
projFs = undefined!;
|
||||
|
||||
@@ -1,16 +1,50 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
appendText,
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
replaceText,
|
||||
} from "../helpers/vfs";
|
||||
|
||||
describe("unittests:: tsbuild:: lateBoundSymbol:: interface is merged and contains late bound member", () => {
|
||||
verifyTsc({
|
||||
subScenario: "interface is merged and contains late bound member",
|
||||
fs: () => loadProjectFromDisk("tests/projects/lateBoundSymbol"),
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/src/globals.d.ts": dedent`
|
||||
interface SymbolConstructor {
|
||||
(description?: string | number): symbol;
|
||||
}
|
||||
declare var Symbol: SymbolConstructor;
|
||||
`,
|
||||
"/src/src/hkt.ts": `export interface HKT<T> { }`,
|
||||
"/src/src/main.ts": dedent`
|
||||
import { HKT } from "./hkt";
|
||||
|
||||
const sym = Symbol();
|
||||
|
||||
declare module "./hkt" {
|
||||
interface HKT<T> {
|
||||
[sym]: { a: T }
|
||||
}
|
||||
}
|
||||
const x = 10;
|
||||
type A = HKT<number>[typeof sym];
|
||||
`,
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
rootDir: "src",
|
||||
incremental: true,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
scenario: "lateBoundSymbol",
|
||||
commandLineArgs: ["--b", "/src/tsconfig.json", "--verbose"],
|
||||
edits: [
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as Utils from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
noChangeOnlyRuns,
|
||||
verifyTsc,
|
||||
@@ -26,7 +29,7 @@ describe("unittests:: tsbuild:: moduleResolution:: handles the modules and optio
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg1/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { outDir: "build", ...optionsToExtend },
|
||||
references: [{ path: "../pkg2" }],
|
||||
}),
|
||||
@@ -41,7 +44,7 @@ describe("unittests:: tsbuild:: moduleResolution:: handles the modules and optio
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg2/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
outDir: "build",
|
||||
@@ -52,7 +55,7 @@ describe("unittests:: tsbuild:: moduleResolution:: handles the modules and optio
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg2/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg2",
|
||||
version: "1.0.0",
|
||||
main: "build/index.js",
|
||||
@@ -86,13 +89,13 @@ describe("unittests:: tsbuild:: moduleResolution:: handles the modules and optio
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/packages/pkg1_index.ts": `export const theNum: TheNum = "type1";`,
|
||||
"/src/packages/pkg1.tsconfig.json": JSON.stringify({
|
||||
"/src/packages/pkg1.tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, typeRoots: ["./typeroot1"] },
|
||||
files: ["./pkg1_index.ts"],
|
||||
}),
|
||||
"/src/packages/typeroot1/sometype/index.d.ts": Utils.dedent`declare type TheNum = "type1";`,
|
||||
"/src/packages/pkg2_index.ts": `export const theNum: TheNum2 = "type2";`,
|
||||
"/src/packages/pkg2.tsconfig.json": JSON.stringify({
|
||||
"/src/packages/pkg2.tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, typeRoots: ["./typeroot2"] },
|
||||
files: ["./pkg2_index.ts"],
|
||||
}),
|
||||
@@ -109,22 +112,22 @@ describe("unittests:: tsbuild:: moduleResolution:: impliedNodeFormat differs bet
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/projects/a/src/index.ts": "",
|
||||
"/src/projects/a/tsconfig.json": JSON.stringify({
|
||||
"/src/projects/a/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { strict: true },
|
||||
}),
|
||||
"/src/projects/b/src/index.ts": Utils.dedent`
|
||||
import pg from "pg";
|
||||
pg.foo();
|
||||
`,
|
||||
"/src/projects/b/tsconfig.json": JSON.stringify({
|
||||
"/src/projects/b/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { strict: true, module: "node16" },
|
||||
}),
|
||||
"/src/projects/b/package.json": JSON.stringify({
|
||||
"/src/projects/b/package.json": jsonToReadableText({
|
||||
name: "b",
|
||||
type: "module",
|
||||
}),
|
||||
"/src/projects/node_modules/@types/pg/index.d.ts": "export function foo(): void;",
|
||||
"/src/projects/node_modules/@types/pg/package.json": JSON.stringify({
|
||||
"/src/projects/node_modules/@types/pg/package.json": jsonToReadableText({
|
||||
name: "@types/pg",
|
||||
types: "index.d.ts",
|
||||
}),
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
noChangeRun,
|
||||
verifyTsc,
|
||||
@@ -14,7 +17,7 @@ describe("unittests:: tsbuild:: noEmit", () => {
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/a.ts": aTsContent,
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { noEmit: true },
|
||||
}),
|
||||
}),
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
getFsForNoEmitOnError,
|
||||
} from "../helpers/noEmitOnError";
|
||||
import {
|
||||
noChangeRun,
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
loadProjectFromDisk,
|
||||
} from "../helpers/vfs";
|
||||
|
||||
describe("unittests:: tsbuild - with noEmitOnError", () => {
|
||||
let projFs: vfs.FileSystem;
|
||||
before(() => {
|
||||
projFs = loadProjectFromDisk("tests/projects/noEmitOnError");
|
||||
projFs = getFsForNoEmitOnError();
|
||||
});
|
||||
after(() => {
|
||||
projFs = undefined!;
|
||||
@@ -20,14 +20,14 @@ describe("unittests:: tsbuild - with noEmitOnError", () => {
|
||||
scenario: "noEmitOnError",
|
||||
subScenario: "syntax errors",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig.json"],
|
||||
commandLineArgs: ["--b"],
|
||||
edits: [
|
||||
noChangeRun,
|
||||
{
|
||||
caption: "Fix error",
|
||||
edit: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/src/main.ts",
|
||||
"src/main.ts",
|
||||
`import { A } from "../shared/types/db";
|
||||
const a = {
|
||||
lastName: 'sdsd'
|
||||
@@ -44,14 +44,14 @@ const a = {
|
||||
scenario: "noEmitOnError",
|
||||
subScenario: "syntax errors with incremental",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig.json", "--incremental"],
|
||||
commandLineArgs: ["--b", "--incremental"],
|
||||
edits: [
|
||||
noChangeRun,
|
||||
{
|
||||
caption: "Fix error",
|
||||
edit: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/src/main.ts",
|
||||
"src/main.ts",
|
||||
`import { A } from "../shared/types/db";
|
||||
const a = {
|
||||
lastName: 'sdsd'
|
||||
@@ -70,19 +70,19 @@ const a = {
|
||||
fs: () => projFs,
|
||||
modifyFs: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/src/main.ts",
|
||||
"src/main.ts",
|
||||
`import { A } from "../shared/types/db";
|
||||
const a: string = 10;`,
|
||||
"utf-8",
|
||||
),
|
||||
commandLineArgs: ["--b", "/src/tsconfig.json"],
|
||||
commandLineArgs: ["--b"],
|
||||
edits: [
|
||||
noChangeRun,
|
||||
{
|
||||
caption: "Fix error",
|
||||
edit: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/src/main.ts",
|
||||
"src/main.ts",
|
||||
`import { A } from "../shared/types/db";
|
||||
const a: string = "hello";`,
|
||||
"utf-8",
|
||||
@@ -99,19 +99,19 @@ const a: string = "hello";`,
|
||||
fs: () => projFs,
|
||||
modifyFs: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/src/main.ts",
|
||||
"src/main.ts",
|
||||
`import { A } from "../shared/types/db";
|
||||
const a: string = 10;`,
|
||||
"utf-8",
|
||||
),
|
||||
commandLineArgs: ["--b", "/src/tsconfig.json", "--incremental"],
|
||||
commandLineArgs: ["--b", "--incremental"],
|
||||
edits: [
|
||||
noChangeRun,
|
||||
{
|
||||
caption: "Fix error",
|
||||
edit: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/src/main.ts",
|
||||
"src/main.ts",
|
||||
`import { A } from "../shared/types/db";
|
||||
const a: string = "hello";`,
|
||||
"utf-8",
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import * as fakes from "../../_namespaces/fakes";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
createSolutionBuilderHostForBaseline,
|
||||
} from "../helpers/solutionBuilder";
|
||||
@@ -22,7 +28,7 @@ import {
|
||||
appendText,
|
||||
changeStubToRest,
|
||||
enableStrict,
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
prependText,
|
||||
removeRest,
|
||||
replaceText,
|
||||
@@ -32,7 +38,107 @@ describe("unittests:: tsbuild:: outFile::", () => {
|
||||
let outFileFs: vfs.FileSystem;
|
||||
let outFileWithBuildFs: vfs.FileSystem;
|
||||
before(() => {
|
||||
outFileFs = loadProjectFromDisk("tests/projects/outfile-concat");
|
||||
outFileFs = loadProjectFromFiles({
|
||||
"/src/first/first_PART1.ts": dedent`
|
||||
interface TheFirst {
|
||||
none: any;
|
||||
}
|
||||
|
||||
const s = "Hello, world";
|
||||
|
||||
interface NoJsForHereEither {
|
||||
none: any;
|
||||
}
|
||||
|
||||
console.log(s);
|
||||
`,
|
||||
"/src/first/first_part2.ts": dedent`
|
||||
console.log(f());
|
||||
`,
|
||||
"/src/first/first_part3.ts": dedent`
|
||||
function f() {
|
||||
return "JS does hoists";
|
||||
}
|
||||
`,
|
||||
"/src/first/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
target: "es5",
|
||||
composite: true,
|
||||
removeComments: true,
|
||||
strict: false,
|
||||
sourceMap: true,
|
||||
declarationMap: true,
|
||||
outFile: "./bin/first-output.js",
|
||||
skipDefaultLibCheck: true,
|
||||
},
|
||||
files: [
|
||||
"first_PART1.ts",
|
||||
"first_part2.ts",
|
||||
"first_part3.ts",
|
||||
],
|
||||
references: [],
|
||||
}),
|
||||
"/src/second/second_part1.ts": dedent`
|
||||
namespace N {
|
||||
// Comment text
|
||||
}
|
||||
|
||||
namespace N {
|
||||
function f() {
|
||||
console.log('testing');
|
||||
}
|
||||
|
||||
f();
|
||||
}
|
||||
`,
|
||||
"/src/second/second_part2.ts": dedent`
|
||||
class C {
|
||||
doSomething() {
|
||||
console.log("something got done");
|
||||
}
|
||||
}
|
||||
`,
|
||||
"/src/second/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
ignoreDeprecations: "5.0",
|
||||
target: "es5",
|
||||
composite: true,
|
||||
removeComments: true,
|
||||
strict: false,
|
||||
sourceMap: true,
|
||||
declarationMap: true,
|
||||
declaration: true,
|
||||
outFile: "../2/second-output.js",
|
||||
skipDefaultLibCheck: true,
|
||||
},
|
||||
references: [],
|
||||
}),
|
||||
"/src/third/third_part1.ts": dedent`
|
||||
var c = new C();
|
||||
c.doSomething();
|
||||
`,
|
||||
"/src/third/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
ignoreDeprecations: "5.0",
|
||||
target: "es5",
|
||||
composite: true,
|
||||
removeComments: true,
|
||||
strict: false,
|
||||
sourceMap: true,
|
||||
declarationMap: true,
|
||||
declaration: true,
|
||||
outFile: "./thirdjs/output/third-output.js",
|
||||
skipDefaultLibCheck: true,
|
||||
},
|
||||
files: [
|
||||
"third_part1.ts",
|
||||
],
|
||||
references: [
|
||||
{ path: "../first", prepend: true },
|
||||
{ path: "../second", prepend: true },
|
||||
],
|
||||
}),
|
||||
});
|
||||
});
|
||||
after(() => {
|
||||
outFileFs = undefined!;
|
||||
@@ -497,9 +603,15 @@ ${internal} enum internalEnum { a, b, c }`,
|
||||
"/src/second/tsconfig.json",
|
||||
"[",
|
||||
`[
|
||||
{ "path": "../first", "prepend": true }`,
|
||||
{ "path": "../first", "prepend": true }\n `,
|
||||
);
|
||||
fs.writeFileSync(
|
||||
"/src/third/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
...JSON.parse(fs.readFileSync("/src/third/tsconfig.json", "utf-8")!),
|
||||
references: [{ path: "../second", prepend: true }],
|
||||
}),
|
||||
);
|
||||
replaceText(fs, "/src/third/tsconfig.json", `{ "path": "../first", "prepend": true },`, "");
|
||||
}
|
||||
|
||||
function stripInternalWithDependentOrder(fs: vfs.FileSystem, removeCommentsDisabled?: boolean, jsDocStyle?: boolean) {
|
||||
@@ -632,7 +744,7 @@ ${internal} enum internalEnum { a, b, c }`,
|
||||
fs.writeFileSync("/src/third/third_part1.ts", "const B = 2;");
|
||||
fs.writeFileSync(
|
||||
"/src/first/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
declaration: true,
|
||||
@@ -646,7 +758,7 @@ ${internal} enum internalEnum { a, b, c }`,
|
||||
);
|
||||
fs.writeFileSync(
|
||||
"/src/third/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
ignoreDeprecations: "5.0",
|
||||
composite: true,
|
||||
@@ -700,8 +812,8 @@ ${internal} enum internalEnum { a, b, c }`,
|
||||
commandLineArgs: ["--b", "/src/third", "--verbose"],
|
||||
modifyFs: fs => {
|
||||
// No prepend
|
||||
replaceText(fs, "/src/third/tsconfig.json", `{ "path": "../first", "prepend": true }`, `{ "path": "../first" }`);
|
||||
replaceText(fs, "/src/third/tsconfig.json", `{ "path": "../second", "prepend": true }`, `{ "path": "../second" }`);
|
||||
replaceText(fs, "/src/third/tsconfig.json", `"prepend": true`, "");
|
||||
replaceText(fs, "/src/third/tsconfig.json", `"prepend": true`, "");
|
||||
|
||||
// Non Modules
|
||||
replaceText(fs, "/src/first/tsconfig.json", `"composite": true,`, `"composite": true, "module": "none",`);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import * as fakes from "../../_namespaces/fakes";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
noChangeRun,
|
||||
TestTscEdit,
|
||||
@@ -48,7 +51,7 @@ describe("unittests:: tsbuild - output file paths", () => {
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/src/index.ts": "export const x = 10;",
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "dist",
|
||||
},
|
||||
@@ -62,7 +65,7 @@ describe("unittests:: tsbuild - output file paths", () => {
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/src/index.ts": "export const x = 10;",
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "dist",
|
||||
composite: true,
|
||||
@@ -77,7 +80,7 @@ describe("unittests:: tsbuild - output file paths", () => {
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/src/index.ts": "export const x = 10;",
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "dist",
|
||||
rootDir: "src",
|
||||
@@ -93,7 +96,7 @@ describe("unittests:: tsbuild - output file paths", () => {
|
||||
loadProjectFromFiles({
|
||||
"/src/src/index.ts": "export const x = 10;",
|
||||
"/src/types/type.ts": "export type t = string;",
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "dist",
|
||||
rootDir: "src",
|
||||
@@ -109,7 +112,7 @@ describe("unittests:: tsbuild - output file paths", () => {
|
||||
loadProjectFromFiles({
|
||||
"/src/src/index.ts": "export const x = 10;",
|
||||
"/src/types/type.ts": "export type t = string;",
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "dist",
|
||||
rootDir: "src",
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import * as fakes from "../../_namespaces/fakes";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselinePrograms,
|
||||
commandLineCallbacks,
|
||||
@@ -18,14 +21,14 @@ describe("unittests:: tsbuild:: Public API with custom transformers when passed
|
||||
let sys: TscCompileSystem;
|
||||
before(() => {
|
||||
const inputFs = loadProjectFromFiles({
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
references: [
|
||||
{ path: "./shared/tsconfig.json" },
|
||||
{ path: "./webpack/tsconfig.json" },
|
||||
],
|
||||
files: [],
|
||||
}),
|
||||
"/src/shared/tsconfig.json": JSON.stringify({
|
||||
"/src/shared/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
}),
|
||||
"/src/shared/index.ts": `export function f1() { }
|
||||
@@ -33,7 +36,7 @@ export class c { }
|
||||
export enum e { }
|
||||
// leading
|
||||
export function f2() { } // trailing`,
|
||||
"/src/webpack/tsconfig.json": JSON.stringify({
|
||||
"/src/webpack/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
},
|
||||
|
||||
@@ -1,16 +1,54 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
replaceText,
|
||||
} from "../helpers/vfs";
|
||||
|
||||
describe("unittests:: tsbuild:: with rootDir of project reference in parentDirectory", () => {
|
||||
let projFs: vfs.FileSystem;
|
||||
before(() => {
|
||||
projFs = loadProjectFromDisk("tests/projects/projectReferenceWithRootDirInParent");
|
||||
projFs = loadProjectFromFiles({
|
||||
"/src/src/main/a.ts": dedent`
|
||||
import { b } from './b';
|
||||
const a = b;
|
||||
`,
|
||||
"/src/src/main/b.ts": dedent`
|
||||
export const b = 0;
|
||||
`,
|
||||
"/src/src/main/tsconfig.json": jsonToReadableText({
|
||||
extends: "../../tsconfig.base.json",
|
||||
references: [
|
||||
{ path: "../other" },
|
||||
],
|
||||
}),
|
||||
"/src/src/other/other.ts": dedent`
|
||||
export const Other = 0;
|
||||
`,
|
||||
"/src/src/other/tsconfig.json": jsonToReadableText({
|
||||
extends: "../../tsconfig.base.json",
|
||||
}),
|
||||
"/src/tsconfig.base.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
declaration: true,
|
||||
rootDir: "./src/",
|
||||
outDir: "./dist/",
|
||||
skipDefaultLibCheck: true,
|
||||
},
|
||||
exclude: [
|
||||
"node_modules",
|
||||
],
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
@@ -40,14 +78,14 @@ describe("unittests:: tsbuild:: with rootDir of project reference in parentDirec
|
||||
modifyFs: fs => {
|
||||
fs.writeFileSync(
|
||||
"/src/src/main/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true, outDir: "../../dist/" },
|
||||
references: [{ path: "../other" }],
|
||||
}),
|
||||
);
|
||||
fs.writeFileSync(
|
||||
"/src/src/other/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true, outDir: "../../dist/" },
|
||||
}),
|
||||
);
|
||||
@@ -64,14 +102,14 @@ describe("unittests:: tsbuild:: with rootDir of project reference in parentDirec
|
||||
fs.renameSync("/src/src/other/tsconfig.json", "/src/src/other/tsconfig.other.json");
|
||||
fs.writeFileSync(
|
||||
"/src/src/main/tsconfig.main.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true, outDir: "../../dist/" },
|
||||
references: [{ path: "../other/tsconfig.other.json" }],
|
||||
}),
|
||||
);
|
||||
fs.writeFileSync(
|
||||
"/src/src/other/tsconfig.other.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true, outDir: "../../dist/" },
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -4,6 +4,9 @@ import {
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
noChangeOnlyRuns,
|
||||
verifyTsc,
|
||||
@@ -17,35 +20,27 @@ import {
|
||||
describe("unittests:: tsbuild:: with resolveJsonModule option on project resolveJsonModuleAndComposite", () => {
|
||||
function getProjFs(tsconfigFiles: object, additionalCompilerOptions?: CompilerOptions) {
|
||||
return loadProjectFromFiles({
|
||||
"/src/src/hello.json": JSON.stringify(
|
||||
{
|
||||
hello: "world",
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
"/src/src/hello.json": jsonToReadableText({
|
||||
hello: "world",
|
||||
}),
|
||||
"/src/src/index.ts": dedent`
|
||||
import hello from "./hello.json"
|
||||
export default hello.hello
|
||||
`,
|
||||
"/src/tsconfig.json": JSON.stringify(
|
||||
{
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
moduleResolution: "node",
|
||||
module: "commonjs",
|
||||
resolveJsonModule: true,
|
||||
esModuleInterop: true,
|
||||
allowSyntheticDefaultImports: true,
|
||||
outDir: "dist",
|
||||
skipDefaultLibCheck: true,
|
||||
...additionalCompilerOptions,
|
||||
},
|
||||
...tsconfigFiles,
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
moduleResolution: "node",
|
||||
module: "commonjs",
|
||||
resolveJsonModule: true,
|
||||
esModuleInterop: true,
|
||||
allowSyntheticDefaultImports: true,
|
||||
outDir: "dist",
|
||||
skipDefaultLibCheck: true,
|
||||
...additionalCompilerOptions,
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
...tsconfigFiles,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -169,59 +164,43 @@ describe("unittests:: tsbuild:: with resolveJsonModule option on project importJ
|
||||
subScenario: "importing json module from project reference",
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/strings/foo.json": JSON.stringify(
|
||||
{
|
||||
foo: "bar baz",
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
"/src/strings/tsconfig.json": JSON.stringify(
|
||||
{
|
||||
extends: "../tsconfig.json",
|
||||
include: ["foo.json"],
|
||||
references: [],
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
"/src/strings/foo.json": jsonToReadableText({
|
||||
foo: "bar baz",
|
||||
}),
|
||||
"/src/strings/tsconfig.json": jsonToReadableText({
|
||||
extends: "../tsconfig.json",
|
||||
include: ["foo.json"],
|
||||
references: [],
|
||||
}),
|
||||
"/src/main/index.ts": dedent`
|
||||
import { foo } from '../strings/foo.json';
|
||||
console.log(foo);
|
||||
`,
|
||||
"/src/main/tsconfig.json": JSON.stringify(
|
||||
{
|
||||
extends: "../tsconfig.json",
|
||||
include: [
|
||||
"./**/*.ts",
|
||||
],
|
||||
references: [{
|
||||
path: "../strings/tsconfig.json",
|
||||
}],
|
||||
"/src/main/tsconfig.json": jsonToReadableText({
|
||||
extends: "../tsconfig.json",
|
||||
include: [
|
||||
"./**/*.ts",
|
||||
],
|
||||
references: [{
|
||||
path: "../strings/tsconfig.json",
|
||||
}],
|
||||
}),
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
target: "es5",
|
||||
module: "commonjs",
|
||||
rootDir: "./",
|
||||
composite: true,
|
||||
resolveJsonModule: true,
|
||||
strict: true,
|
||||
esModuleInterop: true,
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
"/src/tsconfig.json": JSON.stringify(
|
||||
{
|
||||
compilerOptions: {
|
||||
target: "es5",
|
||||
module: "commonjs",
|
||||
rootDir: "./",
|
||||
composite: true,
|
||||
resolveJsonModule: true,
|
||||
strict: true,
|
||||
esModuleInterop: true,
|
||||
},
|
||||
references: [
|
||||
{ path: "./strings/tsconfig.json" },
|
||||
{ path: "./main/tsconfig.json" },
|
||||
],
|
||||
files: [],
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
references: [
|
||||
{ path: "./strings/tsconfig.json" },
|
||||
{ path: "./main/tsconfig.json" },
|
||||
],
|
||||
files: [],
|
||||
}),
|
||||
}),
|
||||
commandLineArgs: ["--b", "src/tsconfig.json", "--verbose", "--explainFiles"],
|
||||
edits: noChangeOnlyRuns,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
@@ -17,7 +20,7 @@ describe("unittests:: tsbuild:: roots::", () => {
|
||||
loadProjectFromFiles({
|
||||
"/src/file1.ts": `export const x = "hello";`,
|
||||
"/src/file2.ts": `export const y = "world";`,
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
include: ["*.ts"],
|
||||
}),
|
||||
@@ -42,7 +45,7 @@ describe("unittests:: tsbuild:: roots::", () => {
|
||||
"/src/file2.ts": `export const y = "world";`,
|
||||
"/src/file3.ts": `export const y = "world";`,
|
||||
"/src/file4.ts": `export const y = "world";`,
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
include: ["*.ts"],
|
||||
}),
|
||||
@@ -69,7 +72,7 @@ describe("unittests:: tsbuild:: roots::", () => {
|
||||
import { random } from "./random";
|
||||
export const y = "world";
|
||||
`,
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
include: ["file*.ts"],
|
||||
}),
|
||||
@@ -109,7 +112,7 @@ describe("unittests:: tsbuild:: roots::", () => {
|
||||
import { random } from "./random2";
|
||||
export const nonConsecutive = "hello";
|
||||
`,
|
||||
"/src/tsconfig.json": JSON.stringify({
|
||||
"/src/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
include: ["file*.ts", "nonconsecutive*.ts", "asArray*.ts", "anotherNonConsecutive.ts"],
|
||||
}),
|
||||
|
||||
@@ -2,9 +2,17 @@ import * as fakes from "../../_namespaces/fakes";
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
libContent,
|
||||
libPath,
|
||||
} from "../helpers/contents";
|
||||
import {
|
||||
getFsForSampleProjectReferences,
|
||||
getSysForSampleProjectReferences,
|
||||
} from "../helpers/sampleProjectReferences";
|
||||
import {
|
||||
createSolutionBuilderHostForBaseline,
|
||||
} from "../helpers/solutionBuilder";
|
||||
@@ -19,16 +27,12 @@ import {
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
appendText,
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
prependText,
|
||||
replaceText,
|
||||
} from "../helpers/vfs";
|
||||
import {
|
||||
changeToHostTrackingWrittenFiles,
|
||||
createWatchedSystem,
|
||||
File,
|
||||
getTsBuildProjectFilePath,
|
||||
libFile,
|
||||
TestServerHost,
|
||||
} from "../helpers/virtualFileSystemWithWatch";
|
||||
@@ -37,7 +41,7 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
let projFs: vfs.FileSystem;
|
||||
let projFsWithBuild: vfs.FileSystem;
|
||||
before(() => {
|
||||
projFs = loadProjectFromDisk("tests/projects/sample1");
|
||||
projFs = getFsForSampleProjectReferences();
|
||||
});
|
||||
|
||||
after(() => {
|
||||
@@ -45,19 +49,12 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
projFsWithBuild = undefined!;
|
||||
});
|
||||
|
||||
function getTsBuildProjectFile(project: string, file: string): File {
|
||||
return {
|
||||
path: getTsBuildProjectFilePath(project, file),
|
||||
content: projFs.readFileSync(`/src/${project}/${file}`, "utf8")!,
|
||||
};
|
||||
}
|
||||
|
||||
function getSampleFsAfterBuild() {
|
||||
if (projFsWithBuild) return projFsWithBuild;
|
||||
const fs = projFs.shadow();
|
||||
const sys = new fakes.System(fs, { executingFilePath: "/lib/tsc" });
|
||||
const sys = new fakes.System(fs, { executingFilePath: libFile.path });
|
||||
const host = createSolutionBuilderHostForBaseline(sys as TscCompileSystem);
|
||||
const builder = ts.createSolutionBuilder(host, ["/src/tests"], {});
|
||||
const builder = ts.createSolutionBuilder(host, ["tests"], {});
|
||||
builder.build();
|
||||
fs.makeReadonly();
|
||||
return projFsWithBuild = fs;
|
||||
@@ -68,11 +65,11 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "builds correctly when outDir is specified",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests"],
|
||||
commandLineArgs: ["--b", "tests"],
|
||||
modifyFs: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/logic/tsconfig.json",
|
||||
JSON.stringify({
|
||||
"logic/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true, declaration: true, sourceMap: true, outDir: "outDir" },
|
||||
references: [{ path: "../core" }],
|
||||
}),
|
||||
@@ -83,11 +80,11 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "builds correctly when declarationDir is specified",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests"],
|
||||
commandLineArgs: ["--b", "tests"],
|
||||
modifyFs: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/logic/tsconfig.json",
|
||||
JSON.stringify({
|
||||
"logic/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true, declaration: true, sourceMap: true, declarationDir: "out/decls" },
|
||||
references: [{ path: "../core" }],
|
||||
}),
|
||||
@@ -98,8 +95,8 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "builds correctly when project is not composite or doesnt have any references",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/core", "--verbose"],
|
||||
modifyFs: fs => replaceText(fs, "/src/core/tsconfig.json", `"composite": true,`, ""),
|
||||
commandLineArgs: ["--b", "core", "--verbose"],
|
||||
modifyFs: fs => replaceText(fs, "core/tsconfig.json", `"composite": true,`, ""),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -108,7 +105,7 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "does not write any files in a dry build",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests", "--dry"],
|
||||
commandLineArgs: ["--b", "tests", "--dry"],
|
||||
});
|
||||
});
|
||||
|
||||
@@ -117,7 +114,7 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "removes all files it built",
|
||||
fs: getSampleFsAfterBuild,
|
||||
commandLineArgs: ["--b", "/src/tests", "--clean"],
|
||||
commandLineArgs: ["--b", "tests", "--clean"],
|
||||
edits: noChangeOnlyRuns,
|
||||
});
|
||||
|
||||
@@ -125,11 +122,11 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "cleans till project specified",
|
||||
fs: getSampleFsAfterBuild,
|
||||
commandLineArgs: ["--b", "/src/logic", "--clean"],
|
||||
commandLineArgs: ["--b", "logic", "--clean"],
|
||||
compile: sys => {
|
||||
const buildHost = createSolutionBuilderHostForBaseline(sys);
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], {});
|
||||
sys.exit(builder.clean("/src/logic"));
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["third/tsconfig.json"], {});
|
||||
sys.exit(builder.clean("logic"));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -137,11 +134,11 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "cleaning project in not build order doesnt throw error",
|
||||
fs: getSampleFsAfterBuild,
|
||||
commandLineArgs: ["--b", "/src/logic2", "--clean"],
|
||||
commandLineArgs: ["--b", "logic2", "--clean"],
|
||||
compile: sys => {
|
||||
const buildHost = createSolutionBuilderHostForBaseline(sys);
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["/src/third/tsconfig.json"], {});
|
||||
sys.exit(builder.clean("/src/logic2"));
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["third/tsconfig.json"], {});
|
||||
sys.exit(builder.clean("logic2"));
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -151,7 +148,7 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "always builds under with force option",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests", "--force"],
|
||||
commandLineArgs: ["--b", "tests", "--force"],
|
||||
edits: noChangeOnlyRuns,
|
||||
});
|
||||
});
|
||||
@@ -161,23 +158,23 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "can detect when and what to rebuild",
|
||||
fs: getSampleFsAfterBuild,
|
||||
commandLineArgs: ["--b", "/src/tests", "--verbose"],
|
||||
commandLineArgs: ["--b", "tests", "--verbose"],
|
||||
edits: [
|
||||
// Update a file in the leaf node (tests), only it should rebuild the last one
|
||||
{
|
||||
caption: "Only builds the leaf node project",
|
||||
edit: fs => fs.writeFileSync("/src/tests/index.ts", "const m = 10;"),
|
||||
edit: fs => fs.writeFileSync("tests/index.ts", "const m = 10;"),
|
||||
},
|
||||
// Update a file in the parent (without affecting types), should get fast downstream builds
|
||||
{
|
||||
caption: "Detects type-only changes in upstream projects",
|
||||
edit: fs => replaceText(fs, "/src/core/index.ts", "HELLO WORLD", "WELCOME PLANET"),
|
||||
edit: fs => replaceText(fs, "core/index.ts", "HELLO WORLD", "WELCOME PLANET"),
|
||||
},
|
||||
{
|
||||
caption: "rebuilds when tsconfig changes",
|
||||
edit: fs => {
|
||||
replaceText(fs, "/src/tests/tsconfig.json", `"composite": true`, `"composite": true, "target": "es2020"`);
|
||||
fs.writeFileSync("/lib/lib.es2020.full.d.ts", libContent);
|
||||
replaceText(fs, "tests/tsconfig.json", `"composite": true`, `"composite": true, "target": "es2020"`);
|
||||
fs.writeFileSync(libPath("es2020.full"), libContent);
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -187,13 +184,13 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "when input file text does not change but its modified time changes",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests", "--verbose"],
|
||||
commandLineArgs: ["--b", "tests", "--verbose"],
|
||||
edits: [
|
||||
{
|
||||
caption: "upstream project changes without changing file text",
|
||||
edit: fs => {
|
||||
const time = new Date(fs.time());
|
||||
fs.utimesSync("/src/core/index.ts", time, time);
|
||||
fs.utimesSync("core/index.ts", time, time);
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -203,15 +200,15 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "when declarationMap changes",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests", "--verbose"],
|
||||
commandLineArgs: ["--b", "tests", "--verbose"],
|
||||
edits: [
|
||||
{
|
||||
caption: "Disable declarationMap",
|
||||
edit: fs => replaceText(fs, "/src/core/tsconfig.json", `"declarationMap": true,`, `"declarationMap": false,`),
|
||||
edit: fs => replaceText(fs, "core/tsconfig.json", `"declarationMap": true,`, `"declarationMap": false,`),
|
||||
},
|
||||
{
|
||||
caption: "Enable declarationMap",
|
||||
edit: fs => replaceText(fs, "/src/core/tsconfig.json", `"declarationMap": false,`, `"declarationMap": true,`),
|
||||
edit: fs => replaceText(fs, "core/tsconfig.json", `"declarationMap": false,`, `"declarationMap": true,`),
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -220,14 +217,14 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "indicates that it would skip builds during a dry build",
|
||||
fs: getSampleFsAfterBuild,
|
||||
commandLineArgs: ["--b", "/src/tests", "--dry"],
|
||||
commandLineArgs: ["--b", "tests", "--dry"],
|
||||
});
|
||||
|
||||
verifyTsc({
|
||||
scenario: "sample1",
|
||||
subScenario: "rebuilds from start if force option is set",
|
||||
fs: getSampleFsAfterBuild,
|
||||
commandLineArgs: ["--b", "/src/tests", "--verbose", "--force"],
|
||||
commandLineArgs: ["--b", "tests", "--verbose", "--force"],
|
||||
});
|
||||
|
||||
verifyTsc({
|
||||
@@ -250,11 +247,11 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "rebuilds completely when version in tsbuildinfo doesnt match ts version",
|
||||
fs: getSampleFsAfterBuild,
|
||||
commandLineArgs: ["--b", "/src/tests", "--verbose"],
|
||||
commandLineArgs: ["--b", "tests", "--verbose"],
|
||||
compile: sys => {
|
||||
// Buildinfo will have version which does not match with current ts version
|
||||
const buildHost = createSolutionBuilderHostForBaseline(sys, "FakeTSCurrentVersion");
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["/src/tests"], { verbose: true });
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["tests"], { verbose: true });
|
||||
sys.exit(builder.build());
|
||||
},
|
||||
});
|
||||
@@ -265,16 +262,16 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
fs: () => {
|
||||
const fs = projFs.shadow();
|
||||
const host = fakes.SolutionBuilderHost.create(fs, /*options*/ undefined, /*setParentNodes*/ undefined, ts.createAbstractBuilder);
|
||||
const builder = ts.createSolutionBuilder(host, ["/src/tests"], { verbose: true });
|
||||
const builder = ts.createSolutionBuilder(host, ["tests"], { verbose: true });
|
||||
builder.build();
|
||||
fs.makeReadonly();
|
||||
return fs;
|
||||
},
|
||||
commandLineArgs: ["--b", "/src/tests", "--verbose"],
|
||||
commandLineArgs: ["--b", "tests", "--verbose"],
|
||||
compile: sys => {
|
||||
// Buildinfo will have version which does not match with current ts version
|
||||
const buildHost = createSolutionBuilderHostForBaseline(sys, "FakeTSCurrentVersion");
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["/src/tests"], { verbose: true });
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["tests"], { verbose: true });
|
||||
sys.exit(builder.build());
|
||||
},
|
||||
});
|
||||
@@ -283,14 +280,14 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "rebuilds when extended config file changes",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests", "--verbose"],
|
||||
commandLineArgs: ["--b", "tests", "--verbose"],
|
||||
modifyFs: fs => {
|
||||
fs.writeFileSync("/src/tests/tsconfig.base.json", JSON.stringify({ compilerOptions: { target: "es3" } }));
|
||||
replaceText(fs, "/src/tests/tsconfig.json", `"references": [`, `"extends": "./tsconfig.base.json", "references": [`);
|
||||
fs.writeFileSync("tests/tsconfig.base.json", jsonToReadableText({ compilerOptions: { target: "es3" } }));
|
||||
replaceText(fs, "tests/tsconfig.json", `"references": [`, `"extends": "./tsconfig.base.json", "references": [`);
|
||||
},
|
||||
edits: [{
|
||||
caption: "incremental-declaration-changes",
|
||||
edit: fs => fs.writeFileSync("/src/tests/tsconfig.base.json", JSON.stringify({ compilerOptions: {} })),
|
||||
edit: fs => fs.writeFileSync("tests/tsconfig.base.json", jsonToReadableText({ compilerOptions: {} })),
|
||||
}],
|
||||
});
|
||||
|
||||
@@ -298,11 +295,11 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "builds till project specified",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--build", "/src/logic/tsconfig.json"],
|
||||
commandLineArgs: ["--build", "logic/tsconfig.json"],
|
||||
compile: sys => {
|
||||
const buildHost = createSolutionBuilderHostForBaseline(sys);
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["/src/tests"], {});
|
||||
sys.exit(builder.build("/src/logic/tsconfig.json"));
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["tests"], {});
|
||||
sys.exit(builder.build("logic/tsconfig.json"));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -310,43 +307,25 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "building project in not build order doesnt throw error",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--build", "/src/logic2/tsconfig.json"],
|
||||
commandLineArgs: ["--build", "logic2/tsconfig.json"],
|
||||
compile: sys => {
|
||||
const buildHost = createSolutionBuilderHostForBaseline(sys);
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["/src/tests"], {});
|
||||
sys.exit(builder.build("/src/logic2/tsconfig.json"));
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["tests"], {});
|
||||
sys.exit(builder.build("logic2/tsconfig.json"));
|
||||
},
|
||||
});
|
||||
|
||||
it("building using getNextInvalidatedProject", () => {
|
||||
const coreConfig = getTsBuildProjectFile("core", "tsconfig.json");
|
||||
const coreIndex = getTsBuildProjectFile("core", "index.ts");
|
||||
const coreDecl = getTsBuildProjectFile("core", "some_decl.d.ts");
|
||||
const coreAnotherModule = getTsBuildProjectFile("core", "anotherModule.ts");
|
||||
const logicConfig = getTsBuildProjectFile("logic", "tsconfig.json");
|
||||
const logicIndex = getTsBuildProjectFile("logic", "index.ts");
|
||||
const testsConfig = getTsBuildProjectFile("tests", "tsconfig.json");
|
||||
const testsIndex = getTsBuildProjectFile("tests", "index.ts");
|
||||
const baseline: string[] = [];
|
||||
let oldSnap: ReturnType<TestServerHost["snap"]> | undefined;
|
||||
const system = changeToHostTrackingWrittenFiles(
|
||||
fakes.patchHostForBuildInfoReadWrite(
|
||||
createWatchedSystem([
|
||||
coreConfig,
|
||||
coreIndex,
|
||||
coreDecl,
|
||||
coreAnotherModule,
|
||||
logicConfig,
|
||||
logicIndex,
|
||||
testsConfig,
|
||||
testsIndex,
|
||||
libFile,
|
||||
]),
|
||||
getSysForSampleProjectReferences(),
|
||||
),
|
||||
);
|
||||
|
||||
const host = createSolutionBuilderHostForBaseline(system);
|
||||
const builder = ts.createSolutionBuilder(host, [testsConfig.path], {});
|
||||
const builder = ts.createSolutionBuilder(host, ["tests"], {});
|
||||
baseline.push("Input::");
|
||||
baselineState();
|
||||
verifyBuildNextResult(); // core
|
||||
@@ -358,7 +337,7 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
function verifyBuildNextResult() {
|
||||
const project = builder.getNextInvalidatedProject();
|
||||
const result = project && project.done();
|
||||
baseline.push(`Project Result:: ${JSON.stringify({ project: project?.project, result })}`);
|
||||
baseline.push(`Project Result:: ${jsonToReadableText({ project: project?.project, result })}`);
|
||||
baselineState();
|
||||
}
|
||||
|
||||
@@ -374,11 +353,11 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "building using buildReferencedProject",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--build", "/src/logic2/tsconfig.json"],
|
||||
commandLineArgs: ["--build", "logic2/tsconfig.json"],
|
||||
compile: sys => {
|
||||
const buildHost = createSolutionBuilderHostForBaseline(sys);
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["/src/tests"], { verbose: true });
|
||||
sys.exit(builder.buildReferences("/src/tests"));
|
||||
const builder = ts.createSolutionBuilder(buildHost, ["tests"], { verbose: true });
|
||||
sys.exit(builder.buildReferences("tests"));
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -388,61 +367,43 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
scenario: "sample1",
|
||||
subScenario: "does not build downstream projects if upstream projects have errors",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests", "--verbose"],
|
||||
modifyFs: fs => replaceText(fs, "/src/logic/index.ts", "c.multiply(10, 15)", `c.muitply()`),
|
||||
commandLineArgs: ["--b", "tests", "--verbose"],
|
||||
modifyFs: fs => replaceText(fs, "logic/index.ts", "c.multiply(10, 15)", `c.muitply()`),
|
||||
edits: noChangeOnlyRuns,
|
||||
});
|
||||
});
|
||||
|
||||
describe("project invalidation", () => {
|
||||
it("invalidates projects correctly", () => {
|
||||
const coreConfig = getTsBuildProjectFile("core", "tsconfig.json");
|
||||
const coreIndex = getTsBuildProjectFile("core", "index.ts");
|
||||
const coreDecl = getTsBuildProjectFile("core", "some_decl.d.ts");
|
||||
const coreAnotherModule = getTsBuildProjectFile("core", "anotherModule.ts");
|
||||
const logicConfig = getTsBuildProjectFile("logic", "tsconfig.json");
|
||||
const logicIndex = getTsBuildProjectFile("logic", "index.ts");
|
||||
const testsConfig = getTsBuildProjectFile("tests", "tsconfig.json");
|
||||
const testsIndex = getTsBuildProjectFile("tests", "index.ts");
|
||||
const baseline: string[] = [];
|
||||
let oldSnap: ReturnType<TestServerHost["snap"]> | undefined;
|
||||
const system = changeToHostTrackingWrittenFiles(
|
||||
fakes.patchHostForBuildInfoReadWrite(
|
||||
createWatchedSystem([
|
||||
coreConfig,
|
||||
coreIndex,
|
||||
coreDecl,
|
||||
coreAnotherModule,
|
||||
logicConfig,
|
||||
logicIndex,
|
||||
testsConfig,
|
||||
testsIndex,
|
||||
libFile,
|
||||
]),
|
||||
getSysForSampleProjectReferences(),
|
||||
),
|
||||
);
|
||||
|
||||
const host = createSolutionBuilderHostForBaseline(system);
|
||||
const builder = ts.createSolutionBuilder(host, [testsConfig.path], { dry: false, force: false, verbose: false });
|
||||
const builder = ts.createSolutionBuilder(host, ["tests"], { dry: false, force: false, verbose: false });
|
||||
builder.build();
|
||||
baselineState("Build of project");
|
||||
|
||||
// Update a timestamp in the middle project
|
||||
system.appendFile(logicIndex.path, "function foo() {}");
|
||||
system.appendFile("logic/index.ts", "function foo() {}");
|
||||
|
||||
// Because we haven't reset the build context, the builder should assume there's nothing to do right now
|
||||
const status = builder.getUpToDateStatusOfProject(logicConfig.path);
|
||||
const status = builder.getUpToDateStatusOfProject("logic/tsconfig.json");
|
||||
baseline.push(`Project should still be upto date: ${ts.UpToDateStatusType[status.type]}`);
|
||||
verifyInvalidation("non Dts change to logic");
|
||||
|
||||
// Rebuild this project
|
||||
system.appendFile(logicIndex.path, `export class cNew {}`);
|
||||
system.appendFile("logic/index.ts", `export class cNew {}`);
|
||||
verifyInvalidation("Dts change to Logic");
|
||||
Harness.Baseline.runBaseline(`tsbuild/sample1/invalidates-projects-correctly.js`, baseline.join("\r\n"));
|
||||
|
||||
function verifyInvalidation(heading: string) {
|
||||
// Rebuild this project
|
||||
builder.invalidateProject(logicConfig.path as ts.ResolvedConfigFilePath);
|
||||
builder.invalidateProject("/user/username/projects/sample1/logic/tsconfig.json" as ts.ResolvedConfigFilePath);
|
||||
builder.getNextInvalidatedProject()?.done();
|
||||
baselineState(`${heading}:: After rebuilding logicConfig`);
|
||||
|
||||
@@ -467,7 +428,7 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
|
||||
edit: fs =>
|
||||
appendText(
|
||||
fs,
|
||||
"/src/core/index.ts",
|
||||
"core/index.ts",
|
||||
`
|
||||
export class someClass { }`,
|
||||
),
|
||||
@@ -477,7 +438,7 @@ export class someClass { }`,
|
||||
edit: fs =>
|
||||
appendText(
|
||||
fs,
|
||||
"/src/core/index.ts",
|
||||
"core/index.ts",
|
||||
`
|
||||
class someClass2 { }`,
|
||||
),
|
||||
@@ -490,21 +451,21 @@ class someClass2 { }`,
|
||||
scenario: "sample1",
|
||||
subScenario: "listFiles",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests", "--listFiles"],
|
||||
commandLineArgs: ["--b", "tests", "--listFiles"],
|
||||
edits: coreChanges,
|
||||
});
|
||||
verifyTsc({
|
||||
scenario: "sample1",
|
||||
subScenario: "listEmittedFiles",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests", "--listEmittedFiles"],
|
||||
commandLineArgs: ["--b", "tests", "--listEmittedFiles"],
|
||||
edits: coreChanges,
|
||||
});
|
||||
verifyTsc({
|
||||
scenario: "sample1",
|
||||
subScenario: "explainFiles",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests", "--explainFiles", "--v"],
|
||||
commandLineArgs: ["--b", "tests", "--explainFiles", "--v"],
|
||||
edits: coreChanges,
|
||||
});
|
||||
});
|
||||
@@ -514,7 +475,7 @@ class someClass2 { }`,
|
||||
subScenario: "sample",
|
||||
fs: () => projFs,
|
||||
scenario: "sample1",
|
||||
commandLineArgs: ["--b", "/src/tests", "--verbose"],
|
||||
commandLineArgs: ["--b", "tests", "--verbose"],
|
||||
baselineSourceMap: true,
|
||||
baselineReadFileCalls: true,
|
||||
edits: [
|
||||
@@ -524,7 +485,7 @@ class someClass2 { }`,
|
||||
edit: fs =>
|
||||
replaceText(
|
||||
fs,
|
||||
"/src/logic/tsconfig.json",
|
||||
"logic/tsconfig.json",
|
||||
`"declaration": true,`,
|
||||
`"declaration": true,
|
||||
"declarationDir": "decls",`,
|
||||
@@ -541,12 +502,12 @@ class someClass2 { }`,
|
||||
modifyFs: fs =>
|
||||
replaceText(
|
||||
fs,
|
||||
"/src/logic/tsconfig.json",
|
||||
"logic/tsconfig.json",
|
||||
`"composite": true,`,
|
||||
`"composite": true,
|
||||
"tsBuildInfoFile": "ownFile.tsbuildinfo",`,
|
||||
"tsBuildInfoFile": "ownFile.tsbuildinfo",`,
|
||||
),
|
||||
commandLineArgs: ["--b", "/src/tests", "--verbose"],
|
||||
commandLineArgs: ["--b", "tests", "--verbose"],
|
||||
baselineSourceMap: true,
|
||||
baselineReadFileCalls: true,
|
||||
});
|
||||
@@ -555,20 +516,20 @@ class someClass2 { }`,
|
||||
subScenario: "when declaration option changes",
|
||||
fs: () => projFs,
|
||||
scenario: "sample1",
|
||||
commandLineArgs: ["--b", "/src/core", "--verbose"],
|
||||
commandLineArgs: ["--b", "core", "--verbose"],
|
||||
modifyFs: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/core/tsconfig.json",
|
||||
`{
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"skipDefaultLibCheck": true
|
||||
}
|
||||
}`,
|
||||
"core/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
incremental: true,
|
||||
skipDefaultLibCheck: true,
|
||||
},
|
||||
}),
|
||||
),
|
||||
edits: [{
|
||||
caption: "incremental-declaration-changes",
|
||||
edit: fs => replaceText(fs, "/src/core/tsconfig.json", `"incremental": true,`, `"incremental": true, "declaration": true,`),
|
||||
edit: fs => replaceText(fs, "core/tsconfig.json", `"incremental": true,`, `"incremental": true, "declaration": true,`),
|
||||
}],
|
||||
});
|
||||
|
||||
@@ -576,34 +537,34 @@ class someClass2 { }`,
|
||||
subScenario: "when target option changes",
|
||||
fs: () => projFs,
|
||||
scenario: "sample1",
|
||||
commandLineArgs: ["--b", "/src/core", "--verbose"],
|
||||
commandLineArgs: ["--b", "core", "--verbose"],
|
||||
modifyFs: fs => {
|
||||
fs.writeFileSync(
|
||||
"/lib/lib.esnext.full.d.ts",
|
||||
libPath("esnext.full"),
|
||||
`/// <reference no-default-lib="true"/>
|
||||
/// <reference lib="esnext" />`,
|
||||
);
|
||||
fs.writeFileSync("/lib/lib.esnext.d.ts", libContent);
|
||||
fs.writeFileSync(libPath("esnext"), libContent);
|
||||
fs.writeFileSync(
|
||||
"/lib/lib.d.ts",
|
||||
libFile.path,
|
||||
`/// <reference no-default-lib="true"/>
|
||||
/// <reference lib="esnext" />`,
|
||||
);
|
||||
fs.writeFileSync(
|
||||
"/src/core/tsconfig.json",
|
||||
`{
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"listFiles": true,
|
||||
"listEmittedFiles": true,
|
||||
"target": "esnext",
|
||||
}
|
||||
}`,
|
||||
"core/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
incremental: true,
|
||||
listFiles: true,
|
||||
listEmittedFiles: true,
|
||||
target: "esnext",
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
edits: [{
|
||||
caption: "incremental-declaration-changes",
|
||||
edit: fs => replaceText(fs, "/src/core/tsconfig.json", "esnext", "es5"),
|
||||
edit: fs => replaceText(fs, "core/tsconfig.json", "esnext", "es5"),
|
||||
}],
|
||||
});
|
||||
|
||||
@@ -611,20 +572,20 @@ class someClass2 { }`,
|
||||
subScenario: "when module option changes",
|
||||
fs: () => projFs,
|
||||
scenario: "sample1",
|
||||
commandLineArgs: ["--b", "/src/core", "--verbose"],
|
||||
commandLineArgs: ["--b", "core", "--verbose"],
|
||||
modifyFs: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/core/tsconfig.json",
|
||||
`{
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"module": "commonjs"
|
||||
}
|
||||
}`,
|
||||
"core/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
incremental: true,
|
||||
module: "commonjs",
|
||||
},
|
||||
}),
|
||||
),
|
||||
edits: [{
|
||||
caption: "incremental-declaration-changes",
|
||||
edit: fs => replaceText(fs, "/src/core/tsconfig.json", `"module": "commonjs"`, `"module": "amd"`),
|
||||
edit: fs => replaceText(fs, "core/tsconfig.json", `"module": "commonjs"`, `"module": "amd"`),
|
||||
}],
|
||||
});
|
||||
|
||||
@@ -632,28 +593,28 @@ class someClass2 { }`,
|
||||
subScenario: "when esModuleInterop option changes",
|
||||
fs: () => projFs,
|
||||
scenario: "sample1",
|
||||
commandLineArgs: ["--b", "/src/tests", "--verbose"],
|
||||
commandLineArgs: ["--b", "tests", "--verbose"],
|
||||
modifyFs: fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/tests/tsconfig.json",
|
||||
`{
|
||||
"references": [
|
||||
{ "path": "../core" },
|
||||
{ "path": "../logic" }
|
||||
],
|
||||
"files": ["index.ts"],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"declaration": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"skipDefaultLibCheck": true,
|
||||
"esModuleInterop": false
|
||||
}
|
||||
}`,
|
||||
"tests/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
references: [
|
||||
{ path: "../core" },
|
||||
{ path: "../logic" },
|
||||
],
|
||||
files: ["index.ts"],
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
declaration: true,
|
||||
forceConsistentCasingInFileNames: true,
|
||||
skipDefaultLibCheck: true,
|
||||
esModuleInterop: false,
|
||||
},
|
||||
}),
|
||||
),
|
||||
edits: [{
|
||||
caption: "incremental-declaration-changes",
|
||||
edit: fs => replaceText(fs, "/src/tests/tsconfig.json", `"esModuleInterop": false`, `"esModuleInterop": true`),
|
||||
edit: fs => replaceText(fs, "tests/tsconfig.json", `"esModuleInterop": false`, `"esModuleInterop": true`),
|
||||
}],
|
||||
});
|
||||
|
||||
@@ -661,16 +622,16 @@ class someClass2 { }`,
|
||||
scenario: "sample1",
|
||||
subScenario: "reports error if input file is missing",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests", "--v"],
|
||||
commandLineArgs: ["--b", "tests", "--v"],
|
||||
modifyFs: fs => {
|
||||
fs.writeFileSync(
|
||||
"/src/core/tsconfig.json",
|
||||
JSON.stringify({
|
||||
"core/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
files: ["anotherModule.ts", "index.ts", "some_decl.d.ts"],
|
||||
}),
|
||||
);
|
||||
fs.unlinkSync("/src/core/anotherModule.ts");
|
||||
fs.unlinkSync("core/anotherModule.ts");
|
||||
},
|
||||
});
|
||||
|
||||
@@ -678,16 +639,16 @@ class someClass2 { }`,
|
||||
scenario: "sample1",
|
||||
subScenario: "reports error if input file is missing with force",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tests", "--v", "--f"],
|
||||
commandLineArgs: ["--b", "tests", "--v", "--f"],
|
||||
modifyFs: fs => {
|
||||
fs.writeFileSync(
|
||||
"/src/core/tsconfig.json",
|
||||
JSON.stringify({
|
||||
"core/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
files: ["anotherModule.ts", "index.ts", "some_decl.d.ts"],
|
||||
}),
|
||||
);
|
||||
fs.unlinkSync("/src/core/anotherModule.ts");
|
||||
fs.unlinkSync("core/anotherModule.ts");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,15 +1,30 @@
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
getFsContentsForTransitiveReferences,
|
||||
} from "../helpers/transitiveReferences";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
} from "../helpers/vfs";
|
||||
import {
|
||||
libFile,
|
||||
} from "../helpers/virtualFileSystemWithWatch";
|
||||
|
||||
describe("unittests:: tsbuild:: when project reference is referenced transitively", () => {
|
||||
let projFs: vfs.FileSystem;
|
||||
before(() => {
|
||||
projFs = loadProjectFromDisk("tests/projects/transitiveReferences");
|
||||
projFs = loadProjectFromFiles(
|
||||
getFsContentsForTransitiveReferences(),
|
||||
{
|
||||
cwd: "/user/username/projects/transitiveReferences",
|
||||
executingFilePath: libFile.path,
|
||||
},
|
||||
);
|
||||
});
|
||||
after(() => {
|
||||
projFs = undefined!; // Release the contents
|
||||
@@ -17,13 +32,13 @@ describe("unittests:: tsbuild:: when project reference is referenced transitivel
|
||||
|
||||
function modifyFsBTsToNonRelativeImport(fs: vfs.FileSystem, moduleResolution: "node" | "classic") {
|
||||
fs.writeFileSync(
|
||||
"/src/b.ts",
|
||||
"b.ts",
|
||||
`import {A} from 'a';
|
||||
export const b = new A();`,
|
||||
);
|
||||
fs.writeFileSync(
|
||||
"/src/tsconfig.b.json",
|
||||
JSON.stringify({
|
||||
"tsconfig.b.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
moduleResolution,
|
||||
@@ -38,14 +53,14 @@ export const b = new A();`,
|
||||
scenario: "transitiveReferences",
|
||||
subScenario: "builds correctly",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig.c.json", "--listFiles"],
|
||||
commandLineArgs: ["--b", "tsconfig.c.json", "--listFiles"],
|
||||
});
|
||||
|
||||
verifyTsc({
|
||||
scenario: "transitiveReferences",
|
||||
subScenario: "builds correctly when the referenced project uses different module resolution",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig.c.json", "--listFiles"],
|
||||
commandLineArgs: ["--b", "tsconfig.c.json", "--listFiles"],
|
||||
modifyFs: fs => modifyFsBTsToNonRelativeImport(fs, "classic"),
|
||||
});
|
||||
|
||||
@@ -53,7 +68,7 @@ export const b = new A();`,
|
||||
scenario: "transitiveReferences",
|
||||
subScenario: "reports error about module not found with node resolution with external module name",
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--b", "/src/tsconfig.c.json", "--listFiles"],
|
||||
commandLineArgs: ["--b", "tsconfig.c.json", "--listFiles"],
|
||||
modifyFs: fs => modifyFsBTsToNonRelativeImport(fs, "node"),
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,9 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTscWatch,
|
||||
} from "../helpers/tscWatch";
|
||||
@@ -63,7 +66,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: configFileErrors:: reports synt
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
`/user/username/projects/myproject/tsconfig.json`,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true, declaration: true },
|
||||
files: ["a.ts", "b.ts"],
|
||||
}),
|
||||
|
||||
@@ -1,66 +1,35 @@
|
||||
import {
|
||||
libContent,
|
||||
} from "../helpers/contents";
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
getFsContentsForDemoProjectReferencesCoreConfig,
|
||||
getSysForDemoProjectReferences,
|
||||
} from "../helpers/demoProjectReferences";
|
||||
import {
|
||||
verifyTscWatch,
|
||||
} from "../helpers/tscWatch";
|
||||
import {
|
||||
createWatchedSystem,
|
||||
File,
|
||||
getTsBuildProjectFile,
|
||||
libFile,
|
||||
} from "../helpers/virtualFileSystemWithWatch";
|
||||
|
||||
describe("unittests:: tsbuildWatch:: watchMode:: with demo project", () => {
|
||||
const projectLocation = `/user/username/projects/demo`;
|
||||
let coreFiles: File[];
|
||||
let animalFiles: File[];
|
||||
let zooFiles: File[];
|
||||
let solutionFile: File;
|
||||
let baseConfig: File;
|
||||
let allFiles: File[];
|
||||
before(() => {
|
||||
coreFiles = subProjectFiles("core", ["tsconfig.json", "utilities.ts"]);
|
||||
animalFiles = subProjectFiles("animals", ["tsconfig.json", "animal.ts", "dog.ts", "index.ts"]);
|
||||
zooFiles = subProjectFiles("zoo", ["tsconfig.json", "zoo.ts"]);
|
||||
solutionFile = projectFile("tsconfig.json");
|
||||
baseConfig = projectFile("tsconfig-base.json");
|
||||
allFiles = [...coreFiles, ...animalFiles, ...zooFiles, solutionFile, baseConfig, { path: libFile.path, content: libContent }];
|
||||
});
|
||||
|
||||
after(() => {
|
||||
coreFiles = undefined!;
|
||||
animalFiles = undefined!;
|
||||
zooFiles = undefined!;
|
||||
solutionFile = undefined!;
|
||||
baseConfig = undefined!;
|
||||
allFiles = undefined!;
|
||||
});
|
||||
|
||||
verifyTscWatch({
|
||||
scenario: "demo",
|
||||
subScenario: "updates with circular reference",
|
||||
commandLineArgs: ["-b", "-w", "-verbose"],
|
||||
sys: () => {
|
||||
const sys = createWatchedSystem(allFiles, { currentDirectory: projectLocation });
|
||||
const sys = getSysForDemoProjectReferences();
|
||||
sys.writeFile(
|
||||
coreFiles[0].path,
|
||||
coreFiles[0].content.replace(
|
||||
"}",
|
||||
`},
|
||||
"references": [
|
||||
{
|
||||
"path": "../zoo"
|
||||
}
|
||||
]`,
|
||||
),
|
||||
"core/tsconfig.json",
|
||||
getFsContentsForDemoProjectReferencesCoreConfig({
|
||||
references: [{
|
||||
path: "../zoo",
|
||||
}],
|
||||
}),
|
||||
);
|
||||
return sys;
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
caption: "Fix error",
|
||||
edit: sys => sys.writeFile(coreFiles[0].path, coreFiles[0].content),
|
||||
edit: sys => sys.writeFile("core/tsconfig.json", getFsContentsForDemoProjectReferencesCoreConfig()),
|
||||
timeouts: sys => {
|
||||
sys.runQueuedTimeoutCallbacks(); // build core
|
||||
sys.runQueuedTimeoutCallbacks(); // build animals, zoo and solution
|
||||
@@ -74,35 +43,22 @@ describe("unittests:: tsbuildWatch:: watchMode:: with demo project", () => {
|
||||
subScenario: "updates with bad reference",
|
||||
commandLineArgs: ["-b", "-w", "-verbose"],
|
||||
sys: () => {
|
||||
const sys = createWatchedSystem(allFiles, { currentDirectory: projectLocation });
|
||||
sys.writeFile(
|
||||
coreFiles[1].path,
|
||||
`import * as A from '../animals';
|
||||
${coreFiles[1].content}`,
|
||||
const sys = getSysForDemoProjectReferences();
|
||||
sys.prependFile(
|
||||
"core/utilities.ts",
|
||||
dedent`
|
||||
import * as A from '../animals';
|
||||
`,
|
||||
);
|
||||
return sys;
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
caption: "Prepend a line",
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
coreFiles[1].path,
|
||||
`
|
||||
import * as A from '../animals';
|
||||
${coreFiles[1].content}`,
|
||||
),
|
||||
edit: sys => sys.prependFile("core/utilities.ts", "\n"),
|
||||
// build core
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
function subProjectFiles(subProject: string, fileNames: readonly string[]): File[] {
|
||||
return fileNames.map(file => projectFile(`${subProject}/${file}`));
|
||||
}
|
||||
|
||||
function projectFile(fileName: string): File {
|
||||
return getTsBuildProjectFile("demo", fileName);
|
||||
}
|
||||
});
|
||||
@@ -1,6 +1,9 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTscWatch,
|
||||
} from "../helpers/tscWatch";
|
||||
@@ -20,7 +23,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
|
||||
{ path: `/user/username/projects/myproject/project1/node_modules/file/index.d.ts`, content: "export const foo = 10;" },
|
||||
{
|
||||
path: `/user/username/projects/myproject/project1/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { composite: true, types: ["foo", "bar"] },
|
||||
files: ["index.ts"],
|
||||
}),
|
||||
@@ -29,7 +32,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
|
||||
{ path: `/user/username/projects/myproject/project2/file.d.ts`, content: "export const foo = 10;" },
|
||||
{
|
||||
path: `/user/username/projects/myproject/project2/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { composite: true, types: ["foo"], moduleResolution: "classic" },
|
||||
files: ["index.ts"],
|
||||
}),
|
||||
@@ -38,7 +41,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
|
||||
{ path: `/user/username/projects/myproject/node_modules/@types/bar/index.d.ts`, content: "export const bar = 10;" },
|
||||
{
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
files: [],
|
||||
references: [
|
||||
{ path: "./project1" },
|
||||
@@ -67,7 +70,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
|
||||
createWatchedSystem([
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg1/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg1",
|
||||
version: "1.0.0",
|
||||
main: "build/index.js",
|
||||
@@ -82,7 +85,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg1/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "build",
|
||||
module: "node16",
|
||||
@@ -100,7 +103,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg2/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
outDir: "build",
|
||||
@@ -110,7 +113,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg2/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg2",
|
||||
version: "1.0.0",
|
||||
main: "build/index.js",
|
||||
@@ -161,7 +164,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
|
||||
createWatchedSystem([
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg1/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg1",
|
||||
version: "1.0.0",
|
||||
main: "build/index.js",
|
||||
@@ -175,7 +178,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg1/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "build",
|
||||
},
|
||||
@@ -184,7 +187,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg2/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
outDir: "build",
|
||||
@@ -206,7 +209,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg2/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg2",
|
||||
version: "1.0.0",
|
||||
main: "build/index.js",
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
libContent,
|
||||
} from "../helpers/contents";
|
||||
@@ -15,15 +18,12 @@ describe("unittests:: tsbuildWatch:: watchMode:: with noEmit", () => {
|
||||
subScenario: "does not go in loop when watching when no files are emitted",
|
||||
commandLineArgs: ["-b", "-w", "-verbose"],
|
||||
sys: () =>
|
||||
createWatchedSystem(
|
||||
[
|
||||
{ path: libFile.path, content: libContent },
|
||||
{ path: `/user/username/projects/myproject/a.js`, content: "" },
|
||||
{ path: `/user/username/projects/myproject/b.ts`, content: "" },
|
||||
{ path: `/user/username/projects/myproject/tsconfig.json`, content: JSON.stringify({ compilerOptions: { allowJs: true, noEmit: true } }) },
|
||||
],
|
||||
{ currentDirectory: "/user/username/projects/myproject" },
|
||||
),
|
||||
createWatchedSystem({
|
||||
[libFile.path]: libContent,
|
||||
"/user/username/projects/myproject/a.js": "",
|
||||
"/user/username/projects/myproject/b.ts": "",
|
||||
"/user/username/projects/myproject/tsconfig.json": jsonToReadableText({ compilerOptions: { allowJs: true, noEmit: true } }),
|
||||
}, { currentDirectory: "/user/username/projects/myproject" }),
|
||||
edits: [
|
||||
{
|
||||
caption: "No change",
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
import {
|
||||
libContent,
|
||||
} from "../helpers/contents";
|
||||
getSysForNoEmitOnError,
|
||||
} from "../helpers/noEmitOnError";
|
||||
import {
|
||||
TscWatchCompileChange,
|
||||
verifyTscWatch,
|
||||
} from "../helpers/tscWatch";
|
||||
import {
|
||||
createWatchedSystem,
|
||||
getTsBuildProjectFile,
|
||||
libFile,
|
||||
} from "../helpers/virtualFileSystemWithWatch";
|
||||
|
||||
describe("unittests:: tsbuildWatch:: watchMode:: with noEmitOnError", () => {
|
||||
function change(caption: string, content: string): TscWatchCompileChange {
|
||||
@@ -31,15 +26,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: with noEmitOnError", () => {
|
||||
scenario: "noEmitOnError",
|
||||
subScenario: "does not emit any files on error",
|
||||
commandLineArgs: ["-b", "-w", "-verbose"],
|
||||
sys: () =>
|
||||
createWatchedSystem(
|
||||
[
|
||||
...["tsconfig.json", "shared/types/db.ts", "src/main.ts", "src/other.ts"]
|
||||
.map(f => getTsBuildProjectFile("noEmitOnError", f)),
|
||||
{ path: libFile.path, content: libContent },
|
||||
],
|
||||
{ currentDirectory: `/user/username/projects/noEmitOnError` },
|
||||
),
|
||||
sys: getSysForNoEmitOnError,
|
||||
edits: [
|
||||
noChange,
|
||||
change(
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
FsContents,
|
||||
} from "../helpers/contents";
|
||||
import {
|
||||
getFsContentsForSampleProjectReferences,
|
||||
getFsContentsForSampleProjectReferencesLogicConfig,
|
||||
getSysForSampleProjectReferences,
|
||||
} from "../helpers/sampleProjectReferences";
|
||||
import {
|
||||
commonFile1,
|
||||
commonFile2,
|
||||
@@ -12,86 +23,22 @@ import {
|
||||
import {
|
||||
createWatchedSystem,
|
||||
File,
|
||||
getTsBuildProjectFile,
|
||||
getTsBuildProjectFilePath,
|
||||
libFile,
|
||||
} from "../helpers/virtualFileSystemWithWatch";
|
||||
|
||||
describe("unittests:: tsbuildWatch:: watchMode:: program updates", () => {
|
||||
const enum SubProject {
|
||||
core = "core",
|
||||
logic = "logic",
|
||||
tests = "tests",
|
||||
ui = "ui",
|
||||
}
|
||||
type ReadonlyFile = Readonly<File>;
|
||||
/** [tsconfig, index] | [tsconfig, index, anotherModule, someDecl] */
|
||||
type SubProjectFiles = [tsconfig: ReadonlyFile, index: ReadonlyFile] | [tsconfig: ReadonlyFile, index: ReadonlyFile, anotherModule: ReadonlyFile, someDecl: ReadonlyFile];
|
||||
function projectFilePath(subProject: SubProject, baseFileName: string) {
|
||||
return `${getTsBuildProjectFilePath("sample1", subProject)}/${baseFileName.toLowerCase()}`;
|
||||
}
|
||||
|
||||
function projectFile(subProject: SubProject, baseFileName: string): File {
|
||||
return getTsBuildProjectFile("sample1", `${subProject}/${baseFileName}`);
|
||||
}
|
||||
|
||||
function subProjectFiles(subProject: SubProject, anotherModuleAndSomeDecl?: true): SubProjectFiles {
|
||||
const tsconfig = projectFile(subProject, "tsconfig.json");
|
||||
const index = projectFile(subProject, "index.ts");
|
||||
if (!anotherModuleAndSomeDecl) {
|
||||
return [tsconfig, index];
|
||||
}
|
||||
const anotherModule = projectFile(SubProject.core, "anotherModule.ts");
|
||||
const someDecl = projectFile(SubProject.core, "some_decl.ts");
|
||||
return [tsconfig, index, anotherModule, someDecl];
|
||||
}
|
||||
|
||||
function changeFile(fileName: string | (() => string), content: string | (() => string), caption: string): TscWatchCompileChange {
|
||||
return {
|
||||
caption,
|
||||
edit: sys => sys.writeFile(ts.isString(fileName) ? fileName : fileName(), ts.isString(content) ? content : content()),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // Builds core
|
||||
};
|
||||
}
|
||||
|
||||
function changeCore(content: () => string, caption: string) {
|
||||
return changeFile(() => core[1].path, content, caption);
|
||||
}
|
||||
|
||||
let core: SubProjectFiles;
|
||||
let logic: SubProjectFiles;
|
||||
let tests: SubProjectFiles;
|
||||
let ui: SubProjectFiles;
|
||||
let allFiles: readonly File[];
|
||||
|
||||
before(() => {
|
||||
core = subProjectFiles(SubProject.core, /*anotherModuleAndSomeDecl*/ true);
|
||||
logic = subProjectFiles(SubProject.logic);
|
||||
tests = subProjectFiles(SubProject.tests);
|
||||
ui = subProjectFiles(SubProject.ui);
|
||||
allFiles = [libFile, ...core, ...logic, ...tests, ...ui];
|
||||
});
|
||||
|
||||
after(() => {
|
||||
core = undefined!;
|
||||
logic = undefined!;
|
||||
tests = undefined!;
|
||||
ui = undefined!;
|
||||
allFiles = undefined!;
|
||||
});
|
||||
|
||||
verifyTscWatch({
|
||||
scenario: "programUpdates",
|
||||
subScenario: "creates solution in watch mode",
|
||||
commandLineArgs: ["-b", "-w", `sample1/${SubProject.tests}`],
|
||||
sys: () => createWatchedSystem(allFiles, { currentDirectory: "/user/username/projects" }),
|
||||
commandLineArgs: ["-b", "-w", "tests"],
|
||||
sys: getSysForSampleProjectReferences,
|
||||
});
|
||||
|
||||
it("verify building references watches only those projects", () => {
|
||||
const { sys, baseline, oldSnap, cb, getPrograms } = createBaseline(createWatchedSystem(allFiles, { currentDirectory: "/user/username/projects" }));
|
||||
const { sys, baseline, oldSnap, cb, getPrograms } = createBaseline(getSysForSampleProjectReferences());
|
||||
const host = createSolutionBuilderWithWatchHostForBaseline(sys, cb);
|
||||
const solutionBuilder = ts.createSolutionBuilderWithWatch(host, [`sample1/${SubProject.tests}`], { watch: true });
|
||||
solutionBuilder.buildReferences(`sample1/${SubProject.tests}`);
|
||||
const solutionBuilder = ts.createSolutionBuilderWithWatch(host, ["tests"], { watch: true });
|
||||
solutionBuilder.buildReferences("tests");
|
||||
runWatchBaseline({
|
||||
scenario: "programUpdates",
|
||||
subScenario: "verify building references watches only those projects",
|
||||
@@ -105,13 +52,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: program updates", () => {
|
||||
});
|
||||
|
||||
describe("validates the changes and watched files", () => {
|
||||
const newFileWithoutExtension = "newFile";
|
||||
const newFile: File = {
|
||||
path: projectFilePath(SubProject.core, `${newFileWithoutExtension}.ts`),
|
||||
content: `export const newFileConst = 30;`,
|
||||
};
|
||||
|
||||
function verifyProjectChanges(subScenario: string, allFilesGetter: () => readonly File[]) {
|
||||
function verifyProjectChanges(subScenario: string, allFilesGetter: () => FsContents) {
|
||||
const buildLogicAndTests: TscWatchCompileChange = {
|
||||
caption: "Build logic and tests",
|
||||
edit: ts.noop,
|
||||
@@ -121,33 +62,31 @@ describe("unittests:: tsbuildWatch:: watchMode:: program updates", () => {
|
||||
verifyTscWatch({
|
||||
scenario: "programUpdates",
|
||||
subScenario: `${subScenario}/change builds changes and reports found errors message`,
|
||||
commandLineArgs: ["-b", "-w", `sample1/${SubProject.tests}`],
|
||||
commandLineArgs: ["-b", "-w", "sample1/tests"],
|
||||
sys: () =>
|
||||
createWatchedSystem(
|
||||
allFilesGetter(),
|
||||
{ currentDirectory: "/user/username/projects" },
|
||||
),
|
||||
edits: [
|
||||
changeCore(() =>
|
||||
`${core[1].content}
|
||||
export class someClass { }`, "Make change to core"),
|
||||
{
|
||||
caption: "Make change to core",
|
||||
edit: sys => sys.appendFile("sample1/core/index.ts", `\nexport class someClass { }`),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // Builds core
|
||||
},
|
||||
buildLogicAndTests,
|
||||
// Another change requeues and builds it
|
||||
changeCore(() => core[1].content, "Revert core file"),
|
||||
{
|
||||
caption: "Revert core file",
|
||||
edit: sys => sys.replaceFileText("sample1/core/index.ts", `\nexport class someClass { }`, ""),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // Builds core
|
||||
},
|
||||
buildLogicAndTests,
|
||||
{
|
||||
caption: "Make two changes",
|
||||
edit: sys => {
|
||||
const change1 = `${core[1].content}
|
||||
export class someClass { }`;
|
||||
sys.writeFile(core[1].path, change1);
|
||||
assert.equal(sys.writtenFiles.size, 1);
|
||||
sys.writtenFiles.clear();
|
||||
sys.writeFile(
|
||||
core[1].path,
|
||||
`${change1}
|
||||
export class someClass2 { }`,
|
||||
);
|
||||
sys.appendFile("sample1/core/index.ts", `\nexport class someClass { }`);
|
||||
sys.appendFile("sample1/core/index.ts", `\nexport class someClass2 { }`);
|
||||
},
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // Builds core
|
||||
},
|
||||
@@ -158,36 +97,40 @@ export class someClass2 { }`,
|
||||
verifyTscWatch({
|
||||
scenario: "programUpdates",
|
||||
subScenario: `${subScenario}/non local change does not start build of referencing projects`,
|
||||
commandLineArgs: ["-b", "-w", `sample1/${SubProject.tests}`],
|
||||
commandLineArgs: ["-b", "-w", "sample1/tests"],
|
||||
sys: () =>
|
||||
createWatchedSystem(
|
||||
allFilesGetter(),
|
||||
{ currentDirectory: "/user/username/projects" },
|
||||
),
|
||||
edits: [
|
||||
changeCore(() =>
|
||||
`${core[1].content}
|
||||
function foo() { }`, "Make local change to core"),
|
||||
],
|
||||
edits: [{
|
||||
caption: "Make local change to core",
|
||||
edit: sys => sys.appendFile("sample1/core/index.ts", `\nfunction foo() { }`),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // Builds core
|
||||
}],
|
||||
});
|
||||
|
||||
function changeNewFile(newFileContent: string) {
|
||||
return changeFile(newFile.path, newFileContent, "Change to new File and build core");
|
||||
}
|
||||
verifyTscWatch({
|
||||
scenario: "programUpdates",
|
||||
subScenario: `${subScenario}/builds when new file is added, and its subsequent updates`,
|
||||
commandLineArgs: ["-b", "-w", `sample1/${SubProject.tests}`],
|
||||
commandLineArgs: ["-b", "-w", "sample1/tests"],
|
||||
sys: () =>
|
||||
createWatchedSystem(
|
||||
allFilesGetter(),
|
||||
{ currentDirectory: "/user/username/projects" },
|
||||
),
|
||||
edits: [
|
||||
changeNewFile(newFile.content),
|
||||
{
|
||||
caption: "Change to new File and build core",
|
||||
edit: sys => sys.writeFile("sample1/core/newfile.ts", `export const newFileConst = 30;`),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // Builds core
|
||||
},
|
||||
buildLogicAndTests,
|
||||
changeNewFile(`${newFile.content}
|
||||
export class someClass2 { }`),
|
||||
{
|
||||
caption: "Change to new File and build core",
|
||||
edit: sys => sys.appendFile("sample1/core/newfile.ts", `\nexport class someClass2 { }`),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // Builds core
|
||||
},
|
||||
buildLogicAndTests,
|
||||
],
|
||||
});
|
||||
@@ -196,24 +139,20 @@ export class someClass2 { }`),
|
||||
describe("with simple project reference graph", () => {
|
||||
verifyProjectChanges(
|
||||
"with simple project reference graph",
|
||||
() => allFiles,
|
||||
getFsContentsForSampleProjectReferences,
|
||||
);
|
||||
});
|
||||
|
||||
describe("with circular project reference", () => {
|
||||
verifyProjectChanges(
|
||||
"with circular project reference",
|
||||
() => {
|
||||
const [coreTsconfig, ...otherCoreFiles] = core;
|
||||
const circularCoreConfig: File = {
|
||||
path: coreTsconfig.path,
|
||||
content: JSON.stringify({
|
||||
compilerOptions: { composite: true, declaration: true },
|
||||
references: [{ path: "../tests", circular: true }],
|
||||
}),
|
||||
};
|
||||
return [libFile, circularCoreConfig, ...otherCoreFiles, ...logic, ...tests];
|
||||
},
|
||||
() => ({
|
||||
...getFsContentsForSampleProjectReferences(),
|
||||
"/user/username/projects/sample1/core/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, declaration: true },
|
||||
references: [{ path: "../tests", circular: true }],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -221,16 +160,16 @@ export class someClass2 { }`),
|
||||
verifyTscWatch({
|
||||
scenario: "programUpdates",
|
||||
subScenario: "watches config files that are not present",
|
||||
commandLineArgs: ["-b", "-w", `sample1/${SubProject.tests}`],
|
||||
sys: () =>
|
||||
createWatchedSystem(
|
||||
[libFile, ...core, logic[1], ...tests],
|
||||
{ currentDirectory: "/user/username/projects" },
|
||||
),
|
||||
commandLineArgs: ["-b", "-w", "tests"],
|
||||
sys: () => {
|
||||
const sys = getSysForSampleProjectReferences();
|
||||
sys.deleteFile("logic/tsconfig.json");
|
||||
return sys;
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
caption: "Write logic tsconfig and build logic",
|
||||
edit: sys => sys.writeFile(logic[0].path, logic[0].content),
|
||||
edit: sys => sys.writeFile("logic/tsconfig.json", getFsContentsForSampleProjectReferencesLogicConfig()),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // Builds logic
|
||||
},
|
||||
{
|
||||
@@ -242,58 +181,47 @@ export class someClass2 { }`),
|
||||
],
|
||||
});
|
||||
|
||||
describe("when referenced using prepend, builds referencing project even for non local change", () => {
|
||||
let coreIndex: File;
|
||||
before(() => {
|
||||
coreIndex = {
|
||||
path: core[1].path,
|
||||
content: `function foo() { return 10; }`,
|
||||
};
|
||||
});
|
||||
after(() => {
|
||||
coreIndex = undefined!;
|
||||
});
|
||||
const buildLogic: TscWatchCompileChange = {
|
||||
caption: "Build logic",
|
||||
edit: ts.noop,
|
||||
// Builds logic
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
};
|
||||
verifyTscWatch({
|
||||
scenario: "programUpdates",
|
||||
subScenario: "when referenced using prepend builds referencing project even for non local change",
|
||||
commandLineArgs: ["-b", "-w", `sample1/${SubProject.logic}`],
|
||||
sys: () => {
|
||||
const coreTsConfig: File = {
|
||||
path: core[0].path,
|
||||
content: JSON.stringify({
|
||||
compilerOptions: { composite: true, declaration: true, outFile: "index.js" },
|
||||
}),
|
||||
};
|
||||
const logicTsConfig: File = {
|
||||
path: logic[0].path,
|
||||
content: JSON.stringify({
|
||||
compilerOptions: { ignoreDeprecations: "5.0", composite: true, declaration: true, outFile: "index.js" },
|
||||
references: [{ path: "../core", prepend: true }],
|
||||
}),
|
||||
};
|
||||
const logicIndex: File = {
|
||||
path: logic[1].path,
|
||||
content: `function bar() { return foo() + 1 };`,
|
||||
};
|
||||
return createWatchedSystem([libFile, coreTsConfig, coreIndex, logicTsConfig, logicIndex], { currentDirectory: "/user/username/projects" });
|
||||
verifyTscWatch({
|
||||
scenario: "programUpdates",
|
||||
subScenario: "when referenced using prepend builds referencing project even for non local change",
|
||||
commandLineArgs: ["-b", "-w", "sample1/logic"],
|
||||
sys: () =>
|
||||
createWatchedSystem({
|
||||
[libFile.path]: libFile.content,
|
||||
"/user/username/projects/sample1/core/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, declaration: true, outFile: "index.js" },
|
||||
}),
|
||||
"/user/username/projects/sample1/core/index.ts": `function foo() { return 10; }`,
|
||||
"/user/username/projects/sample1/logic/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { ignoreDeprecations: "5.0", composite: true, declaration: true, outFile: "index.js" },
|
||||
references: [{ path: "../core", prepend: true }],
|
||||
}),
|
||||
"/user/username/projects/sample1/logic/index.ts": `function bar() { return foo() + 1 };`,
|
||||
}, { currentDirectory: "/user/username/projects" }),
|
||||
edits: [
|
||||
{
|
||||
caption: "Make non local change and build core",
|
||||
edit: sys => sys.appendFile("sample1/core/index.ts", `\nfunction myFunc() { return 10; }`),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // Builds core
|
||||
},
|
||||
edits: [
|
||||
changeCore(() =>
|
||||
`${coreIndex.content}
|
||||
function myFunc() { return 10; }`, "Make non local change and build core"),
|
||||
buildLogic,
|
||||
changeCore(() =>
|
||||
`${coreIndex.content}
|
||||
function myFunc() { return 100; }`, "Make local change and build core"),
|
||||
buildLogic,
|
||||
],
|
||||
});
|
||||
{
|
||||
caption: "Build logic",
|
||||
edit: ts.noop,
|
||||
// Builds logic
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Make local change and build core",
|
||||
edit: sys => sys.replaceFileText("sample1/core/index.ts", `\nfunction myFunc() { return 10; }`, `\nfunction myFunc() { return 100; }`),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // Builds core
|
||||
},
|
||||
{
|
||||
caption: "Build logic",
|
||||
edit: ts.noop,
|
||||
// Builds logic
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
describe("when referenced project change introduces error in the down stream project and then fixes it", () => {
|
||||
@@ -320,7 +248,7 @@ export function createSomeObject(): SomeObject
|
||||
sys: () => {
|
||||
const libraryTsconfig: File = {
|
||||
path: `${subProjectLibrary}/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { composite: true } }),
|
||||
content: jsonToReadableText({ compilerOptions: { composite: true } }),
|
||||
};
|
||||
const subProjectApp = `${"/user/username/projects"}/sample1/App`;
|
||||
const appTs: File = {
|
||||
@@ -330,7 +258,7 @@ createSomeObject().message;`,
|
||||
};
|
||||
const appTsconfig: File = {
|
||||
path: `${subProjectApp}/tsconfig.json`,
|
||||
content: JSON.stringify({ references: [{ path: "../Library" }] }),
|
||||
content: jsonToReadableText({ references: [{ path: "../Library" }] }),
|
||||
};
|
||||
|
||||
const files = [libFile, libraryTs, libraryTsconfig, appTs, appTsconfig];
|
||||
@@ -364,28 +292,18 @@ createSomeObject().message;`,
|
||||
verifyTscWatch({
|
||||
scenario: "programUpdates",
|
||||
subScenario: `reportErrors/${subScenario}`,
|
||||
commandLineArgs: ["-b", "-w", `sample1/${SubProject.tests}`, ...buildOptions],
|
||||
sys: () => createWatchedSystem(allFiles, { currentDirectory: "/user/username/projects" }),
|
||||
commandLineArgs: ["-b", "-w", "tests", ...buildOptions],
|
||||
sys: getSysForSampleProjectReferences,
|
||||
edits: [
|
||||
{
|
||||
caption: "change logic",
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
logic[1].path,
|
||||
`${logic[1].content}
|
||||
let y: string = 10;`,
|
||||
),
|
||||
edit: sys => sys.appendFile("logic/index.ts", `\nlet y: string = 10;`),
|
||||
// Builds logic
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "change core",
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
core[1].path,
|
||||
`${core[1].content}
|
||||
let x: string = 10;`,
|
||||
),
|
||||
edit: sys => sys.appendFile("core/index.ts", `\nlet x: string = 10;`),
|
||||
// Builds core
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
@@ -416,7 +334,7 @@ let x: string = 10;`,
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: `${subProjectLocation}/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { composite: true } }),
|
||||
content: jsonToReadableText({ compilerOptions: { composite: true } }),
|
||||
};
|
||||
|
||||
const fixError: TscWatchCompileChange = {
|
||||
@@ -503,27 +421,17 @@ let x: string = 10;`,
|
||||
verifyTscWatch({
|
||||
scenario: "programUpdates",
|
||||
subScenario: "incremental updates in verbose mode",
|
||||
commandLineArgs: ["-b", "-w", `sample1/${SubProject.tests}`, "-verbose"],
|
||||
sys: () => createWatchedSystem(allFiles, { currentDirectory: "/user/username/projects" }),
|
||||
commandLineArgs: ["-b", "-w", "tests", "-verbose"],
|
||||
sys: getSysForSampleProjectReferences,
|
||||
edits: [
|
||||
{
|
||||
caption: "Make non dts change",
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
logic[1].path,
|
||||
`${logic[1].content}
|
||||
function someFn() { }`,
|
||||
),
|
||||
edit: sys => sys.appendFile("logic/index.ts", `\nfunction someFn() { }`),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(), // build logic and updates tests
|
||||
},
|
||||
{
|
||||
caption: "Make dts change",
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
logic[1].path,
|
||||
`${logic[1].content}
|
||||
export function someFn() { }`,
|
||||
),
|
||||
edit: sys => sys.replaceFileText("logic/index.ts", `\nfunction someFn() { }`, `\nexport function someFn() { }`),
|
||||
timeouts: sys => {
|
||||
sys.runQueuedTimeoutCallbacks(); // build logic
|
||||
sys.runQueuedTimeoutCallbacks(); // build tests
|
||||
@@ -543,7 +451,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const configFile: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
noUnusedParameters: true,
|
||||
},
|
||||
@@ -557,7 +465,7 @@ export function someFn() { }`,
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
`/user/username/projects/myproject/tsconfig.json`,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
noUnusedParameters: false,
|
||||
},
|
||||
@@ -571,13 +479,13 @@ export function someFn() { }`,
|
||||
verifyTscWatch({
|
||||
scenario: "programUpdates",
|
||||
subScenario: "should not trigger recompilation because of program emit",
|
||||
commandLineArgs: ["-b", "-w", `sample1/${SubProject.core}`, "-verbose"],
|
||||
sys: () => createWatchedSystem([libFile, ...core], { currentDirectory: "/user/username/projects" }),
|
||||
commandLineArgs: ["-b", "-w", "core", "-verbose"],
|
||||
sys: getSysForSampleProjectReferences,
|
||||
edits: [
|
||||
noopChange,
|
||||
{
|
||||
caption: "Add new file",
|
||||
edit: sys => sys.writeFile(`sample1/${SubProject.core}/file3.ts`, `export const y = 10;`),
|
||||
edit: sys => sys.writeFile("core/file3.ts", `export const y = 10;`),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
noopChange,
|
||||
@@ -587,17 +495,19 @@ export function someFn() { }`,
|
||||
verifyTscWatch({
|
||||
scenario: "programUpdates",
|
||||
subScenario: "should not trigger recompilation because of program emit with outDir specified",
|
||||
commandLineArgs: ["-b", "-w", `sample1/${SubProject.core}`, "-verbose"],
|
||||
sys: () => {
|
||||
const [coreConfig, ...rest] = core;
|
||||
const newCoreConfig: File = { path: coreConfig.path, content: JSON.stringify({ compilerOptions: { composite: true, outDir: "outDir" } }) };
|
||||
return createWatchedSystem([libFile, newCoreConfig, ...rest], { currentDirectory: "/user/username/projects" });
|
||||
},
|
||||
commandLineArgs: ["-b", "-w", "sample1/core", "-verbose"],
|
||||
sys: () =>
|
||||
createWatchedSystem({
|
||||
...getFsContentsForSampleProjectReferences(),
|
||||
"/user/username/projects/sample1/core/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, outDir: "outDir" },
|
||||
}),
|
||||
}, { currentDirectory: "/user/username/projects" }),
|
||||
edits: [
|
||||
noopChange,
|
||||
{
|
||||
caption: "Add new file",
|
||||
edit: sys => sys.writeFile(`sample1/${SubProject.core}/file3.ts`, `export const y = 10;`),
|
||||
edit: sys => sys.writeFile("sample1/core/file3.ts", `export const y = 10;`),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
noopChange,
|
||||
@@ -615,7 +525,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const project1Config: File = {
|
||||
path: "/a/b/project1.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
extends: "./alpha.tsconfig.json",
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
@@ -625,7 +535,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const bravoExtendedConfigFile: File = {
|
||||
path: "/a/b/bravo.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
extends: "./alpha.tsconfig.json",
|
||||
}),
|
||||
};
|
||||
@@ -635,7 +545,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const project2Config: File = {
|
||||
path: "/a/b/project2.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
extends: "./bravo.tsconfig.json",
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
@@ -649,7 +559,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const extendsConfigFile1: File = {
|
||||
path: "/a/b/extendsConfig1.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
},
|
||||
@@ -657,7 +567,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const extendsConfigFile2: File = {
|
||||
path: "/a/b/extendsConfig2.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strictNullChecks: false,
|
||||
},
|
||||
@@ -665,7 +575,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const extendsConfigFile3: File = {
|
||||
path: "/a/b/extendsConfig3.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
noImplicitAny: true,
|
||||
},
|
||||
@@ -673,7 +583,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const project3Config: File = {
|
||||
path: "/a/b/project3.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
extends: ["./extendsConfig1.tsconfig.json", "./extendsConfig2.tsconfig.json", "./extendsConfig3.tsconfig.json"],
|
||||
compilerOptions: {
|
||||
composite: false,
|
||||
@@ -703,7 +613,7 @@ export function someFn() { }`,
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
"/a/b/alpha.tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { strict: true },
|
||||
}),
|
||||
),
|
||||
@@ -719,7 +629,7 @@ export function someFn() { }`,
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
"/a/b/bravo.tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
extends: "./alpha.tsconfig.json",
|
||||
compilerOptions: { strict: false },
|
||||
}),
|
||||
@@ -731,7 +641,7 @@ export function someFn() { }`,
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
"/a/b/project2.tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
extends: "./alpha.tsconfig.json",
|
||||
}),
|
||||
),
|
||||
@@ -752,7 +662,7 @@ export function someFn() { }`,
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
"/a/b/extendsConfig2.tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { strictNullChecks: true },
|
||||
}),
|
||||
),
|
||||
@@ -763,7 +673,7 @@ export function someFn() { }`,
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
"/a/b/project3.tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
extends: ["./extendsConfig1.tsconfig.json", "./extendsConfig2.tsconfig.json"],
|
||||
compilerOptions: { composite: false },
|
||||
files: ["/a/b/other2.ts"],
|
||||
@@ -786,7 +696,7 @@ export function someFn() { }`,
|
||||
sys: () => {
|
||||
const alphaExtendedConfigFile: File = {
|
||||
path: "/a/b/alpha.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: true,
|
||||
},
|
||||
@@ -794,7 +704,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const project1Config: File = {
|
||||
path: "/a/b/project1.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
extends: "./alpha.tsconfig.json",
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
@@ -804,7 +714,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const bravoExtendedConfigFile: File = {
|
||||
path: "/a/b/bravo.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: true,
|
||||
},
|
||||
@@ -816,7 +726,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const project2Config: File = {
|
||||
path: "/a/b/project2.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
extends: "./bravo.tsconfig.json",
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
@@ -826,7 +736,7 @@ export function someFn() { }`,
|
||||
};
|
||||
const configFile: File = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
references: [
|
||||
{
|
||||
path: "./project1.tsconfig.json",
|
||||
@@ -856,7 +766,7 @@ export function someFn() { }`,
|
||||
edit: sys =>
|
||||
sys.modifyFile(
|
||||
"/a/b/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
references: [
|
||||
{
|
||||
path: "./project1.tsconfig.json",
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
noopChange,
|
||||
TscWatchCompileChange,
|
||||
@@ -29,7 +32,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: projectsBuilding", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/pkg${index}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
references: index === 0 ?
|
||||
undefined :
|
||||
@@ -41,7 +44,7 @@ describe("unittests:: tsbuildWatch:: watchMode:: projectsBuilding", () => {
|
||||
function solution(maxPkgs: number): File {
|
||||
return {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
references: pkgs(createPkgReference, maxPkgs),
|
||||
files: [],
|
||||
}),
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
createBaseline,
|
||||
createSolutionBuilderWithWatchHostForBaseline,
|
||||
@@ -13,7 +16,7 @@ import {
|
||||
it("unittests:: tsbuildWatch:: watchMode:: Public API with custom transformers", () => {
|
||||
const solution: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
references: [
|
||||
{ path: "./shared/tsconfig.json" },
|
||||
{ path: "./webpack/tsconfig.json" },
|
||||
@@ -23,7 +26,7 @@ it("unittests:: tsbuildWatch:: watchMode:: Public API with custom transformers",
|
||||
};
|
||||
const sharedConfig: File = {
|
||||
path: `/user/username/projects/myproject/shared/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
}),
|
||||
};
|
||||
@@ -37,7 +40,7 @@ export function f2() { } // trailing`,
|
||||
};
|
||||
const webpackConfig: File = {
|
||||
path: `/user/username/projects/myproject/webpack/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
references: [{ path: "../shared/tsconfig.json" }],
|
||||
}),
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
libContent,
|
||||
} from "../helpers/contents";
|
||||
@@ -6,7 +12,6 @@ import {
|
||||
} from "../helpers/tscWatch";
|
||||
import {
|
||||
createWatchedSystem,
|
||||
getTsBuildProjectFile,
|
||||
libFile,
|
||||
} from "../helpers/virtualFileSystemWithWatch";
|
||||
|
||||
@@ -16,21 +21,44 @@ describe("unittests:: tsbuildWatch:: watchMode:: with reexport when referenced p
|
||||
subScenario: "Reports errors correctly",
|
||||
commandLineArgs: ["-b", "-w", "-verbose", "src"],
|
||||
sys: () =>
|
||||
createWatchedSystem(
|
||||
[
|
||||
...[
|
||||
"src/tsconfig.json",
|
||||
"src/main/tsconfig.json",
|
||||
"src/main/index.ts",
|
||||
"src/pure/tsconfig.json",
|
||||
"src/pure/index.ts",
|
||||
"src/pure/session.ts",
|
||||
]
|
||||
.map(f => getTsBuildProjectFile("reexport", f)),
|
||||
{ path: libFile.path, content: libContent },
|
||||
],
|
||||
{ currentDirectory: `/user/username/projects/reexport` },
|
||||
),
|
||||
createWatchedSystem({
|
||||
"/user/username/projects/reexport/src/tsconfig.json": jsonToReadableText({
|
||||
files: [],
|
||||
include: [],
|
||||
references: [{ path: "./pure" }, { path: "./main" }],
|
||||
}),
|
||||
"/user/username/projects/reexport/src/main/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "../../out",
|
||||
rootDir: "../",
|
||||
},
|
||||
include: ["**/*.ts"],
|
||||
references: [{ path: "../pure" }],
|
||||
}),
|
||||
"/user/username/projects/reexport/src/main/index.ts": dedent`
|
||||
import { Session } from "../pure";
|
||||
|
||||
export const session: Session = {
|
||||
foo: 1
|
||||
};
|
||||
`,
|
||||
"/user/username/projects/reexport/src/pure/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
outDir: "../../out",
|
||||
rootDir: "../",
|
||||
},
|
||||
include: ["**/*.ts"],
|
||||
}),
|
||||
"/user/username/projects/reexport/src/pure/index.ts": `export * from "./session";\n`,
|
||||
"/user/username/projects/reexport/src/pure/session.ts": dedent`
|
||||
export interface Session {
|
||||
foo: number;
|
||||
// bar: number;
|
||||
}
|
||||
`,
|
||||
[libFile.path]: libContent,
|
||||
}, { currentDirectory: `/user/username/projects/reexport` }),
|
||||
edits: [
|
||||
{
|
||||
caption: "Introduce error",
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
createBaseline,
|
||||
createSolutionBuilderWithWatchHostForBaseline,
|
||||
@@ -101,7 +104,7 @@ describe("unittests:: tsbuildWatch:: watchEnvironment:: tsbuild:: watchMode:: wi
|
||||
},
|
||||
{
|
||||
path: `${project}/pkg${index}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
complerOptions: { composite: true },
|
||||
include: [
|
||||
"**/*.ts",
|
||||
@@ -114,7 +117,7 @@ describe("unittests:: tsbuildWatch:: watchEnvironment:: tsbuild:: watchMode:: wi
|
||||
function writePkgReferences(system: TestServerHost) {
|
||||
system.writeFile(
|
||||
configPath,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
files: [],
|
||||
include: [],
|
||||
references: pkgs(createPkgReference),
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as Utils from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineBuildInfo,
|
||||
CommandLineProgram,
|
||||
@@ -50,7 +53,7 @@ describe("unittests:: tsc:: builder cancellationToken", () => {
|
||||
};
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { incremental: true, declaration: true } }),
|
||||
content: jsonToReadableText({ compilerOptions: { incremental: true, declaration: true } }),
|
||||
};
|
||||
const { sys, baseline, oldSnap: originalSnap } = createBaseline(createWatchedSystem(
|
||||
[aFile, bFile, cFile, dFile, config, libFile],
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as Utils from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
@@ -100,7 +103,7 @@ describe("unittests:: tsc:: composite::", () => {
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/src/main.ts": "const x = 10;",
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "none",
|
||||
composite: true,
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as Utils from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTscWatch,
|
||||
} from "../helpers/tscWatch";
|
||||
@@ -50,7 +53,7 @@ describe("unittests:: tsc:: declarationEmit::", () => {
|
||||
|
||||
describe("with symlinks in sibling folders and common package referenced from both folders", () => {
|
||||
function pluginOneConfig() {
|
||||
return JSON.stringify({
|
||||
return jsonToReadableText({
|
||||
compilerOptions: {
|
||||
target: "es5",
|
||||
declaration: true,
|
||||
@@ -93,7 +96,7 @@ describe("unittests:: tsc:: declarationEmit::", () => {
|
||||
export default _default;`;
|
||||
}
|
||||
function fsaPackageJson() {
|
||||
return JSON.stringify({
|
||||
return jsonToReadableText({
|
||||
name: "typescript-fsa",
|
||||
version: "3.0.0-beta-2",
|
||||
});
|
||||
@@ -139,7 +142,7 @@ describe("unittests:: tsc:: declarationEmit::", () => {
|
||||
files: [
|
||||
{
|
||||
path: `/user/username/projects/myproject/plugin-two/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "plugin-two",
|
||||
version: "0.1.3",
|
||||
main: "dist/commonjs/index.js",
|
||||
@@ -192,7 +195,7 @@ ${pluginOneAction()}`,
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/pkg1/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "@raymondfeng/pkg1",
|
||||
version: "1.0.0",
|
||||
main: "dist/index.js",
|
||||
@@ -211,7 +214,7 @@ ${pluginOneAction()}`,
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/pkg2/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "@raymondfeng/pkg2",
|
||||
version: "1.0.0",
|
||||
main: "dist/index.js",
|
||||
@@ -231,7 +234,7 @@ ${pluginOneAction()}`,
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/pkg3/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "dist",
|
||||
rootDir: "src",
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as Utils from "../../_namespaces/Utils";
|
||||
import * as vfs from "../../_namespaces/vfs";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
compilerOptionsToConfigJson,
|
||||
libContent,
|
||||
} from "../helpers/contents";
|
||||
import {
|
||||
getFsForNoEmitOnError,
|
||||
} from "../helpers/noEmitOnError";
|
||||
import {
|
||||
noChangeOnlyRuns,
|
||||
noChangeRun,
|
||||
@@ -13,7 +19,6 @@ import {
|
||||
} from "../helpers/tsc";
|
||||
import {
|
||||
appendText,
|
||||
loadProjectFromDisk,
|
||||
loadProjectFromFiles,
|
||||
prependText,
|
||||
replaceText,
|
||||
@@ -116,7 +121,7 @@ describe("unittests:: tsc:: incremental::", () => {
|
||||
describe("with noEmitOnError", () => {
|
||||
let projFs: vfs.FileSystem;
|
||||
before(() => {
|
||||
projFs = loadProjectFromDisk("tests/projects/noEmitOnError");
|
||||
projFs = getFsForNoEmitOnError();
|
||||
});
|
||||
after(() => {
|
||||
projFs = undefined!;
|
||||
@@ -127,7 +132,7 @@ describe("unittests:: tsc:: incremental::", () => {
|
||||
scenario: "incremental",
|
||||
subScenario,
|
||||
fs: () => projFs,
|
||||
commandLineArgs: ["--incremental", "-p", "src"],
|
||||
commandLineArgs: ["--incremental"],
|
||||
modifyFs,
|
||||
edits: [
|
||||
noChangeRun,
|
||||
@@ -144,7 +149,7 @@ describe("unittests:: tsc:: incremental::", () => {
|
||||
"with noEmitOnError syntax errors",
|
||||
fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/src/main.ts",
|
||||
"src/main.ts",
|
||||
`import { A } from "../shared/types/db";
|
||||
const a = {
|
||||
lastName: 'sdsd'
|
||||
@@ -157,14 +162,14 @@ const a = {
|
||||
"with noEmitOnError semantic errors",
|
||||
fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/src/main.ts",
|
||||
"src/main.ts",
|
||||
`import { A } from "../shared/types/db";
|
||||
const a: string = "hello";`,
|
||||
"utf-8",
|
||||
),
|
||||
fs =>
|
||||
fs.writeFileSync(
|
||||
"/src/src/main.ts",
|
||||
"src/main.ts",
|
||||
`import { A } from "../shared/types/db";
|
||||
const a: string = 10;`,
|
||||
"utf-8",
|
||||
@@ -295,7 +300,7 @@ const a: string = 10;`,
|
||||
"/src/project/src/noChangeFileWithEmitSpecificError.ts": Utils.dedent`
|
||||
function someFunc(arguments: boolean, ...rest: any[]) {
|
||||
}`,
|
||||
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions }),
|
||||
"/src/project/tsconfig.json": jsonToReadableText({ compilerOptions }),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -317,7 +322,7 @@ const a: string = 10;`,
|
||||
function anotherFileWithSameReferenes() { }
|
||||
`,
|
||||
"/src/project/src/filePresent.ts": `function something() { return 10; }`,
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
include: ["src/**/*.ts"],
|
||||
}),
|
||||
@@ -382,7 +387,7 @@ declare global {
|
||||
"/src/project/node_modules/react/jsx-runtime.js": "export {}", // js needs to be present so there's a resolution result
|
||||
"/src/project/node_modules/@types/react/index.d.ts": getJsxLibraryContent(), // doesn't contain a jsx-runtime definition
|
||||
"/src/project/src/index.tsx": `export const App = () => <div propA={true}></div>;`,
|
||||
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" } }),
|
||||
"/src/project/tsconfig.json": jsonToReadableText({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" } }),
|
||||
}),
|
||||
commandLineArgs: ["--p", "src/project"],
|
||||
});
|
||||
@@ -395,7 +400,7 @@ declare global {
|
||||
"/src/project/node_modules/react/jsx-runtime.js": "export {}", // js needs to be present so there's a resolution result
|
||||
"/src/project/node_modules/@types/react/index.d.ts": getJsxLibraryContent(), // doesn't contain a jsx-runtime definition
|
||||
"/src/project/src/index.tsx": `export const App = () => <div propA={true}></div>;`,
|
||||
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" } }),
|
||||
"/src/project/tsconfig.json": jsonToReadableText({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" } }),
|
||||
}),
|
||||
commandLineArgs: ["--p", "src/project", "--strict"],
|
||||
});
|
||||
@@ -407,7 +412,7 @@ declare global {
|
||||
commandLineArgs: ["-i", "-p", `src/projects/project2`],
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/projects/project1/tsconfig.json": JSON.stringify({
|
||||
"/src/projects/project1/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "none",
|
||||
composite: true,
|
||||
@@ -416,7 +421,7 @@ declare global {
|
||||
}),
|
||||
"/src/projects/project1/class1.ts": `class class1 {}`,
|
||||
"/src/projects/project1/class1.d.ts": `declare class class1 {}`,
|
||||
"/src/projects/project2/tsconfig.json": JSON.stringify({
|
||||
"/src/projects/project2/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "none",
|
||||
composite: true,
|
||||
@@ -468,7 +473,7 @@ declare global {
|
||||
commandLineArgs: ["-noEmit", "-p", `src/project`],
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
incremental: true,
|
||||
strict: true,
|
||||
@@ -486,7 +491,7 @@ declare global {
|
||||
commandLineArgs: ["-p", `src/project`],
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
incremental: true,
|
||||
strict: true,
|
||||
@@ -550,7 +555,7 @@ declare global {
|
||||
commandLineArgs: ["-p", `src/project`],
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions: { composite: true } }),
|
||||
"/src/project/tsconfig.json": jsonToReadableText({ compilerOptions: { composite: true } }),
|
||||
"/src/project/class1.ts": `const a: MagicNumber = 1;
|
||||
console.log(a);`,
|
||||
"/src/project/constants.ts": "export default 1;",
|
||||
@@ -568,7 +573,7 @@ console.log(a);`,
|
||||
commandLineArgs: ["-p", `src/project`],
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions: { composite: true } }),
|
||||
"/src/project/tsconfig.json": jsonToReadableText({ compilerOptions: { composite: true } }),
|
||||
"/src/project/class1.ts": `const a: MagicNumber = 1;
|
||||
console.log(a);`,
|
||||
"/src/project/constants.ts": "export default 1;",
|
||||
@@ -588,7 +593,7 @@ console.log(a);`,
|
||||
commandLineArgs: ["-p", "src/project", "--incremental"],
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions: { declaration } }),
|
||||
"/src/project/tsconfig.json": jsonToReadableText({ compilerOptions: { declaration } }),
|
||||
"/src/project/main.ts": Utils.dedent`
|
||||
import MessageablePerson from './MessageablePerson.js';
|
||||
function logMessage( person: MessageablePerson ) {
|
||||
@@ -632,7 +637,7 @@ console.log(a);`,
|
||||
subScenario: `when declarationMap changes`,
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
noEmitOnError: true,
|
||||
declaration: true,
|
||||
@@ -667,7 +672,7 @@ console.log(a);`,
|
||||
subScenario: `when declarationMap changes with outFile`,
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
noEmitOnError: true,
|
||||
declaration: true,
|
||||
@@ -750,7 +755,7 @@ console.log(a);`,
|
||||
}
|
||||
function fs(options: ts.CompilerOptions) {
|
||||
return loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions: compilerOptionsToConfigJson(options) }),
|
||||
"/src/project/tsconfig.json": jsonToReadableText({ compilerOptions: compilerOptionsToConfigJson(options) }),
|
||||
"/src/project/a.ts": `export const a = 10;const aLocal = 10;`,
|
||||
"/src/project/b.ts": `export const b = 10;const bLocal = 10;`,
|
||||
"/src/project/c.ts": `import { a } from "./a";export const c = a;`,
|
||||
@@ -763,7 +768,7 @@ console.log(a);`,
|
||||
edit: fs => {
|
||||
const config = JSON.parse(fs.readFileSync("/src/project/tsconfig.json", "utf-8"));
|
||||
config.compilerOptions.declarationMap = true;
|
||||
fs.writeFileSync("/src/project/tsconfig.json", JSON.stringify(config));
|
||||
fs.writeFileSync("/src/project/tsconfig.json", jsonToReadableText(config));
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -865,7 +870,7 @@ console.log(a);`,
|
||||
commandLineArgs: ["-p", `/src/project`],
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
outDir: "outDir",
|
||||
@@ -887,7 +892,7 @@ console.log(a);`,
|
||||
subScenario: "file deleted before fixing error with noEmitOnError",
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "outDir",
|
||||
noEmitOnError: true,
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
@@ -12,7 +15,7 @@ describe("unittests:: tsc:: projectReferences::", () => {
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/src/main.ts": "export const x = 10;",
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "amd",
|
||||
outFile: "theApp.js",
|
||||
@@ -31,14 +34,14 @@ describe("unittests:: tsc:: projectReferences::", () => {
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/utils/index.ts": "export const x = 10;",
|
||||
"/src/utils/tsconfig.json": JSON.stringify({
|
||||
"/src/utils/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
noEmit: true,
|
||||
},
|
||||
}),
|
||||
"/src/project/index.ts": `import { x } from "../utils";`,
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
references: [
|
||||
{ path: "../utils" },
|
||||
],
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
@@ -23,24 +26,20 @@ function getConfig({ references, options, config }: {
|
||||
options?: ts.CompilerOptions;
|
||||
config?: object;
|
||||
} = {}) {
|
||||
return JSON.stringify(
|
||||
{
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
outDir: "bin",
|
||||
...options,
|
||||
},
|
||||
references: references?.map(r => {
|
||||
if (typeof r === "string") {
|
||||
return { path: r };
|
||||
}
|
||||
return r;
|
||||
}) || [],
|
||||
...config,
|
||||
return jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
outDir: "bin",
|
||||
...options,
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
);
|
||||
references: references?.map(r => {
|
||||
if (typeof r === "string") {
|
||||
return { path: r };
|
||||
}
|
||||
return r;
|
||||
}) || [],
|
||||
...config,
|
||||
});
|
||||
}
|
||||
|
||||
describe("unittests:: config:: project-references meta check", () => {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTsc,
|
||||
} from "../helpers/tsc";
|
||||
@@ -11,7 +14,7 @@ describe("unittests:: tsc:: redirect::", () => {
|
||||
subScenario: "when redirecting ts file",
|
||||
fs: () =>
|
||||
loadProjectFromFiles({
|
||||
"/src/project/tsconfig.json": JSON.stringify({
|
||||
"/src/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "out",
|
||||
},
|
||||
@@ -22,14 +25,14 @@ describe("unittests:: tsc:: redirect::", () => {
|
||||
}),
|
||||
"/src/project/copy1/node_modules/target/index.ts": "export const a = 1;",
|
||||
"/src/project/copy1/node_modules/target/import.ts": `import {} from "./";`,
|
||||
"/src/project/copy1/node_modules/target/package.json": JSON.stringify({
|
||||
"/src/project/copy1/node_modules/target/package.json": jsonToReadableText({
|
||||
name: "target",
|
||||
version: "1.0.0",
|
||||
main: "index.js",
|
||||
}),
|
||||
"/src/project/copy2/node_modules/target/index.ts": "export const a = 1;",
|
||||
"/src/project/copy2/node_modules/target/import.ts": `import {} from "./";`,
|
||||
"/src/project/copy2/node_modules/target/package.json": JSON.stringify({
|
||||
"/src/project/copy2/node_modules/target/package.json": jsonToReadableText({
|
||||
name: "target",
|
||||
version: "1.0.0",
|
||||
main: "index.js",
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
createBaseline,
|
||||
createWatchCompilerHostOfConfigFileForBaseline,
|
||||
@@ -46,7 +49,7 @@ describe("unittests:: tsc-watch:: console clearing", () => {
|
||||
};
|
||||
const configFile: File = {
|
||||
path: "/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions }),
|
||||
content: jsonToReadableText({ compilerOptions }),
|
||||
};
|
||||
const files = [file, configFile, libFile];
|
||||
it("using createWatchOfConfigFile ", () => {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
TscWatchCompileChange,
|
||||
verifyTscWatch,
|
||||
@@ -21,7 +24,7 @@ describe("unittests:: tsc-watch:: emit with outFile or out setting", () => {
|
||||
createWatchedSystem({
|
||||
"/a/a.ts": "let x = 1",
|
||||
"/a/b.ts": "let y = 1",
|
||||
"/a/tsconfig.json": JSON.stringify({ compilerOptions: { out, outFile } }),
|
||||
"/a/tsconfig.json": jsonToReadableText({ compilerOptions: { out, outFile } }),
|
||||
[libFile.path]: libFile.content,
|
||||
}),
|
||||
edits: [
|
||||
@@ -66,7 +69,7 @@ describe("unittests:: tsc-watch:: emit with outFile or out setting", () => {
|
||||
};
|
||||
const configFile: File = {
|
||||
path: "/a/b/project/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: useOutFile ?
|
||||
{ outFile: "../output/common.js", target: "es5" } :
|
||||
{ outDir: "../output", target: "es5" },
|
||||
@@ -136,7 +139,7 @@ describe("unittests:: tsc-watch:: emit for configured projects", () => {
|
||||
};
|
||||
const configFile: File = {
|
||||
path: configFilePath,
|
||||
content: JSON.stringify(configObj || {}),
|
||||
content: jsonToReadableText(configObj || {}),
|
||||
};
|
||||
const additionalFiles = getAdditionalFileOrFolder?.() || ts.emptyArray;
|
||||
const files = [moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile, ...additionalFiles];
|
||||
@@ -469,7 +472,7 @@ describe("unittests:: tsc-watch:: emit file content", () => {
|
||||
};
|
||||
const configFile: File = {
|
||||
path: `${projectLocation}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
include: [
|
||||
"app/**/*.ts",
|
||||
],
|
||||
@@ -496,7 +499,7 @@ describe("unittests:: tsc-watch:: emit with when module emit is specified as nod
|
||||
sys: () => {
|
||||
const configFile: File = {
|
||||
path: "/a/rootFolder/project/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "none",
|
||||
allowJs: true,
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import {
|
||||
libContent,
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
FsContents,
|
||||
} from "../helpers/contents";
|
||||
import {
|
||||
getFsContentsForNoEmitOnError,
|
||||
} from "../helpers/noEmitOnError";
|
||||
import {
|
||||
TscWatchCompileChange,
|
||||
verifyTscWatch,
|
||||
@@ -8,7 +14,6 @@ import {
|
||||
import {
|
||||
createWatchedSystem,
|
||||
File,
|
||||
getTsBuildProjectFile,
|
||||
libFile,
|
||||
} from "../helpers/virtualFileSystemWithWatch";
|
||||
|
||||
@@ -19,7 +24,7 @@ describe("unittests:: tsc-watch:: Emit times and Error updates in builder after
|
||||
};
|
||||
interface VerifyEmitAndErrorUpdates {
|
||||
subScenario: string;
|
||||
files: () => File[];
|
||||
files: () => FsContents | readonly File[];
|
||||
currentDirectory?: string;
|
||||
changes: TscWatchCompileChange[];
|
||||
}
|
||||
@@ -251,7 +256,7 @@ getPoint().c.x;`,
|
||||
describe("updates errors when file transitively exported file changes", () => {
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
files: ["app.ts"],
|
||||
compilerOptions: { baseUrl: "." },
|
||||
}),
|
||||
@@ -370,9 +375,7 @@ export class Data2 {
|
||||
verifyEmitAndErrorUpdates({
|
||||
subScenario: "with noEmitOnError",
|
||||
currentDirectory: `/user/username/projects/noEmitOnError`,
|
||||
files: () =>
|
||||
["shared/types/db.ts", "src/main.ts", "src/other.ts", "tsconfig.json"]
|
||||
.map(f => getTsBuildProjectFile("noEmitOnError", f)).concat({ path: libFile.path, content: libContent }),
|
||||
files: getFsContentsForNoEmitOnError,
|
||||
changes: [
|
||||
noChange,
|
||||
change(
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as Utils from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
TscWatchCompileChange,
|
||||
verifyTscWatch,
|
||||
@@ -21,7 +24,7 @@ describe("unittests:: tsc-watch:: forceConsistentCasingInFileNames", () => {
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { forceConsistentCasingInFileNames: true },
|
||||
}),
|
||||
};
|
||||
@@ -77,7 +80,7 @@ describe("unittests:: tsc-watch:: forceConsistentCasingInFileNames", () => {
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { forceConsistentCasingInFileNames: true } }),
|
||||
content: jsonToReadableText({ compilerOptions: { forceConsistentCasingInFileNames: true } }),
|
||||
};
|
||||
return createWatchedSystem([moduleA, moduleB, moduleC, libFile, tsconfig], { currentDirectory: "/user/username/projects/myproject" });
|
||||
},
|
||||
@@ -119,7 +122,7 @@ export const Fragment: unique symbol;
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/node_modules/react/package.json`,
|
||||
content: JSON.stringify({ name: "react", version: "0.0.1" }),
|
||||
content: jsonToReadableText({ name: "react", version: "0.0.1" }),
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/index.tsx`,
|
||||
@@ -127,7 +130,7 @@ export const Fragment: unique symbol;
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { jsx: "react-jsx", jsxImportSource: "react", forceConsistentCasingInFileNames: true },
|
||||
files: ["node_modules/react/Jsx-Runtime/index.d.ts", "index.tsx"],
|
||||
}),
|
||||
@@ -159,7 +162,7 @@ a;b;
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: `${windowsStyleRoot}/${projectRootRelative}/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { forceConsistentCasingInFileNames: true } }),
|
||||
content: jsonToReadableText({ compilerOptions: { forceConsistentCasingInFileNames: true } }),
|
||||
};
|
||||
return createWatchedSystem([moduleA, moduleB, libFile, tsconfig], { windowsStyleRoot, useCaseSensitiveFileNames: false });
|
||||
},
|
||||
@@ -209,7 +212,7 @@ a;b;
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { forceConsistentCasingInFileNames: true } }),
|
||||
content: jsonToReadableText({ compilerOptions: { forceConsistentCasingInFileNames: true } }),
|
||||
};
|
||||
return createWatchedSystem([moduleA, symlinkA, moduleB, libFile, tsconfig], { currentDirectory: "/user/username/projects/myproject" });
|
||||
},
|
||||
@@ -264,7 +267,7 @@ a;b;
|
||||
const tsconfig: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
// Use outFile because otherwise the real and linked files will have the same output path
|
||||
content: JSON.stringify({ compilerOptions: { forceConsistentCasingInFileNames: true, outFile: "out.js", module: "system" } }),
|
||||
content: jsonToReadableText({ compilerOptions: { forceConsistentCasingInFileNames: true, outFile: "out.js", module: "system" } }),
|
||||
};
|
||||
return createWatchedSystem([moduleA, symlinkA, moduleB, libFile, tsconfig], { currentDirectory: "/user/username/projects/myproject" });
|
||||
},
|
||||
@@ -299,7 +302,7 @@ a;b;
|
||||
"/Users/name/projects/web/src/bin.ts": `import { foo } from "yargs";`,
|
||||
"/Users/name/projects/web/node_modules/@types/yargs/index.d.ts": "export function foo(): void;",
|
||||
"/Users/name/projects/web/node_modules/@types/yargs/index.d.mts": "export function foo(): void;",
|
||||
"/Users/name/projects/web/node_modules/@types/yargs/package.json": JSON.stringify({
|
||||
"/Users/name/projects/web/node_modules/@types/yargs/package.json": jsonToReadableText({
|
||||
name: "yargs",
|
||||
version: "17.0.12",
|
||||
exports: {
|
||||
@@ -311,7 +314,7 @@ a;b;
|
||||
},
|
||||
},
|
||||
}),
|
||||
"/Users/name/projects/web/tsconfig.json": JSON.stringify({
|
||||
"/Users/name/projects/web/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
moduleResolution: "nodenext",
|
||||
forceConsistentCasingInFileNames: true,
|
||||
@@ -328,7 +331,7 @@ a;b;
|
||||
commandLineArgs: ["-w", "--explainFiles"],
|
||||
sys: () =>
|
||||
createWatchedSystem({
|
||||
"/Users/name/projects/web/package.json": JSON.stringify({
|
||||
"/Users/name/projects/web/package.json": jsonToReadableText({
|
||||
name: "@this/package",
|
||||
type: "module",
|
||||
exports: {
|
||||
@@ -340,7 +343,7 @@ a;b;
|
||||
me.thing();
|
||||
export function thing(): void {}
|
||||
`,
|
||||
"/Users/name/projects/web/tsconfig.json": JSON.stringify({
|
||||
"/Users/name/projects/web/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "nodenext",
|
||||
outDir: "./dist",
|
||||
@@ -360,7 +363,7 @@ a;b;
|
||||
commandLineArgs: ["-w", "--explainFiles"],
|
||||
sys: () =>
|
||||
createWatchedSystem({
|
||||
"/Users/name/projects/lib-boilerplate/package.json": JSON.stringify({
|
||||
"/Users/name/projects/lib-boilerplate/package.json": jsonToReadableText({
|
||||
name: "lib-boilerplate",
|
||||
version: "0.0.2",
|
||||
type: "module",
|
||||
@@ -372,7 +375,7 @@ a;b;
|
||||
"/Users/name/projects/lib-boilerplate/test/basic.spec.ts": Utils.dedent`
|
||||
import { thing } from 'lib-boilerplate'
|
||||
`,
|
||||
"/Users/name/projects/lib-boilerplate/tsconfig.json": JSON.stringify({
|
||||
"/Users/name/projects/lib-boilerplate/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "node16",
|
||||
target: "es2021",
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
CommandLineProgram,
|
||||
} from "../helpers/baseline";
|
||||
@@ -25,7 +28,7 @@ describe("unittests:: tsc-watch:: emit file --incremental", () => {
|
||||
|
||||
const configFile: File = {
|
||||
path: `${project}/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { incremental: true } }),
|
||||
content: jsonToReadableText({ compilerOptions: { incremental: true } }),
|
||||
};
|
||||
|
||||
interface VerifyIncrementalWatchEmitInput {
|
||||
@@ -115,7 +118,7 @@ describe("unittests:: tsc-watch:: emit file --incremental", () => {
|
||||
verifyIncrementalWatchEmit({
|
||||
files: () => [libFile, file1, file2, {
|
||||
path: configFile.path,
|
||||
content: JSON.stringify({ compilerOptions: { incremental: true, outFile: "out.js" } }),
|
||||
content: jsonToReadableText({ compilerOptions: { incremental: true, outFile: "out.js" } }),
|
||||
}],
|
||||
subScenario: "with --out",
|
||||
});
|
||||
@@ -132,7 +135,7 @@ describe("unittests:: tsc-watch:: emit file --incremental", () => {
|
||||
};
|
||||
const config: File = {
|
||||
path: configFile.path,
|
||||
content: JSON.stringify({ compilerOptions: { incremental: true, module: "amd" } }),
|
||||
content: jsonToReadableText({ compilerOptions: { incremental: true, module: "amd" } }),
|
||||
};
|
||||
|
||||
verifyIncrementalWatchEmit({
|
||||
@@ -229,7 +232,7 @@ describe("unittests:: tsc-watch:: emit file --incremental", () => {
|
||||
verifyIncrementalWatchEmit({
|
||||
files: () => [libFile, file1, file2, {
|
||||
path: configFile.path,
|
||||
content: JSON.stringify({ compilerOptions: { incremental: true, module: "amd", outFile: "out.js" } }),
|
||||
content: jsonToReadableText({ compilerOptions: { incremental: true, module: "amd", outFile: "out.js" } }),
|
||||
}],
|
||||
subScenario: "module compilation/with --out",
|
||||
});
|
||||
@@ -239,7 +242,7 @@ describe("unittests:: tsc-watch:: emit file --incremental", () => {
|
||||
files: () => {
|
||||
const config: File = {
|
||||
path: configFile.path,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
incremental: true,
|
||||
target: "es5",
|
||||
@@ -301,7 +304,7 @@ export interface A {
|
||||
{ path: libFile.path, content: libContent },
|
||||
{ path: `${project}/globals.d.ts`, content: `declare namespace Config { const value: string;} ` },
|
||||
{ path: `${project}/index.ts`, content: `console.log(Config.value);` },
|
||||
{ path: configFile.path, content: JSON.stringify({ compilerOptions: { incremental: true } }) },
|
||||
{ path: configFile.path, content: jsonToReadableText({ compilerOptions: { incremental: true } }) },
|
||||
],
|
||||
modifyFs: host => host.deleteFile(`${project}/globals.d.ts`),
|
||||
});
|
||||
@@ -326,13 +329,13 @@ export const Fragment: unique symbol;
|
||||
files: () => [
|
||||
{ path: libFile.path, content: libContent },
|
||||
{ path: `${project}/node_modules/react/jsx-runtime/index.d.ts`, content: jsxLibraryContent },
|
||||
{ path: `${project}/node_modules/react/package.json`, content: JSON.stringify({ name: "react", version: "0.0.1" }) },
|
||||
{ path: `${project}/node_modules/react/package.json`, content: jsonToReadableText({ name: "react", version: "0.0.1" }) },
|
||||
{ path: `${project}/node_modules/preact/jsx-runtime/index.d.ts`, content: jsxLibraryContent.replace("propA", "propB") },
|
||||
{ path: `${project}/node_modules/preact/package.json`, content: JSON.stringify({ name: "preact", version: "0.0.1" }) },
|
||||
{ path: `${project}/node_modules/preact/package.json`, content: jsonToReadableText({ name: "preact", version: "0.0.1" }) },
|
||||
{ path: `${project}/index.tsx`, content: `export const App = () => <div propA={true}></div>;` },
|
||||
{ path: configFile.path, content: JSON.stringify({ compilerOptions: jsxImportSourceOptions }) },
|
||||
{ path: configFile.path, content: jsonToReadableText({ compilerOptions: jsxImportSourceOptions }) },
|
||||
],
|
||||
modifyFs: host => host.writeFile(configFile.path, JSON.stringify({ compilerOptions: { ...jsxImportSourceOptions, jsxImportSource: "preact" } })),
|
||||
modifyFs: host => host.writeFile(configFile.path, jsonToReadableText({ compilerOptions: { ...jsxImportSourceOptions, jsxImportSource: "preact" } })),
|
||||
optionsToExtend: ["--explainFiles"],
|
||||
});
|
||||
|
||||
@@ -341,14 +344,14 @@ export const Fragment: unique symbol;
|
||||
files: () => [
|
||||
{ path: libFile.path, content: libContent },
|
||||
{ path: `${project}/index.tsx`, content: `export const App = () => <div propA={true}></div>;` },
|
||||
{ path: configFile.path, content: JSON.stringify({ compilerOptions: jsxImportSourceOptions }) },
|
||||
{ path: configFile.path, content: jsonToReadableText({ compilerOptions: jsxImportSourceOptions }) },
|
||||
],
|
||||
modifyFs: host => {
|
||||
host.createDirectory(`${project}/node_modules`);
|
||||
host.createDirectory(`${project}/node_modules/react`);
|
||||
host.createDirectory(`${project}/node_modules/react/jsx-runtime`);
|
||||
host.writeFile(`${project}/node_modules/react/jsx-runtime/index.d.ts`, jsxLibraryContent);
|
||||
host.writeFile(`${project}/node_modules/react/package.json`, JSON.stringify({ name: "react", version: "0.0.1" }));
|
||||
host.writeFile(`${project}/node_modules/react/package.json`, jsonToReadableText({ name: "react", version: "0.0.1" }));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -357,9 +360,9 @@ export const Fragment: unique symbol;
|
||||
files: () => [
|
||||
{ path: libFile.path, content: libContent },
|
||||
{ path: `${project}/node_modules/react/jsx-runtime/index.d.ts`, content: jsxLibraryContent },
|
||||
{ path: `${project}/node_modules/react/package.json`, content: JSON.stringify({ name: "react", version: "0.0.1" }) },
|
||||
{ path: `${project}/node_modules/react/package.json`, content: jsonToReadableText({ name: "react", version: "0.0.1" }) },
|
||||
{ path: `${project}/index.tsx`, content: `export const App = () => <div propA={true}></div>;` },
|
||||
{ path: configFile.path, content: JSON.stringify({ compilerOptions: jsxImportSourceOptions }) },
|
||||
{ path: configFile.path, content: jsonToReadableText({ compilerOptions: jsxImportSourceOptions }) },
|
||||
],
|
||||
modifyFs: host => {
|
||||
host.deleteFile(`${project}/node_modules/react/jsx-runtime/index.d.ts`);
|
||||
@@ -372,9 +375,9 @@ export const Fragment: unique symbol;
|
||||
files: () => [
|
||||
{ path: libFile.path, content: libContent },
|
||||
{ path: `${project}/node_modules/tslib/index.d.ts`, content: "export function __assign(...args: any[]): any;" },
|
||||
{ path: `${project}/node_modules/tslib/package.json`, content: JSON.stringify({ name: "tslib", version: "0.0.1" }) },
|
||||
{ path: `${project}/node_modules/tslib/package.json`, content: jsonToReadableText({ name: "tslib", version: "0.0.1" }) },
|
||||
{ path: `${project}/index.tsx`, content: `export const x = {...{}};` },
|
||||
{ path: configFile.path, content: JSON.stringify({ compilerOptions: { importHelpers: true } }) },
|
||||
{ path: configFile.path, content: jsonToReadableText({ compilerOptions: { importHelpers: true } }) },
|
||||
],
|
||||
modifyFs: host => {
|
||||
host.deleteFile(`${project}/node_modules/tslib/index.d.ts`);
|
||||
@@ -391,7 +394,7 @@ export const Fragment: unique symbol;
|
||||
{ path: `${project}/node_modules/classnames/index.d.ts`, content: `export interface Result {} export default function classNames(): Result;` },
|
||||
{ path: `${project}/src/types/classnames.d.ts`, content: `export {}; declare module "classnames" { interface Result { foo } }` },
|
||||
{ path: `${project}/src/index.ts`, content: `import classNames from "classnames"; classNames().foo;` },
|
||||
{ path: configFile.path, content: JSON.stringify({ compilerOptions: { module: "commonjs", incremental: true } }) },
|
||||
{ path: configFile.path, content: jsonToReadableText({ compilerOptions: { module: "commonjs", incremental: true } }) },
|
||||
],
|
||||
modifyFs: host => {
|
||||
// delete 'foo'
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
getCommandLineArgsForLibResolution,
|
||||
getSysForLibResolution,
|
||||
@@ -20,7 +23,7 @@ describe("unittests:: tsc-watch:: libraryResolution", () => {
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
"/home/src/projects/project1/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
typeRoots: ["./typeroot1", "./typeroot2"],
|
||||
@@ -36,7 +39,7 @@ describe("unittests:: tsc-watch:: libraryResolution", () => {
|
||||
edit: sys => {
|
||||
sys.writeFile(
|
||||
"/home/src/projects/project1/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
typeRoots: ["./typeroot1"],
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as Utils from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
getFsConentsForNode10ResultAtTypesPackageJson,
|
||||
getFsContentsForNode10Result,
|
||||
@@ -22,7 +25,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
createWatchedSystem([
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg1/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg1",
|
||||
version: "1.0.0",
|
||||
main: "build/index.js",
|
||||
@@ -36,7 +39,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg1/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "build",
|
||||
},
|
||||
@@ -56,7 +59,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/packages/pkg2/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg2",
|
||||
version: "1.0.0",
|
||||
main: "build/index.js",
|
||||
@@ -96,7 +99,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
createWatchedSystem([
|
||||
{
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
moduleResolution: "nodenext",
|
||||
outDir: "./dist",
|
||||
@@ -107,7 +110,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "@this/package",
|
||||
type: "module",
|
||||
exports: {
|
||||
@@ -146,7 +149,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
function getSys(packageFileContents: string) {
|
||||
const configFile: File = {
|
||||
path: `/user/username/projects/myproject/src/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
target: "es2016",
|
||||
module: "Node16",
|
||||
@@ -181,14 +184,14 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
scenario: "moduleResolution",
|
||||
subScenario: "package json file is edited",
|
||||
commandLineArgs: ["--w", "--p", "src", "--extendedDiagnostics", "-traceResolution", "--explainFiles"],
|
||||
sys: () => getSys(JSON.stringify({ name: "app", version: "1.0.0" })),
|
||||
sys: () => getSys(jsonToReadableText({ name: "app", version: "1.0.0" })),
|
||||
edits: [
|
||||
{
|
||||
caption: "Modify package json file to add type module",
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
`/user/username/projects/myproject/package.json`,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
name: "app",
|
||||
version: "1.0.0",
|
||||
type: "module",
|
||||
@@ -201,7 +204,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
caption: "Modify package.json file to remove type module",
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/package.json`, JSON.stringify({ name: "app", version: "1.0.0" })),
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/package.json`, jsonToReadableText({ name: "app", version: "1.0.0" })),
|
||||
timeouts: host => {
|
||||
host.runQueuedTimeoutCallbacks(); // Failed lookup updates
|
||||
host.runQueuedTimeoutCallbacks(); // Actual update
|
||||
@@ -220,7 +223,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
`/user/username/projects/myproject/package.json`,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
name: "app",
|
||||
version: "1.0.0",
|
||||
type: "module",
|
||||
@@ -247,7 +250,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
subScenario: "package json file is edited when package json with type module exists",
|
||||
commandLineArgs: ["--w", "--p", "src", "--extendedDiagnostics", "-traceResolution", "--explainFiles"],
|
||||
sys: () =>
|
||||
getSys(JSON.stringify({
|
||||
getSys(jsonToReadableText({
|
||||
name: "app",
|
||||
version: "1.0.0",
|
||||
type: "module",
|
||||
@@ -255,7 +258,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
edits: [
|
||||
{
|
||||
caption: "Modify package.json file to remove type module",
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/package.json`, JSON.stringify({ name: "app", version: "1.0.0" })),
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/package.json`, jsonToReadableText({ name: "app", version: "1.0.0" })),
|
||||
timeouts: host => {
|
||||
host.runQueuedTimeoutCallbacks(); // Failed lookup updates
|
||||
host.runQueuedTimeoutCallbacks(); // Actual update
|
||||
@@ -266,7 +269,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
`/user/username/projects/myproject/package.json`,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
name: "app",
|
||||
version: "1.0.0",
|
||||
type: "module",
|
||||
@@ -287,7 +290,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
caption: "Modify package json file to without type module",
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/package.json`, JSON.stringify({ name: "app", version: "1.0.0" })),
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/package.json`, jsonToReadableText({ name: "app", version: "1.0.0" })),
|
||||
timeouts: host => {
|
||||
host.runQueuedTimeoutCallbacks(); // Failed lookup updates
|
||||
host.runQueuedTimeoutCallbacks(); // Actual update
|
||||
@@ -312,7 +315,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
createWatchedSystem([
|
||||
{
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { moduleResolution: "node16" },
|
||||
}),
|
||||
},
|
||||
@@ -332,7 +335,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/node_modules/pkg/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg",
|
||||
version: "0.0.1",
|
||||
exports: {
|
||||
@@ -351,7 +354,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/node_modules/pkg1/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg1",
|
||||
version: "0.0.1",
|
||||
exports: {
|
||||
@@ -383,7 +386,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
createWatchedSystem([
|
||||
{
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { moduleResolution: "node16" },
|
||||
}),
|
||||
},
|
||||
@@ -403,7 +406,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/node_modules/pkg/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg",
|
||||
version: "0.0.1",
|
||||
exports: {
|
||||
@@ -422,7 +425,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/node_modules/pkg1/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg1",
|
||||
version: "0.0.1",
|
||||
exports: {
|
||||
@@ -454,7 +457,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
createWatchedSystem([
|
||||
{
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { moduleResolution: "node16" },
|
||||
}),
|
||||
},
|
||||
@@ -474,7 +477,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/node_modules/pkg/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg",
|
||||
version: "0.0.1",
|
||||
exports: {
|
||||
@@ -503,7 +506,7 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
|
||||
},
|
||||
{
|
||||
path: `/user/username/projects/myproject/node_modules/pkg1/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "pkg1",
|
||||
version: "0.0.1",
|
||||
exports: {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as Utils from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTscWatch,
|
||||
} from "../helpers/tscWatch";
|
||||
@@ -16,7 +19,7 @@ describe("unittests:: tsc-watch:: nodeNextWatch:: emit when module emit is speci
|
||||
sys: () => {
|
||||
const configFile: File = {
|
||||
path: "/project/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: true,
|
||||
target: "es2020",
|
||||
@@ -28,7 +31,7 @@ describe("unittests:: tsc-watch:: nodeNextWatch:: emit when module emit is speci
|
||||
};
|
||||
const packageFile: File = {
|
||||
path: "/project/package.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "some-proj",
|
||||
version: "1.0.0",
|
||||
description: "",
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
commandLineCallbacks,
|
||||
} from "../helpers/baseline";
|
||||
@@ -64,7 +67,7 @@ describe("unittests:: tsc-watch:: program updates", () => {
|
||||
};
|
||||
const config = {
|
||||
path: configFilePath,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
include: ["app.ts"],
|
||||
}),
|
||||
};
|
||||
@@ -259,7 +262,7 @@ describe("unittests:: tsc-watch:: program updates", () => {
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: "/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { allowUnusedLabels: true },
|
||||
}),
|
||||
};
|
||||
@@ -271,7 +274,7 @@ describe("unittests:: tsc-watch:: program updates", () => {
|
||||
edit: sys =>
|
||||
sys.modifyFile(
|
||||
"/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { allowUnusedLabels: false },
|
||||
}),
|
||||
),
|
||||
@@ -282,7 +285,7 @@ describe("unittests:: tsc-watch:: program updates", () => {
|
||||
edit: sys =>
|
||||
sys.modifyFile(
|
||||
"/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { allowUnusedLabels: true },
|
||||
}),
|
||||
),
|
||||
@@ -306,7 +309,7 @@ describe("unittests:: tsc-watch:: program updates", () => {
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: "/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { allowArbitraryExtensions: true },
|
||||
files: ["/a.ts"],
|
||||
}),
|
||||
@@ -319,7 +322,7 @@ describe("unittests:: tsc-watch:: program updates", () => {
|
||||
edit: sys =>
|
||||
sys.modifyFile(
|
||||
"/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { allowArbitraryExtensions: false },
|
||||
files: ["/a.ts"],
|
||||
}),
|
||||
@@ -331,7 +334,7 @@ describe("unittests:: tsc-watch:: program updates", () => {
|
||||
edit: sys =>
|
||||
sys.modifyFile(
|
||||
"/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { allowArbitraryExtensions: true },
|
||||
files: ["/a.ts"],
|
||||
}),
|
||||
@@ -360,7 +363,7 @@ export class A {
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: "/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { target: "es6", importsNotUsedAsValues: "error" },
|
||||
}),
|
||||
};
|
||||
@@ -372,7 +375,7 @@ export class A {
|
||||
edit: sys =>
|
||||
sys.modifyFile(
|
||||
"/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { target: "es6", importsNotUsedAsValues: "error", experimentalDecorators: true },
|
||||
}),
|
||||
),
|
||||
@@ -383,7 +386,7 @@ export class A {
|
||||
edit: sys =>
|
||||
sys.modifyFile(
|
||||
"/tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { target: "es6", importsNotUsedAsValues: "error", experimentalDecorators: true, emitDecoratorMetadata: true },
|
||||
}),
|
||||
),
|
||||
@@ -581,7 +584,7 @@ export class A {
|
||||
};
|
||||
const configFile = {
|
||||
path: "/a/c/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: {}, files: ["f2.ts", "f3.ts"] }),
|
||||
content: jsonToReadableText({ compilerOptions: {}, files: ["f2.ts", "f3.ts"] }),
|
||||
};
|
||||
return createWatchedSystem([file1, file2, file3, libFile, configFile]);
|
||||
},
|
||||
@@ -602,7 +605,7 @@ export class A {
|
||||
caption: "change `module` to 'none'",
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
edit: sys => {
|
||||
sys.writeFile(configFilePath, JSON.stringify({ compilerOptions: { module: "none" } }));
|
||||
sys.writeFile(configFilePath, jsonToReadableText({ compilerOptions: { module: "none" } }));
|
||||
},
|
||||
}],
|
||||
});
|
||||
@@ -699,14 +702,14 @@ export class A {
|
||||
};
|
||||
const configFile = {
|
||||
path: configFilePath,
|
||||
content: JSON.stringify({ compilerOptions: {}, files: ["f1.ts"] }),
|
||||
content: jsonToReadableText({ compilerOptions: {}, files: ["f1.ts"] }),
|
||||
};
|
||||
return createWatchedSystem([file1, file2, libFile, configFile]);
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
caption: "Modify config to make f2 as root too",
|
||||
edit: sys => sys.writeFile(configFilePath, JSON.stringify({ compilerOptions: {}, files: ["f1.ts", "f2.ts"] })),
|
||||
edit: sys => sys.writeFile(configFilePath, jsonToReadableText({ compilerOptions: {}, files: ["f1.ts", "f2.ts"] })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
@@ -727,7 +730,7 @@ export class A {
|
||||
};
|
||||
const configFile = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { composite: true }, include: ["./", "./**/*.json"] }),
|
||||
content: jsonToReadableText({ compilerOptions: { composite: true }, include: ["./", "./**/*.json"] }),
|
||||
};
|
||||
return createWatchedSystem([file1, file2, libFile, configFile], { currentDirectory: "/user/username/projects/myproject" });
|
||||
},
|
||||
@@ -756,7 +759,7 @@ export class A {
|
||||
};
|
||||
const configFile = {
|
||||
path: `/user/username/projects/myproject/Project/tsconfig.json`,
|
||||
content: JSON.stringify({ include: [".", "./**/*.json"] }),
|
||||
content: jsonToReadableText({ include: [".", "./**/*.json"] }),
|
||||
};
|
||||
return createWatchedSystem([file1, libFile, configFile], { currentDirectory: `/user/username/projects/myproject/Project` });
|
||||
},
|
||||
@@ -784,14 +787,14 @@ export class A {
|
||||
};
|
||||
const configFile = {
|
||||
path: configFilePath,
|
||||
content: JSON.stringify({ compilerOptions: {}, files: ["f1.ts", "f2.ts"] }),
|
||||
content: jsonToReadableText({ compilerOptions: {}, files: ["f1.ts", "f2.ts"] }),
|
||||
};
|
||||
return createWatchedSystem([file1, file2, libFile, configFile]);
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
caption: "Modify config to set outFile option",
|
||||
edit: sys => sys.writeFile(configFilePath, JSON.stringify({ compilerOptions: { outFile: "out.js" }, files: ["f1.ts", "f2.ts"] })),
|
||||
edit: sys => sys.writeFile(configFilePath, jsonToReadableText({ compilerOptions: { outFile: "out.js" }, files: ["f1.ts", "f2.ts"] })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
@@ -812,7 +815,7 @@ export class A {
|
||||
};
|
||||
const configFile = {
|
||||
path: configFilePath,
|
||||
content: JSON.stringify({ compilerOptions: {}, files: ["f1.ts", "f2.ts"] }),
|
||||
content: jsonToReadableText({ compilerOptions: {}, files: ["f1.ts", "f2.ts"] }),
|
||||
};
|
||||
return createWatchedSystem([file1, file2, libFile, configFile]);
|
||||
},
|
||||
@@ -886,7 +889,7 @@ declare const eval: any`,
|
||||
};
|
||||
const config1 = {
|
||||
path: "/src/tsconfig.json",
|
||||
content: JSON.stringify(
|
||||
content: jsonToReadableText(
|
||||
{
|
||||
compilerOptions: {
|
||||
module: "commonjs",
|
||||
@@ -908,7 +911,7 @@ declare const eval: any`,
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
"/src/tsconfig.json",
|
||||
JSON.stringify(
|
||||
jsonToReadableText(
|
||||
{
|
||||
compilerOptions: {
|
||||
module: "commonjs",
|
||||
@@ -939,7 +942,7 @@ declare const eval: any`,
|
||||
};
|
||||
const config = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {},
|
||||
include: [
|
||||
"src/**/*",
|
||||
@@ -1031,7 +1034,7 @@ declare const eval: any`,
|
||||
};
|
||||
const config = {
|
||||
path: configFilePath,
|
||||
content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: includeTypeRoots ? [] : undefined } }),
|
||||
content: jsonToReadableText({ compilerOptions: { types: ["node"], typeRoots: includeTypeRoots ? [] : undefined } }),
|
||||
};
|
||||
const node = {
|
||||
path: "/a/b/node_modules/@types/node/index.d.ts",
|
||||
@@ -1180,7 +1183,7 @@ declare const eval: any`,
|
||||
};
|
||||
const config = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compiler: {},
|
||||
files: [],
|
||||
}),
|
||||
@@ -1281,7 +1284,7 @@ declare const eval: any`,
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: compilerOptionsToConfigJson(options),
|
||||
}),
|
||||
};
|
||||
@@ -1416,7 +1419,7 @@ export default test;`,
|
||||
};
|
||||
const tsconfigFile: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "commonjs",
|
||||
noEmit: true,
|
||||
@@ -1446,24 +1449,24 @@ foo().hello`,
|
||||
};
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: {} }),
|
||||
content: jsonToReadableText({ compilerOptions: {} }),
|
||||
};
|
||||
return createWatchedSystem([aFile, config, libFile], { currentDirectory: "/user/username/projects/myproject" });
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
caption: "Enable strict null checks",
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, JSON.stringify({ compilerOptions: { strictNullChecks: true } })),
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, jsonToReadableText({ compilerOptions: { strictNullChecks: true } })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Set always strict false",
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, JSON.stringify({ compilerOptions: { strict: true, alwaysStrict: false } })), // Avoid changing 'alwaysStrict' or must re-bind
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, jsonToReadableText({ compilerOptions: { strict: true, alwaysStrict: false } })), // Avoid changing 'alwaysStrict' or must re-bind
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Disable strict",
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, JSON.stringify({ compilerOptions: {} })),
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, jsonToReadableText({ compilerOptions: {} })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
@@ -1489,14 +1492,14 @@ v === 'foo';`,
|
||||
};
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: {} }),
|
||||
content: jsonToReadableText({ compilerOptions: {} }),
|
||||
};
|
||||
return createWatchedSystem([aFile, config, libFile], { currentDirectory: "/user/username/projects/myproject" });
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
caption: "Enable noErrorTruncation",
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, JSON.stringify({ compilerOptions: { noErrorTruncation: true } })),
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, jsonToReadableText({ compilerOptions: { noErrorTruncation: true } })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
@@ -1514,14 +1517,14 @@ class D extends C { prop = 1; }`,
|
||||
};
|
||||
const config: File = {
|
||||
path: `/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { target: "es6" } }),
|
||||
content: jsonToReadableText({ compilerOptions: { target: "es6" } }),
|
||||
};
|
||||
return createWatchedSystem([aFile, config, libFile]);
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
caption: "Enable useDefineForClassFields",
|
||||
edit: sys => sys.writeFile(`/tsconfig.json`, JSON.stringify({ compilerOptions: { target: "es6", useDefineForClassFields: true } })),
|
||||
edit: sys => sys.writeFile(`/tsconfig.json`, jsonToReadableText({ compilerOptions: { target: "es6", useDefineForClassFields: true } })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
@@ -1543,24 +1546,24 @@ export function f(p: C) { return p; }`,
|
||||
};
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: {} }),
|
||||
content: jsonToReadableText({ compilerOptions: {} }),
|
||||
};
|
||||
return createWatchedSystem([aFile, bFile, config, libFile], { currentDirectory: "/user/username/projects/myproject" });
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
caption: 'Set to "remove"',
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "remove" } })),
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, jsonToReadableText({ compilerOptions: { importsNotUsedAsValues: "remove" } })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: 'Set to "error"',
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "error" } })),
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, jsonToReadableText({ compilerOptions: { importsNotUsedAsValues: "error" } })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: 'Set to "preserve"',
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "preserve" } })),
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, jsonToReadableText({ compilerOptions: { importsNotUsedAsValues: "preserve" } })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
@@ -1581,14 +1584,14 @@ export function f(p: C) { return p; }`,
|
||||
};
|
||||
const config: File = {
|
||||
path: `/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { forceConsistentCasingInFileNames: false } }),
|
||||
content: jsonToReadableText({ compilerOptions: { forceConsistentCasingInFileNames: false } }),
|
||||
};
|
||||
return createWatchedSystem([aFile, bFile, config, libFile], { useCaseSensitiveFileNames: false });
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
caption: "Enable forceConsistentCasingInFileNames",
|
||||
edit: sys => sys.writeFile(`/tsconfig.json`, JSON.stringify({ compilerOptions: { forceConsistentCasingInFileNames: true } })),
|
||||
edit: sys => sys.writeFile(`/tsconfig.json`, jsonToReadableText({ compilerOptions: { forceConsistentCasingInFileNames: true } })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
@@ -1609,14 +1612,14 @@ export function f(p: C) { return p; }`,
|
||||
};
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { moduleResolution: "node" } }),
|
||||
content: jsonToReadableText({ compilerOptions: { moduleResolution: "node" } }),
|
||||
};
|
||||
return createWatchedSystem([aFile, jsonFile, config, libFile], { currentDirectory: "/user/username/projects/myproject" });
|
||||
},
|
||||
edits: [
|
||||
{
|
||||
caption: "Enable resolveJsonModule",
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, JSON.stringify({ compilerOptions: { moduleResolution: "node", resolveJsonModule: true } })),
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, jsonToReadableText({ compilerOptions: { moduleResolution: "node", resolveJsonModule: true } })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
@@ -1724,7 +1727,7 @@ var y: number;
|
||||
});
|
||||
|
||||
function changeWhenLibCheckChanges(compilerOptions: ts.CompilerOptions): TscWatchCompileChange {
|
||||
const configFileContent = JSON.stringify({ compilerOptions });
|
||||
const configFileContent = jsonToReadableText({ compilerOptions });
|
||||
return {
|
||||
caption: `Changing config to ${configFileContent}`,
|
||||
edit: sys => sys.writeFile(`/user/username/projects/myproject/tsconfig.json`, configFileContent),
|
||||
@@ -1789,7 +1792,7 @@ const b: string = a;`,
|
||||
};
|
||||
const configFile: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
isolatedModules: true,
|
||||
},
|
||||
@@ -1821,7 +1824,7 @@ const b: string = a;`,
|
||||
};
|
||||
const configFile: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
rootDir: ".",
|
||||
outDir: "lib",
|
||||
@@ -1856,7 +1859,7 @@ import { x } from "../b";`,
|
||||
};
|
||||
const configFile: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
jsx: "preserve",
|
||||
},
|
||||
@@ -1884,7 +1887,7 @@ import { x } from "../b";`,
|
||||
};
|
||||
const configFile: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {},
|
||||
}),
|
||||
};
|
||||
@@ -1906,7 +1909,7 @@ import { x } from "../b";`,
|
||||
sys: () => {
|
||||
const firstExtendedConfigFile: File = {
|
||||
path: "/a/b/first.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: true,
|
||||
},
|
||||
@@ -1914,13 +1917,13 @@ import { x } from "../b";`,
|
||||
};
|
||||
const secondExtendedConfigFile: File = {
|
||||
path: "/a/b/second.tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
extends: "./first.tsconfig.json",
|
||||
}),
|
||||
};
|
||||
const configFile: File = {
|
||||
path: configFilePath,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {},
|
||||
files: [commonFile1.path, commonFile2.path],
|
||||
}),
|
||||
@@ -1940,7 +1943,7 @@ import { x } from "../b";`,
|
||||
edit: sys =>
|
||||
sys.modifyFile(
|
||||
configFilePath,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
extends: "./second.tsconfig.json",
|
||||
compilerOptions: {},
|
||||
files: [commonFile1.path, commonFile2.path],
|
||||
@@ -1953,7 +1956,7 @@ import { x } from "../b";`,
|
||||
edit: sys =>
|
||||
sys.modifyFile(
|
||||
"/a/b/first.tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: false,
|
||||
},
|
||||
@@ -1966,7 +1969,7 @@ import { x } from "../b";`,
|
||||
edit: sys =>
|
||||
sys.modifyFile(
|
||||
"/a/b/second.tsconfig.json",
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
extends: "./first.tsconfig.json",
|
||||
compilerOptions: {
|
||||
strictNullChecks: true,
|
||||
@@ -1980,7 +1983,7 @@ import { x } from "../b";`,
|
||||
edit: sys =>
|
||||
sys.modifyFile(
|
||||
configFilePath,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: {},
|
||||
files: [commonFile1.path, commonFile2.path],
|
||||
}),
|
||||
@@ -2009,7 +2012,7 @@ import { x } from "../b";`,
|
||||
};
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
baseUrl: "client",
|
||||
paths: { "*": ["*"] },
|
||||
@@ -2035,7 +2038,7 @@ import { x } from "../b";`,
|
||||
sys: () => {
|
||||
const config1: File = {
|
||||
path: `/user/username/projects/myproject/projects/project1/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "none",
|
||||
composite: true,
|
||||
@@ -2054,7 +2057,7 @@ import { x } from "../b";`,
|
||||
};
|
||||
const config2: File = {
|
||||
path: `/user/username/projects/myproject/projects/project2/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "none",
|
||||
composite: true,
|
||||
@@ -2138,7 +2141,7 @@ import { x } from "../b";`,
|
||||
};
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
noEmit: true,
|
||||
allowImportingTsExtensions: false,
|
||||
@@ -2153,7 +2156,7 @@ import { x } from "../b";`,
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
`/user/username/projects/myproject/tsconfig.json`,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
noEmit: true,
|
||||
allowImportingTsExtensions: true,
|
||||
@@ -2180,7 +2183,7 @@ import { x } from "../b";`,
|
||||
};
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
checkJs: false,
|
||||
},
|
||||
@@ -2194,7 +2197,7 @@ import { x } from "../b";`,
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
`/user/username/projects/myproject/tsconfig.json`,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
checkJs: true,
|
||||
},
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
getSysForSampleProjectReferences,
|
||||
} from "../helpers/sampleProjectReferences";
|
||||
import {
|
||||
createSolutionBuilder,
|
||||
createSystemWithSolutionBuild,
|
||||
solutionBuildWithBaseline,
|
||||
} from "../helpers/solutionBuilder";
|
||||
import {
|
||||
getFsContentsForTransitiveReferences,
|
||||
getFsContentsForTransitiveReferencesAConfig,
|
||||
getFsContentsForTransitiveReferencesBConfig,
|
||||
getFsContentsForTransitiveReferencesRefsAdts,
|
||||
} from "../helpers/transitiveReferences";
|
||||
import {
|
||||
verifyTscWatch,
|
||||
} from "../helpers/tscWatch";
|
||||
import {
|
||||
getTsBuildProjectFile,
|
||||
getTsBuildProjectFilePath,
|
||||
createWatchedSystem,
|
||||
libFile,
|
||||
TestServerHost,
|
||||
} from "../helpers/virtualFileSystemWithWatch";
|
||||
@@ -17,27 +28,16 @@ describe("unittests:: tsc-watch:: projects with references: invoking when refere
|
||||
scenario: "projectsWithReferences",
|
||||
subScenario: "on sample project",
|
||||
sys: () =>
|
||||
createSystemWithSolutionBuild(
|
||||
solutionBuildWithBaseline(
|
||||
getSysForSampleProjectReferences(),
|
||||
["tests"],
|
||||
[
|
||||
libFile,
|
||||
getTsBuildProjectFile("sample1", "core/tsconfig.json"),
|
||||
getTsBuildProjectFile("sample1", "core/index.ts"),
|
||||
getTsBuildProjectFile("sample1", "core/anotherModule.ts"),
|
||||
getTsBuildProjectFile("sample1", "core/some_decl.d.ts"),
|
||||
getTsBuildProjectFile("sample1", "logic/tsconfig.json"),
|
||||
getTsBuildProjectFile("sample1", "logic/index.ts"),
|
||||
getTsBuildProjectFile("sample1", "tests/tsconfig.json"),
|
||||
getTsBuildProjectFile("sample1", "tests/index.ts"),
|
||||
],
|
||||
{ currentDirectory: `/user/username/projects/sample1` },
|
||||
),
|
||||
commandLineArgs: ["-w", "-p", "tests", "--traceResolution", "--explainFiles"],
|
||||
edits: [
|
||||
{
|
||||
caption: "local edit in logic ts, and build logic",
|
||||
edit: sys => {
|
||||
sys.appendFile(getTsBuildProjectFilePath("sample1", "logic/index.ts"), `function foo() { }`);
|
||||
sys.appendFile("/user/username/projects/sample1/logic/index.ts", `function foo() { }`);
|
||||
const solutionBuilder = createSolutionBuilder(sys, ["logic"]);
|
||||
solutionBuilder.build();
|
||||
},
|
||||
@@ -48,7 +48,7 @@ describe("unittests:: tsc-watch:: projects with references: invoking when refere
|
||||
{
|
||||
caption: "non local edit in logic ts, and build logic",
|
||||
edit: sys => {
|
||||
sys.appendFile(getTsBuildProjectFilePath("sample1", "logic/index.ts"), `export function gfoo() { }`);
|
||||
sys.appendFile("/user/username/projects/sample1/logic/index.ts", `export function gfoo() { }`);
|
||||
const solutionBuilder = createSolutionBuilder(sys, ["logic"]);
|
||||
solutionBuilder.build();
|
||||
},
|
||||
@@ -58,8 +58,8 @@ describe("unittests:: tsc-watch:: projects with references: invoking when refere
|
||||
caption: "change in project reference config file builds correctly",
|
||||
edit: sys => {
|
||||
sys.writeFile(
|
||||
getTsBuildProjectFilePath("sample1", "logic/tsconfig.json"),
|
||||
JSON.stringify({
|
||||
"/user/username/projects/sample1/logic/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true, declaration: true, declarationDir: "decls" },
|
||||
references: [{ path: "../core" }],
|
||||
}),
|
||||
@@ -76,33 +76,26 @@ describe("unittests:: tsc-watch:: projects with references: invoking when refere
|
||||
function changeCompilerOpitonsPaths(sys: TestServerHost, config: string, newPaths: object) {
|
||||
const configJson = JSON.parse(sys.readFile(config)!);
|
||||
configJson.compilerOptions.paths = newPaths;
|
||||
sys.writeFile(config, JSON.stringify(configJson));
|
||||
sys.writeFile(config, jsonToReadableText(configJson));
|
||||
}
|
||||
|
||||
verifyTscWatch({
|
||||
scenario: "projectsWithReferences",
|
||||
subScenario: "on transitive references",
|
||||
sys: () =>
|
||||
createSystemWithSolutionBuild(
|
||||
solutionBuildWithBaseline(
|
||||
createWatchedSystem(
|
||||
getFsContentsForTransitiveReferences(),
|
||||
{ currentDirectory: `/user/username/projects/transitiveReferences` },
|
||||
),
|
||||
["tsconfig.c.json"],
|
||||
[
|
||||
libFile,
|
||||
getTsBuildProjectFile("transitiveReferences", "tsconfig.a.json"),
|
||||
getTsBuildProjectFile("transitiveReferences", "tsconfig.b.json"),
|
||||
getTsBuildProjectFile("transitiveReferences", "tsconfig.c.json"),
|
||||
getTsBuildProjectFile("transitiveReferences", "a.ts"),
|
||||
getTsBuildProjectFile("transitiveReferences", "b.ts"),
|
||||
getTsBuildProjectFile("transitiveReferences", "c.ts"),
|
||||
getTsBuildProjectFile("transitiveReferences", "refs/a.d.ts"),
|
||||
],
|
||||
{ currentDirectory: `/user/username/projects/transitiveReferences` },
|
||||
),
|
||||
commandLineArgs: ["-w", "-p", "tsconfig.c.json", "--traceResolution", "--explainFiles"],
|
||||
edits: [
|
||||
{
|
||||
caption: "non local edit b ts, and build b",
|
||||
edit: sys => {
|
||||
sys.appendFile(getTsBuildProjectFilePath("transitiveReferences", "b.ts"), `export function gfoo() { }`);
|
||||
sys.appendFile("b.ts", `export function gfoo() { }`);
|
||||
const solutionBuilder = createSolutionBuilder(sys, ["tsconfig.b.json"]);
|
||||
solutionBuilder.build();
|
||||
},
|
||||
@@ -112,46 +105,46 @@ describe("unittests:: tsc-watch:: projects with references: invoking when refere
|
||||
caption: "edit on config file",
|
||||
edit: sys => {
|
||||
sys.ensureFileOrFolder({
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "nrefs/a.d.ts"),
|
||||
content: sys.readFile(getTsBuildProjectFilePath("transitiveReferences", "refs/a.d.ts"))!,
|
||||
path: "/user/username/projects/transitiveReferences/nrefs/a.d.ts",
|
||||
content: sys.readFile("/user/username/projects/transitiveReferences/refs/a.d.ts")!,
|
||||
});
|
||||
changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "tsconfig.c.json"), { "@ref/*": ["./nrefs/*"] });
|
||||
changeCompilerOpitonsPaths(sys, "tsconfig.c.json", { "@ref/*": ["./nrefs/*"] });
|
||||
},
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert config file edit",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "tsconfig.c.json"), { "@ref/*": ["./refs/*"] }),
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "tsconfig.c.json", { "@ref/*": ["./refs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "edit in referenced config file",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "tsconfig.b.json"), { "@ref/*": ["./nrefs/*"] }),
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "tsconfig.b.json", { "@ref/*": ["./nrefs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert referenced config file edit",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "tsconfig.b.json"), { "@ref/*": ["./refs/*"] }),
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "tsconfig.b.json", { "@ref/*": ["./refs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "deleting referenced config file",
|
||||
edit: sys => sys.deleteFile(getTsBuildProjectFilePath("transitiveReferences", "tsconfig.b.json")),
|
||||
edit: sys => sys.deleteFile("tsconfig.b.json"),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert deleting referenced config file",
|
||||
edit: sys => sys.ensureFileOrFolder(getTsBuildProjectFile("transitiveReferences", "tsconfig.b.json")),
|
||||
edit: sys => sys.writeFile("tsconfig.b.json", getFsContentsForTransitiveReferencesBConfig()),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "deleting transitively referenced config file",
|
||||
edit: sys => sys.deleteFile(getTsBuildProjectFilePath("transitiveReferences", "tsconfig.a.json")),
|
||||
edit: sys => sys.deleteFile("tsconfig.a.json"),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert deleting transitively referenced config file",
|
||||
edit: sys => sys.ensureFileOrFolder(getTsBuildProjectFile("transitiveReferences", "tsconfig.a.json")),
|
||||
edit: sys => sys.writeFile("tsconfig.a.json", getFsContentsForTransitiveReferencesAConfig()),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
@@ -162,29 +155,20 @@ describe("unittests:: tsc-watch:: projects with references: invoking when refere
|
||||
scenario: "projectsWithReferences",
|
||||
subScenario: "when referenced project uses different module resolution",
|
||||
sys: () =>
|
||||
createSystemWithSolutionBuild(
|
||||
["tsconfig.c.json"],
|
||||
[
|
||||
libFile,
|
||||
getTsBuildProjectFile("transitiveReferences", "tsconfig.a.json"),
|
||||
solutionBuildWithBaseline(
|
||||
createWatchedSystem(
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "tsconfig.b.json"),
|
||||
content: JSON.stringify({
|
||||
...getFsContentsForTransitiveReferences(),
|
||||
"/user/username/projects/transitiveReferences/tsconfig.b.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, moduleResolution: "classic" },
|
||||
files: ["b.ts"],
|
||||
references: [{ path: "tsconfig.a.json" }],
|
||||
}),
|
||||
"/user/username/projects/transitiveReferences/b.ts": `import {A} from "a";export const b = new A();`,
|
||||
},
|
||||
getTsBuildProjectFile("transitiveReferences", "tsconfig.c.json"),
|
||||
getTsBuildProjectFile("transitiveReferences", "a.ts"),
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "b.ts"),
|
||||
content: `import {A} from "a";export const b = new A();`,
|
||||
},
|
||||
getTsBuildProjectFile("transitiveReferences", "c.ts"),
|
||||
getTsBuildProjectFile("transitiveReferences", "refs/a.d.ts"),
|
||||
],
|
||||
{ currentDirectory: `/user/username/projects/transitiveReferences` },
|
||||
{ currentDirectory: `/user/username/projects/transitiveReferences` },
|
||||
),
|
||||
["tsconfig.c.json"],
|
||||
),
|
||||
commandLineArgs: ["-w", "-p", "tsconfig.c.json", "--traceResolution", "--explainFiles"],
|
||||
baselineDependencies: true,
|
||||
@@ -194,59 +178,43 @@ describe("unittests:: tsc-watch:: projects with references: invoking when refere
|
||||
scenario: "projectsWithReferences",
|
||||
subScenario: "on transitive references in different folders",
|
||||
sys: () =>
|
||||
createSystemWithSolutionBuild(
|
||||
["c"],
|
||||
[
|
||||
libFile,
|
||||
solutionBuildWithBaseline(
|
||||
createWatchedSystem(
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "a/tsconfig.json"),
|
||||
content: JSON.stringify({
|
||||
[libFile.path]: libFile.content,
|
||||
"/user/username/projects/transitiveReferences/a/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
files: ["index.ts"],
|
||||
}),
|
||||
},
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "b/tsconfig.json"),
|
||||
content: JSON.stringify({
|
||||
"/user/username/projects/transitiveReferences/b/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, baseUrl: "./", paths: { "@ref/*": ["../*"] } },
|
||||
files: ["index.ts"],
|
||||
references: [{ path: `../a` }],
|
||||
}),
|
||||
},
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "c/tsconfig.json"),
|
||||
content: JSON.stringify({
|
||||
"/user/username/projects/transitiveReferences/c/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { baseUrl: "./", paths: { "@ref/*": ["../refs/*"] } },
|
||||
files: ["index.ts"],
|
||||
references: [{ path: `../b` }],
|
||||
}),
|
||||
},
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "a/index.ts"),
|
||||
content: `export class A {}`,
|
||||
},
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "b/index.ts"),
|
||||
content: `import {A} from '@ref/a';
|
||||
"/user/username/projects/transitiveReferences/a/index.ts": `export class A {}`,
|
||||
"/user/username/projects/transitiveReferences/b/index.ts": `import {A} from '@ref/a';
|
||||
export const b = new A();`,
|
||||
},
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "c/index.ts"),
|
||||
content: `import {b} from '../b';
|
||||
"/user/username/projects/transitiveReferences/c/index.ts": `import {b} from '../b';
|
||||
import {X} from "@ref/a";
|
||||
b;
|
||||
X;`,
|
||||
"/user/username/projects/transitiveReferences/refs/a.d.ts": getFsContentsForTransitiveReferencesRefsAdts(),
|
||||
},
|
||||
getTsBuildProjectFile("transitiveReferences", "refs/a.d.ts"),
|
||||
],
|
||||
{ currentDirectory: `/user/username/projects/transitiveReferences` },
|
||||
{ currentDirectory: `/user/username/projects/transitiveReferences` },
|
||||
),
|
||||
["c"],
|
||||
),
|
||||
commandLineArgs: ["-w", "-p", "c", "--traceResolution", "--explainFiles"],
|
||||
edits: [
|
||||
{
|
||||
caption: "non local edit b ts, and build b",
|
||||
edit: sys => {
|
||||
sys.appendFile(getTsBuildProjectFilePath("transitiveReferences", "b/index.ts"), `export function gfoo() { }`);
|
||||
sys.appendFile("b/index.ts", `export function gfoo() { }`);
|
||||
const solutionBuilder = createSolutionBuilder(sys, ["b"]);
|
||||
solutionBuilder.build();
|
||||
},
|
||||
@@ -256,39 +224,39 @@ X;`,
|
||||
caption: "edit on config file",
|
||||
edit: sys => {
|
||||
sys.ensureFileOrFolder({
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "nrefs/a.d.ts"),
|
||||
content: sys.readFile(getTsBuildProjectFilePath("transitiveReferences", "refs/a.d.ts"))!,
|
||||
path: "/user/username/projects/transitiveReferences/nrefs/a.d.ts",
|
||||
content: sys.readFile("/user/username/projects/transitiveReferences/refs/a.d.ts")!,
|
||||
});
|
||||
changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "c/tsconfig.json"), { "@ref/*": ["../nrefs/*"] });
|
||||
changeCompilerOpitonsPaths(sys, "c/tsconfig.json", { "@ref/*": ["../nrefs/*"] });
|
||||
},
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert config file edit",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "c/tsconfig.json"), { "@ref/*": ["../refs/*"] }),
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "c/tsconfig.json", { "@ref/*": ["../refs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "edit in referenced config file",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "b/tsconfig.json"), { "@ref/*": ["../nrefs/*"] }),
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "b/tsconfig.json", { "@ref/*": ["../nrefs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert referenced config file edit",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "b/tsconfig.json"), { "@ref/*": ["../refs/*"] }),
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "b/tsconfig.json", { "@ref/*": ["../refs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "deleting referenced config file",
|
||||
edit: sys => sys.deleteFile(getTsBuildProjectFilePath("transitiveReferences", "b/tsconfig.json")),
|
||||
edit: sys => sys.deleteFile("b/tsconfig.json"),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert deleting referenced config file",
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
getTsBuildProjectFilePath("transitiveReferences", "b/tsconfig.json"),
|
||||
JSON.stringify({
|
||||
"b/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true, baseUrl: "./", paths: { "@ref/*": ["../*"] } },
|
||||
files: ["index.ts"],
|
||||
references: [{ path: `../a` }],
|
||||
@@ -298,15 +266,15 @@ X;`,
|
||||
},
|
||||
{
|
||||
caption: "deleting transitively referenced config file",
|
||||
edit: sys => sys.deleteFile(getTsBuildProjectFilePath("transitiveReferences", "a/tsconfig.json")),
|
||||
edit: sys => sys.deleteFile("a/tsconfig.json"),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert deleting transitively referenced config file",
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
getTsBuildProjectFilePath("transitiveReferences", "a/tsconfig.json"),
|
||||
JSON.stringify({
|
||||
"a/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
files: ["index.ts"],
|
||||
}),
|
||||
@@ -321,54 +289,38 @@ X;`,
|
||||
scenario: "projectsWithReferences",
|
||||
subScenario: "on transitive references in different folders with no files clause",
|
||||
sys: () =>
|
||||
createSystemWithSolutionBuild(
|
||||
["c"],
|
||||
[
|
||||
libFile,
|
||||
solutionBuildWithBaseline(
|
||||
createWatchedSystem(
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "a/tsconfig.json"),
|
||||
content: JSON.stringify({ compilerOptions: { composite: true } }),
|
||||
},
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "b/tsconfig.json"),
|
||||
content: JSON.stringify({
|
||||
[libFile.path]: libFile.content,
|
||||
"/user/username/projects/transitiveReferences/a/tsconfig.json": jsonToReadableText({ compilerOptions: { composite: true } }),
|
||||
"/user/username/projects/transitiveReferences/b/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, baseUrl: "./", paths: { "@ref/*": ["../*"] } },
|
||||
references: [{ path: `../a` }],
|
||||
}),
|
||||
},
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "c/tsconfig.json"),
|
||||
content: JSON.stringify({
|
||||
"/user/username/projects/transitiveReferences/c/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { baseUrl: "./", paths: { "@ref/*": ["../refs/*"] } },
|
||||
references: [{ path: `../b` }],
|
||||
}),
|
||||
},
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "a/index.ts"),
|
||||
content: `export class A {}`,
|
||||
},
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "b/index.ts"),
|
||||
content: `import {A} from '@ref/a';
|
||||
"/user/username/projects/transitiveReferences/a/index.ts": `export class A {}`,
|
||||
"/user/username/projects/transitiveReferences/b/index.ts": `import {A} from '@ref/a';
|
||||
export const b = new A();`,
|
||||
},
|
||||
{
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "c/index.ts"),
|
||||
content: `import {b} from '../b';
|
||||
"/user/username/projects/transitiveReferences/c/index.ts": `import {b} from '../b';
|
||||
import {X} from "@ref/a";
|
||||
b;
|
||||
X;`,
|
||||
"/user/username/projects/transitiveReferences/refs/a.d.ts": getFsContentsForTransitiveReferencesRefsAdts(),
|
||||
},
|
||||
getTsBuildProjectFile("transitiveReferences", "refs/a.d.ts"),
|
||||
],
|
||||
{ currentDirectory: `/user/username/projects/transitiveReferences` },
|
||||
{ currentDirectory: `/user/username/projects/transitiveReferences` },
|
||||
),
|
||||
["c"],
|
||||
),
|
||||
commandLineArgs: ["-w", "-p", "c", "--traceResolution", "--explainFiles"],
|
||||
edits: [
|
||||
{
|
||||
caption: "non local edit b ts, and build b",
|
||||
edit: sys => {
|
||||
sys.appendFile(getTsBuildProjectFilePath("transitiveReferences", "b/index.ts"), `export function gfoo() { }`);
|
||||
sys.appendFile("b/index.ts", `export function gfoo() { }`);
|
||||
const solutionBuilder = createSolutionBuilder(sys, ["b"]);
|
||||
solutionBuilder.build();
|
||||
},
|
||||
@@ -378,39 +330,39 @@ X;`,
|
||||
caption: "edit on config file",
|
||||
edit: sys => {
|
||||
sys.ensureFileOrFolder({
|
||||
path: getTsBuildProjectFilePath("transitiveReferences", "nrefs/a.d.ts"),
|
||||
content: sys.readFile(getTsBuildProjectFilePath("transitiveReferences", "refs/a.d.ts"))!,
|
||||
path: "nrefs/a.d.ts",
|
||||
content: sys.readFile("refs/a.d.ts")!,
|
||||
});
|
||||
changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "c/tsconfig.json"), { "@ref/*": ["../nrefs/*"] });
|
||||
changeCompilerOpitonsPaths(sys, "c/tsconfig.json", { "@ref/*": ["../nrefs/*"] });
|
||||
},
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert config file edit",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "c/tsconfig.json"), { "@ref/*": ["../refs/*"] }),
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "c/tsconfig.json", { "@ref/*": ["../refs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "edit in referenced config file",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "b/tsconfig.json"), { "@ref/*": ["../nrefs/*"] }),
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "b/tsconfig.json", { "@ref/*": ["../nrefs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert referenced config file edit",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, getTsBuildProjectFilePath("transitiveReferences", "b/tsconfig.json"), { "@ref/*": ["../refs/*"] }),
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "b/tsconfig.json", { "@ref/*": ["../refs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "deleting referenced config file",
|
||||
edit: sys => sys.deleteFile(getTsBuildProjectFilePath("transitiveReferences", "b/tsconfig.json")),
|
||||
edit: sys => sys.deleteFile("b/tsconfig.json"),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert deleting referenced config file",
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
getTsBuildProjectFilePath("transitiveReferences", "b/tsconfig.json"),
|
||||
JSON.stringify({
|
||||
"b/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true, baseUrl: "./", paths: { "@ref/*": ["../*"] } },
|
||||
references: [{ path: `../a` }],
|
||||
}),
|
||||
@@ -419,15 +371,15 @@ X;`,
|
||||
},
|
||||
{
|
||||
caption: "deleting transitively referenced config file",
|
||||
edit: sys => sys.deleteFile(getTsBuildProjectFilePath("transitiveReferences", "a/tsconfig.json")),
|
||||
edit: sys => sys.deleteFile("a/tsconfig.json"),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert deleting transitively referenced config file",
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
getTsBuildProjectFilePath("transitiveReferences", "a/tsconfig.json"),
|
||||
JSON.stringify({ compilerOptions: { composite: true } }),
|
||||
"a/tsconfig.json",
|
||||
jsonToReadableText({ compilerOptions: { composite: true } }),
|
||||
),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
@@ -439,25 +391,16 @@ X;`,
|
||||
scenario: "projectsWithReferences",
|
||||
subScenario: "when declarationMap changes for dependency",
|
||||
sys: () =>
|
||||
createSystemWithSolutionBuild(
|
||||
solutionBuildWithBaseline(
|
||||
getSysForSampleProjectReferences(),
|
||||
["core"],
|
||||
[
|
||||
libFile,
|
||||
getTsBuildProjectFile("sample1", "core/tsconfig.json"),
|
||||
getTsBuildProjectFile("sample1", "core/index.ts"),
|
||||
getTsBuildProjectFile("sample1", "core/anotherModule.ts"),
|
||||
getTsBuildProjectFile("sample1", "core/some_decl.d.ts"),
|
||||
getTsBuildProjectFile("sample1", "logic/tsconfig.json"),
|
||||
getTsBuildProjectFile("sample1", "logic/index.ts"),
|
||||
],
|
||||
{ currentDirectory: `/user/username/projects/sample1` },
|
||||
),
|
||||
commandLineArgs: ["-w", "-p", "logic", "--traceResolution", "--explainFiles"],
|
||||
edits: [
|
||||
{
|
||||
caption: "change declration map in core",
|
||||
edit: sys => {
|
||||
sys.replaceFileText(getTsBuildProjectFilePath("sample1", "core/tsconfig.json"), `"declarationMap": true,`, `"declarationMap": false,`);
|
||||
sys.replaceFileText("/user/username/projects/sample1/core/tsconfig.json", `"declarationMap": true,`, `"declarationMap": false,`);
|
||||
const solutionBuilder = createSolutionBuilder(sys, ["core"]);
|
||||
solutionBuilder.build();
|
||||
},
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import * as Utils from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
libContent,
|
||||
} from "../helpers/contents";
|
||||
@@ -334,7 +337,7 @@ declare module "fs" {
|
||||
};
|
||||
const configFile: File = {
|
||||
path: configDir + "tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
allowJs: true,
|
||||
rootDir: ".",
|
||||
@@ -406,7 +409,7 @@ declare module "fs" {
|
||||
edit: sys =>
|
||||
sys.ensureFileOrFolder({
|
||||
path: `/user/username/projects/myproject/node_modules/.cache/babel-loader/89c02171edab901b9926470ba6d5677e.ts`,
|
||||
content: JSON.stringify({ something: 10 }),
|
||||
content: jsonToReadableText({ something: 10 }),
|
||||
}),
|
||||
timeouts: sys => sys.logTimeoutQueueLength(),
|
||||
},
|
||||
@@ -428,7 +431,7 @@ declare module "fs" {
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "none",
|
||||
types: ["@myapp/ts-types"],
|
||||
@@ -443,7 +446,7 @@ declare module "fs" {
|
||||
edit: sys => {
|
||||
sys.ensureFileOrFolder({
|
||||
path: `/user/username/projects/myproject/node_modules/@myapp/ts-types/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
version: "1.65.1",
|
||||
types: "types/somefile.define.d.ts",
|
||||
}),
|
||||
@@ -487,7 +490,7 @@ declare namespace myapp {
|
||||
};
|
||||
const config: File = {
|
||||
path: `${mainPackageRoot}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { module: "commonjs", moduleResolution: "node", baseUrl: ".", rootDir: "." },
|
||||
files: ["index.ts"],
|
||||
}),
|
||||
@@ -498,7 +501,7 @@ declare namespace myapp {
|
||||
};
|
||||
const linkedPackageJson: File = {
|
||||
path: `${linkedPackageRoot}/package.json`,
|
||||
content: JSON.stringify({ name: "@scoped/linked-package", version: "0.0.1", types: "dist/index.d.ts", main: "dist/index.js" }),
|
||||
content: jsonToReadableText({ name: "@scoped/linked-package", version: "0.0.1", types: "dist/index.d.ts", main: "dist/index.js" }),
|
||||
};
|
||||
const linkedPackageIndex: File = {
|
||||
path: `${linkedPackageRoot}/dist/index.d.ts`,
|
||||
@@ -598,7 +601,7 @@ declare namespace NodeJS {
|
||||
subScenario: "reusing type ref resolution",
|
||||
sys: () =>
|
||||
createWatchedSystem({
|
||||
"/users/username/projects/project/tsconfig.json": JSON.stringify({
|
||||
"/users/username/projects/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
traceResolution: true,
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
verifyTscWatch,
|
||||
} from "../helpers/tscWatch";
|
||||
@@ -15,13 +18,13 @@ describe("unittests:: tsc-watch:: resolveJsonModuleWithIncremental:: emit file -
|
||||
"/src/project/main.ts": `import data from "./data.json"; let x: string = data;`,
|
||||
"/src/project/data.json": `{}`, // this file intentionally left blank
|
||||
"/src/project/data.d.json.ts": `declare var val: string; export default val;`,
|
||||
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions: { resolveJsonModule: true } }, null, 4), // eslint-disable-line no-null/no-null
|
||||
"/src/project/tsconfig.json": jsonToReadableText({ compilerOptions: { resolveJsonModule: true } }),
|
||||
[libFile.path]: libFile.content,
|
||||
}),
|
||||
commandLineArgs: ["--p", "src/project", "-i", "-w"],
|
||||
edits: [{
|
||||
caption: "Change json setting",
|
||||
edit: sys => sys.writeFile("/src/project/tsconfig.json", JSON.stringify({ compilerOptions: { resolveJsonModule: false } }, null, 4)), // eslint-disable-line no-null/no-null
|
||||
edit: sys => sys.writeFile("/src/project/tsconfig.json", jsonToReadableText({ compilerOptions: { resolveJsonModule: false } })),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
}],
|
||||
});
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
libContent,
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
FsContents,
|
||||
} from "../helpers/contents";
|
||||
import {
|
||||
getFsContentsForDemoProjectReferences,
|
||||
} from "../helpers/demoProjectReferences";
|
||||
import {
|
||||
solutionBuildWithBaseline,
|
||||
} from "../helpers/solutionBuilder";
|
||||
@@ -14,14 +20,13 @@ import {
|
||||
createWatchedSystem,
|
||||
File,
|
||||
FileOrFolderOrSymLink,
|
||||
getTsBuildProjectFile,
|
||||
libFile,
|
||||
SymLink,
|
||||
} from "../helpers/virtualFileSystemWithWatch";
|
||||
|
||||
describe("unittests:: tsc-watch:: watchAPI:: with sourceOfProjectReferenceRedirect", () => {
|
||||
interface VerifyWatchInput {
|
||||
files: readonly FileOrFolderOrSymLink[];
|
||||
files: FsContents | readonly FileOrFolderOrSymLink[];
|
||||
config: string;
|
||||
subScenario: string;
|
||||
}
|
||||
@@ -66,16 +71,9 @@ describe("unittests:: tsc-watch:: watchAPI:: with sourceOfProjectReferenceRedire
|
||||
|
||||
describe("with simple project", () => {
|
||||
verifyScenario(() => {
|
||||
const baseConfig = getTsBuildProjectFile("demo", "tsconfig-base.json");
|
||||
const coreTs = getTsBuildProjectFile("demo", "core/utilities.ts");
|
||||
const coreConfig = getTsBuildProjectFile("demo", "core/tsconfig.json");
|
||||
const animalTs = getTsBuildProjectFile("demo", "animals/animal.ts");
|
||||
const dogTs = getTsBuildProjectFile("demo", "animals/dog.ts");
|
||||
const indexTs = getTsBuildProjectFile("demo", "animals/index.ts");
|
||||
const animalsConfig = getTsBuildProjectFile("demo", "animals/tsconfig.json");
|
||||
return {
|
||||
files: [{ path: libFile.path, content: libContent }, baseConfig, coreTs, coreConfig, animalTs, dogTs, indexTs, animalsConfig],
|
||||
config: animalsConfig.path,
|
||||
files: getFsContentsForDemoProjectReferences(),
|
||||
config: "/user/username/projects/demo/animals/tsconfig.json",
|
||||
subScenario: "with simple project",
|
||||
};
|
||||
});
|
||||
@@ -115,7 +113,7 @@ describe("unittests:: tsc-watch:: watchAPI:: with sourceOfProjectReferenceRedire
|
||||
function config(packageName: string, extraOptions: ts.CompilerOptions, references?: string[]): File {
|
||||
return {
|
||||
path: `/user/username/projects/myproject/packages/${packageName}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
outDir: "lib",
|
||||
rootDir: "src",
|
||||
@@ -140,7 +138,7 @@ describe("unittests:: tsc-watch:: watchAPI:: with sourceOfProjectReferenceRedire
|
||||
verifySymlinkScenario(() => ({
|
||||
bPackageJson: {
|
||||
path: `/user/username/projects/myproject/packages/B/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
main: "lib/index.js",
|
||||
types: "lib/index.d.ts",
|
||||
}),
|
||||
|
||||
@@ -3,6 +3,9 @@ import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
commandLineCallbacks,
|
||||
} from "../helpers/baseline";
|
||||
@@ -36,11 +39,11 @@ describe("unittests:: tsc-watch:: watchAPI:: tsc-watch with custom module resolu
|
||||
};
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify(configFileJson),
|
||||
content: jsonToReadableText(configFileJson),
|
||||
};
|
||||
const settingsJson: File = {
|
||||
path: `/user/username/projects/myproject/settings.json`,
|
||||
content: JSON.stringify({ content: "Print this" }),
|
||||
content: jsonToReadableText({ content: "Print this" }),
|
||||
};
|
||||
const { sys, baseline, oldSnap, cb, getPrograms } = createBaseline(createWatchedSystem(
|
||||
[libFile, mainFile, config, settingsJson],
|
||||
@@ -79,7 +82,7 @@ describe("unittests:: tsc-watch:: watchAPI:: tsc-watch with custom module resolu
|
||||
function verifyWatch(subScenario: string, implementHasInvalidatedResolution: boolean) {
|
||||
it(subScenario, () => {
|
||||
const { sys, baseline, oldSnap, cb, getPrograms } = createBaseline(createWatchedSystem({
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: JSON.stringify({
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: jsonToReadableText({
|
||||
compilerOptions: { traceResolution: true, extendedDiagnostics: true },
|
||||
files: ["main.ts"],
|
||||
}),
|
||||
@@ -137,7 +140,7 @@ describe("unittests:: tsc-watch:: watchAPI:: tsc-watch expose error count to wat
|
||||
it("verify that the error count is correctly passed down to the watch status reporter", () => {
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: { module: "commonjs" },
|
||||
files: ["index.ts"],
|
||||
}),
|
||||
@@ -381,7 +384,7 @@ describe("unittests:: tsc-watch:: watchAPI:: when watchHost uses createSemanticD
|
||||
let baseline: string[];
|
||||
let emitBaseline: string[];
|
||||
before(() => {
|
||||
const configText = JSON.stringify({ compilerOptions: { composite: true } });
|
||||
const configText = jsonToReadableText({ compilerOptions: { composite: true } });
|
||||
const mainText = "export const x = 10;";
|
||||
const result = createSystemForBuilderTest(configText, mainText);
|
||||
baseline = result.baseline;
|
||||
@@ -425,7 +428,7 @@ describe("unittests:: tsc-watch:: watchAPI:: when watchHost uses createSemanticD
|
||||
let baseline: string[];
|
||||
let emitBaseline: string[];
|
||||
before(() => {
|
||||
const configText = JSON.stringify({ compilerOptions: { composite: true, noEmitOnError: true } });
|
||||
const configText = jsonToReadableText({ compilerOptions: { composite: true, noEmitOnError: true } });
|
||||
const mainText = "export const x: string = 10;";
|
||||
const result = createSystemForBuilderTest(configText, mainText);
|
||||
baseline = result.baseline;
|
||||
@@ -459,7 +462,7 @@ describe("unittests:: tsc-watch:: watchAPI:: when watchHost uses createSemanticD
|
||||
|
||||
it("SemanticDiagnosticsBuilderProgram emitDtsOnly does not update affected files pending emit", () => {
|
||||
// Initial
|
||||
const { sys, baseline, config, mainFile } = createSystem(JSON.stringify({ compilerOptions: { composite: true, noEmitOnError: true } }), "export const x: string = 10;");
|
||||
const { sys, baseline, config, mainFile } = createSystem(jsonToReadableText({ compilerOptions: { composite: true, noEmitOnError: true } }), "export const x: string = 10;");
|
||||
createWatch(baseline, config, sys, ts.createSemanticDiagnosticsBuilderProgram);
|
||||
|
||||
// Fix error and emit
|
||||
@@ -505,7 +508,7 @@ describe("unittests:: tsc-watch:: watchAPI:: when getParsedCommandLine is implem
|
||||
function setup(useSourceOfProjectReferenceRedirect?: () => boolean) {
|
||||
const config1: File = {
|
||||
path: `/user/username/projects/myproject/projects/project1/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "none",
|
||||
composite: true,
|
||||
@@ -523,7 +526,7 @@ describe("unittests:: tsc-watch:: watchAPI:: when getParsedCommandLine is implem
|
||||
};
|
||||
const config2: File = {
|
||||
path: `/user/username/projects/myproject/projects/project2/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
module: "none",
|
||||
composite: true,
|
||||
@@ -641,7 +644,7 @@ describe("unittests:: tsc-watch:: watchAPI:: when builder emit occurs with emitO
|
||||
function verify(subScenario: string, outFile?: string) {
|
||||
it(subScenario, () => {
|
||||
const system = createWatchedSystem({
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: JSON.stringify({
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: jsonToReadableText({
|
||||
compilerOptions: { composite: true, noEmitOnError: true, module: "amd", outFile },
|
||||
files: ["a.ts", "b.ts"],
|
||||
}),
|
||||
@@ -733,7 +736,7 @@ describe("unittests:: tsc-watch:: watchAPI:: when builder emit occurs with emitO
|
||||
describe("unittests:: tsc-watch:: watchAPI:: when creating program with project references but not config file", () => {
|
||||
function setup(libExtends: boolean) {
|
||||
const system = createWatchedSystem({
|
||||
"/user/username/projects/project/tsconfig.json": JSON.stringify({
|
||||
"/user/username/projects/project/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: { types: [] },
|
||||
files: ["app.ts"],
|
||||
references: [{ path: "./lib" }],
|
||||
@@ -742,12 +745,12 @@ describe("unittests:: tsc-watch:: watchAPI:: when creating program with project
|
||||
import { one } from './lib';
|
||||
console.log(one);
|
||||
`,
|
||||
"/user/username/projects/project/lib/tsconfig.json": JSON.stringify({
|
||||
"/user/username/projects/project/lib/tsconfig.json": jsonToReadableText({
|
||||
extends: libExtends ? "./tsconfig.base.json" : undefined,
|
||||
compilerOptions: libExtends ? undefined : { composite: true, types: [] },
|
||||
files: ["index.ts"],
|
||||
}),
|
||||
"/user/username/projects/project/lib/tsconfig.base.json": JSON.stringify({
|
||||
"/user/username/projects/project/lib/tsconfig.base.json": jsonToReadableText({
|
||||
compilerOptions: { composite: true, types: [] },
|
||||
}),
|
||||
"/user/username/projects/project/lib/index.ts": "export const one = 1;",
|
||||
@@ -792,7 +795,7 @@ describe("unittests:: tsc-watch:: watchAPI:: when creating program with project
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
`/user/username/projects/project/lib/tsconfig.json`,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
files: ["index.ts"],
|
||||
}),
|
||||
@@ -817,7 +820,7 @@ describe("unittests:: tsc-watch:: watchAPI:: when creating program with project
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
`/user/username/projects/project/lib/tsconfig.json`,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
extends: "./tsconfig.base.json",
|
||||
compilerOptions: { typeRoots: [] },
|
||||
files: ["index.ts"],
|
||||
@@ -830,7 +833,7 @@ describe("unittests:: tsc-watch:: watchAPI:: when creating program with project
|
||||
edit: sys =>
|
||||
sys.writeFile(
|
||||
`/user/username/projects/project/lib/tsconfig.base.json`,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
commonFile1,
|
||||
commonFile2,
|
||||
@@ -88,7 +91,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
sys: () => {
|
||||
const configFile: File = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
watchOptions: {
|
||||
watchFile: "FixedChunkSizePolling",
|
||||
},
|
||||
@@ -141,7 +144,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
const projectSrcFolder = `${projectFolder}/src`;
|
||||
const configFile: File = {
|
||||
path: `${projectFolder}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
watchOptions: {
|
||||
synchronousWatchDirectory: true,
|
||||
},
|
||||
@@ -316,7 +319,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
sys: () => {
|
||||
const configFile: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { outDir: "dist", declaration: true } }),
|
||||
content: jsonToReadableText({ compilerOptions: { outDir: "dist", declaration: true } }),
|
||||
};
|
||||
const file1: File = {
|
||||
path: `/user/username/projects/myproject/src/file1.ts`,
|
||||
@@ -357,7 +360,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
sys: () => {
|
||||
const configFile: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: { outDir: "dist" } }),
|
||||
content: jsonToReadableText({ compilerOptions: { outDir: "dist" } }),
|
||||
};
|
||||
const file1: File = {
|
||||
path: `/user/username/projects/myproject/src/file1.ts`,
|
||||
@@ -399,7 +402,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
sys: () => {
|
||||
const configFile: File = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
watchOptions: {
|
||||
watchFile: "UseFsEvents",
|
||||
},
|
||||
@@ -417,7 +420,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
sys: () => {
|
||||
const configFile: File = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
watchOptions: {
|
||||
watchDirectory: "UseFsEvents",
|
||||
},
|
||||
@@ -435,7 +438,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
sys: () => {
|
||||
const configFile: File = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
watchOptions: {
|
||||
fallbackPolling: "PriorityInterval",
|
||||
},
|
||||
@@ -464,7 +467,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
function sys(watchOptions: ts.WatchOptions, runWithoutRecursiveWatches?: boolean): TestServerHost {
|
||||
const configFile: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ exclude: ["node_modules"], watchOptions }),
|
||||
content: jsonToReadableText({ exclude: ["node_modules"], watchOptions }),
|
||||
};
|
||||
const main: File = {
|
||||
path: `/user/username/projects/myproject/src/main.ts`,
|
||||
@@ -554,7 +557,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
[libFile.path]: libFile.content,
|
||||
[`/user/username/projects/myproject/main.ts`]: `import { foo } from "./foo"; foo();`,
|
||||
[`/user/username/projects/myproject/foo.ts`]: `export declare function foo(): string;`,
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: JSON.stringify({
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: jsonToReadableText({
|
||||
watchOptions: { watchFile: "useFsEvents" },
|
||||
files: ["foo.ts", "main.ts"],
|
||||
}),
|
||||
@@ -592,7 +595,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
[libFile.path]: libFile.content,
|
||||
[`/user/username/projects/myproject/main.ts`]: `import { foo } from "./foo"; foo();`,
|
||||
[`/user/username/projects/myproject/foo.d.ts`]: `export function foo(): string;`,
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: JSON.stringify({ watchOptions: { watchFile: "useFsEvents" }, files: ["foo.d.ts", "main.ts"] }),
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: jsonToReadableText({ watchOptions: { watchFile: "useFsEvents" }, files: ["foo.d.ts", "main.ts"] }),
|
||||
},
|
||||
{
|
||||
currentDirectory: "/user/username/projects/myproject",
|
||||
@@ -623,7 +626,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
[libFile.path]: libFile.content,
|
||||
[`/user/username/projects/myproject/main.ts`]: `import { foo } from "./foo"; foo();`,
|
||||
[`/user/username/projects/myproject/foo.d.ts`]: `export function foo(): string;`,
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: JSON.stringify({ watchOptions: { watchFile: "useFsEvents" }, files: ["foo.d.ts", "main.ts"] }),
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: jsonToReadableText({ watchOptions: { watchFile: "useFsEvents" }, files: ["foo.d.ts", "main.ts"] }),
|
||||
},
|
||||
{
|
||||
currentDirectory: "/user/username/projects/myproject",
|
||||
@@ -654,7 +657,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
|
||||
[libFile.path]: libFile.content,
|
||||
[`/user/username/projects/myproject/main.ts`]: `import { foo } from "./foo"; foo();`,
|
||||
[`/user/username/projects/myproject/foo.ts`]: `export declare function foo(): string;`,
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: JSON.stringify({
|
||||
[`/user/username/projects/myproject/tsconfig.json`]: jsonToReadableText({
|
||||
watchOptions: { watchFile: "useFsEvents" },
|
||||
files: ["foo.ts", "main.ts"],
|
||||
}),
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../harness/tsserverLogger";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createSession,
|
||||
@@ -261,7 +264,7 @@ describe("unittests:: tsserver:: autoImportProvider", () => {
|
||||
}
|
||||
|
||||
const dependencies = packages.reduce((hash, p) => ({ ...hash, [JSON.parse(p[0].content).name]: "*" }), {});
|
||||
const packageJson: File = { path: "/package.json", content: JSON.stringify(dependencies) };
|
||||
const packageJson: File = { path: "/package.json", content: jsonToReadableText(dependencies) };
|
||||
const { projectService, session } = setup([...ts.flatten(packages), indexTs, tsconfig, packageJson]);
|
||||
|
||||
openFilesForSession([indexTs], session);
|
||||
@@ -273,11 +276,11 @@ describe("unittests:: tsserver:: autoImportProvider", () => {
|
||||
it("Shared source files between AutoImportProvider and main program do not cause duplicate entries in export info map", () => {
|
||||
const files = [
|
||||
// node_modules/memfs - AutoImportProvider only
|
||||
{ path: "/node_modules/memfs/package.json", content: `{ "name": "memfs", "version": "1.0.0", "types": "lib/index.d.ts" }` },
|
||||
{ path: "/node_modules/memfs/package.json", content: jsonToReadableText({ name: "memfs", version: "1.0.0", types: "lib/index.d.ts" }) },
|
||||
{ path: "/node_modules/memfs/lib/index.d.ts", content: `/// <reference types="node" />\nexport declare class Volume {}` },
|
||||
|
||||
// node_modules/@types/node - AutoImportProvider and main program
|
||||
{ path: "/node_modules/@types/node/package.json", content: `{ "name": "@types/node", "version": "1.0.0" }` },
|
||||
{ path: "/node_modules/@types/node/package.json", content: jsonToReadableText({ name: "@types/node", version: "1.0.0" }) },
|
||||
{ path: "/node_modules/@types/node/index.d.ts", content: `export declare class Stats {}` },
|
||||
|
||||
// root
|
||||
|
||||
@@ -5,6 +5,9 @@ import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
dedent,
|
||||
} from "../../_namespaces/Utils";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createSession,
|
||||
@@ -76,15 +79,11 @@ describe("unittests:: tsserver:: auxiliaryProject::", () => {
|
||||
`,
|
||||
};
|
||||
const host = createServerHost({
|
||||
"/user/users/projects/myproject/node_modules/@types/yargs/package.json": JSON.stringify(
|
||||
{
|
||||
name: "@types/yargs",
|
||||
version: "1.0.0",
|
||||
types: "./index.d.ts",
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
"/user/users/projects/myproject/node_modules/@types/yargs/package.json": jsonToReadableText({
|
||||
name: "@types/yargs",
|
||||
version: "1.0.0",
|
||||
types: "./index.d.ts",
|
||||
}),
|
||||
"/user/users/projects/myproject/node_modules/@types/yargs/callback.d.ts": dedent`
|
||||
export declare class Yargs { positional(): Yargs; }
|
||||
`,
|
||||
@@ -92,15 +91,11 @@ describe("unittests:: tsserver:: auxiliaryProject::", () => {
|
||||
import { Yargs } from "./callback";
|
||||
export declare function command(command: string, cb: (yargs: Yargs) => void): void;
|
||||
`,
|
||||
"/user/users/projects/myproject/node_modules/yargs/package.json": JSON.stringify(
|
||||
{
|
||||
name: "yargs",
|
||||
version: "1.0.0",
|
||||
main: "index.js",
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
"/user/users/projects/myproject/node_modules/yargs/package.json": jsonToReadableText({
|
||||
name: "yargs",
|
||||
version: "1.0.0",
|
||||
main: "index.js",
|
||||
}),
|
||||
"/user/users/projects/myproject/node_modules/yargs/callback.js": dedent`
|
||||
export class Yargs { positional() { } }
|
||||
`,
|
||||
@@ -140,15 +135,11 @@ describe("unittests:: tsserver:: auxiliaryProject::", () => {
|
||||
`,
|
||||
};
|
||||
const host = createServerHost({
|
||||
"/user/users/projects/myproject/node_modules/@types/yargs/package.json": JSON.stringify(
|
||||
{
|
||||
name: "@types/yargs",
|
||||
version: "1.0.0",
|
||||
types: "./index.d.ts",
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
"/user/users/projects/myproject/node_modules/@types/yargs/package.json": jsonToReadableText({
|
||||
name: "@types/yargs",
|
||||
version: "1.0.0",
|
||||
types: "./index.d.ts",
|
||||
}),
|
||||
"/user/users/projects/myproject/node_modules/@types/yargs/callback.d.ts": dedent`
|
||||
export declare class Yargs { positional(): Yargs; }
|
||||
`,
|
||||
@@ -156,15 +147,11 @@ describe("unittests:: tsserver:: auxiliaryProject::", () => {
|
||||
import { Yargs } from "./callback";
|
||||
export declare function command(command: string, cb: (yargs: Yargs) => void): void;
|
||||
`,
|
||||
"/user/users/projects/myproject/node_modules/yargs/package.json": JSON.stringify(
|
||||
{
|
||||
name: "yargs",
|
||||
version: "1.0.0",
|
||||
main: "index.js",
|
||||
},
|
||||
undefined,
|
||||
" ",
|
||||
),
|
||||
"/user/users/projects/myproject/node_modules/yargs/package.json": jsonToReadableText({
|
||||
name: "yargs",
|
||||
version: "1.0.0",
|
||||
main: "index.js",
|
||||
}),
|
||||
"/user/users/projects/myproject/node_modules/yargs/callback.js": dedent`
|
||||
export class Yargs { positional() { } }
|
||||
`,
|
||||
|
||||
@@ -6,6 +6,9 @@ import {
|
||||
Logger,
|
||||
} from "../../../harness/tsserverLogger";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createProjectService,
|
||||
@@ -78,7 +81,7 @@ describe("unittests:: tsserver:: CachingFileSystemInformation:: tsserverProjectS
|
||||
|
||||
function logCacheEntry(logger: Logger, callback: CalledMaps) {
|
||||
const result = Array.from<[string, (true | CalledWithFiveArgs)[]], { key: string; count: number; }>(calledMaps[callback].entries(), ([key, arr]) => ({ key, count: arr.length }));
|
||||
logger.info(`${callback}:: ${JSON.stringify(result)}`);
|
||||
logger.info(`${callback}:: ${jsonToReadableText(result)}`);
|
||||
calledMaps[callback].clear();
|
||||
}
|
||||
|
||||
@@ -214,7 +217,7 @@ describe("unittests:: tsserver:: CachingFileSystemInformation:: tsserverProjectS
|
||||
};
|
||||
const tsconfigFile: File = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
target: "es6",
|
||||
module: "es6",
|
||||
@@ -283,7 +286,7 @@ describe("unittests:: tsserver:: CachingFileSystemInformation:: tsserverProjectS
|
||||
const types = ["node", "jest"];
|
||||
const tsconfigFile: File = {
|
||||
path: `${frontendDir}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: true,
|
||||
strictNullChecks: true,
|
||||
@@ -348,7 +351,7 @@ describe("unittests:: tsserver:: CachingFileSystemInformation:: tsserverProjectS
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: `${projectLocation}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
files: ["foo/boo/app.ts", "foo/boo/moo/app.ts"],
|
||||
moduleResolution: resolution,
|
||||
}),
|
||||
@@ -603,7 +606,7 @@ describe("unittests:: tsserver:: CachingFileSystemInformation:: tsserverProjectS
|
||||
};
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
baseUrl: "client",
|
||||
paths: { "*": ["*"] },
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../harness/tsserverLogger";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createSession,
|
||||
@@ -66,7 +69,7 @@ describe("unittests:: tsserver:: cancellationToken", () => {
|
||||
};
|
||||
const config = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {},
|
||||
}),
|
||||
};
|
||||
@@ -163,7 +166,7 @@ describe("unittests:: tsserver:: cancellationToken", () => {
|
||||
};
|
||||
const config = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {},
|
||||
}),
|
||||
};
|
||||
@@ -223,7 +226,7 @@ describe("unittests:: tsserver:: cancellationToken", () => {
|
||||
session.logger.log(`Exception is OperationCanceledException: ${e instanceof ts.OperationCanceledException}`);
|
||||
operationCanceledExceptionThrown = true;
|
||||
}
|
||||
if (!operationCanceledExceptionThrown) session.logger.log("Operation Canceled Exception not thrown for request: " + JSON.stringify(request));
|
||||
if (!operationCanceledExceptionThrown) session.logger.log("Operation Canceled Exception not thrown for request: " + jsonToReadableText(request));
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -3,6 +3,9 @@ import {
|
||||
Logger,
|
||||
} from "../../../harness/tsserverLogger";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createSession,
|
||||
@@ -644,7 +647,7 @@ describe("unittests:: tsserver:: compileOnSave:: affected list", () => {
|
||||
};
|
||||
const config = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: opts,
|
||||
compileOnSave: true,
|
||||
}),
|
||||
@@ -714,7 +717,7 @@ describe("unittests:: tsserver:: compileOnSave:: affected list", () => {
|
||||
};
|
||||
const config = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: opts,
|
||||
compileOnSave: true,
|
||||
}),
|
||||
@@ -861,7 +864,7 @@ describe("unittests:: tsserver:: compileOnSave:: EmitFile test", () => {
|
||||
function verify(richResponse: boolean | undefined) {
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compileOnSave: true,
|
||||
compilerOptions: {
|
||||
outDir: "test",
|
||||
@@ -919,7 +922,7 @@ describe("unittests:: tsserver:: compileOnSave:: EmitFile test", () => {
|
||||
function verifyGlobalSave(declaration: boolean, hasModule: boolean) {
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compileOnSave: true,
|
||||
compilerOptions: {
|
||||
declaration,
|
||||
@@ -1041,7 +1044,7 @@ describe("unittests:: tsserver:: compileOnSave:: CompileOnSaveAffectedFileListRe
|
||||
};
|
||||
const app1Config: File = {
|
||||
path: `/user/username/projects/myproject/app1/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
files: ["app.ts", "../core/core.ts"],
|
||||
compilerOptions: { outFile: "build/output.js" },
|
||||
compileOnSave: true,
|
||||
@@ -1049,7 +1052,7 @@ describe("unittests:: tsserver:: compileOnSave:: CompileOnSaveAffectedFileListRe
|
||||
};
|
||||
const app2Config: File = {
|
||||
path: `/user/username/projects/myproject/app2/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
files: ["app.ts", "../core/core.ts"],
|
||||
compilerOptions: { outFile: "build/output.js" },
|
||||
compileOnSave: true,
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../harness/tsserverLogger";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createSession,
|
||||
@@ -73,7 +76,7 @@ describe("unittests:: tsserver:: completions", () => {
|
||||
const projectRoot = "e:/myproject";
|
||||
const appPackage: File = {
|
||||
path: `${projectRoot}/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "test",
|
||||
version: "0.1.0",
|
||||
dependencies: {
|
||||
@@ -94,7 +97,7 @@ import {
|
||||
const localAtTypes = `${localNodeModules}/@types`;
|
||||
const localReactPackage: File = {
|
||||
path: `${localAtTypes}/react/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "@types/react",
|
||||
version: "16.9.14",
|
||||
}),
|
||||
@@ -106,7 +109,7 @@ import {
|
||||
};
|
||||
const localReactRouterDomPackage: File = {
|
||||
path: `${localNodeModules}/react-router-dom/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "react-router-dom",
|
||||
version: "5.1.2",
|
||||
}),
|
||||
@@ -117,7 +120,7 @@ import {
|
||||
};
|
||||
const localPropTypesPackage: File = {
|
||||
path: `${localAtTypes}/prop-types/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "@types/prop-types",
|
||||
version: "15.7.3",
|
||||
}),
|
||||
@@ -135,7 +138,7 @@ import {
|
||||
const globalAtTypes = `${globalTypingsCacheLocation}/node_modules/@types`;
|
||||
const globalReactRouterDomPackage: File = {
|
||||
path: `${globalAtTypes}/react-router-dom/package.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
name: "@types/react-router-dom",
|
||||
version: "5.1.2",
|
||||
}),
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../harness/tsserverLogger";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
ensureErrorFreeBuild,
|
||||
} from "../helpers/solutionBuilder";
|
||||
@@ -55,7 +58,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
const { configFileName, configFileErrors } = projectService.openClientFile(file1.path);
|
||||
|
||||
assert(configFileName, "should find config file");
|
||||
assert.isTrue(!configFileErrors || configFileErrors.length === 0, `expect no errors in config file, got ${JSON.stringify(configFileErrors)}`);
|
||||
assert.isTrue(!configFileErrors || configFileErrors.length === 0, `expect no errors in config file, got ${jsonToReadableText(configFileErrors)}`);
|
||||
|
||||
baselineTsserverLogs("configuredProjects", "create configured project without file list", projectService);
|
||||
});
|
||||
@@ -87,7 +90,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
const { configFileName, configFileErrors } = projectService.openClientFile(file1.path);
|
||||
|
||||
assert(configFileName, "should find config file");
|
||||
assert.isTrue(!configFileErrors || configFileErrors.length === 0, `expect no errors in config file, got ${JSON.stringify(configFileErrors)}`);
|
||||
assert.isTrue(!configFileErrors || configFileErrors.length === 0, `expect no errors in config file, got ${jsonToReadableText(configFileErrors)}`);
|
||||
|
||||
baselineTsserverLogs("configuredProjects", "create configured project with the file list", projectService);
|
||||
});
|
||||
@@ -366,7 +369,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
};
|
||||
const configFile = {
|
||||
path: `/user/username/projects/myproject/a/c/tsconfig.json`,
|
||||
content: JSON.stringify({ compilerOptions: {}, files: ["f2.ts", "f3.ts"] }),
|
||||
content: jsonToReadableText({ compilerOptions: {}, files: ["f2.ts", "f3.ts"] }),
|
||||
};
|
||||
|
||||
const host = createServerHost([file1, file2, file3]);
|
||||
@@ -393,7 +396,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
};
|
||||
const configFile = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: {} }),
|
||||
content: jsonToReadableText({ compilerOptions: {} }),
|
||||
};
|
||||
|
||||
const host = createServerHost([file1, configFile]);
|
||||
@@ -419,7 +422,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
};
|
||||
const configFile = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: {}, files: ["f1.ts"] }),
|
||||
content: jsonToReadableText({ compilerOptions: {}, files: ["f1.ts"] }),
|
||||
};
|
||||
|
||||
const host = createServerHost([file1, file2, configFile]);
|
||||
@@ -427,7 +430,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
|
||||
projectService.openClientFile(file1.path);
|
||||
|
||||
host.writeFile(configFile.path, JSON.stringify({ compilerOptions: {}, files: ["f1.ts", "f2.ts"] }));
|
||||
host.writeFile(configFile.path, jsonToReadableText({ compilerOptions: {}, files: ["f1.ts", "f2.ts"] }));
|
||||
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
baselineTsserverLogs("configuredProjects", "can correctly update configured project when set of root files has changed (new file in list of files)", projectService);
|
||||
@@ -444,7 +447,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
};
|
||||
const configFile = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: {}, files: ["f1.ts", "f2.ts"] }),
|
||||
content: jsonToReadableText({ compilerOptions: {}, files: ["f1.ts", "f2.ts"] }),
|
||||
};
|
||||
|
||||
const host = createServerHost([file1, file2, configFile]);
|
||||
@@ -452,7 +455,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
|
||||
projectService.openClientFile(file1.path);
|
||||
|
||||
host.writeFile(configFile.path, JSON.stringify({ compilerOptions: { outFile: "out.js" }, files: ["f1.ts", "f2.ts"] }));
|
||||
host.writeFile(configFile.path, jsonToReadableText({ compilerOptions: { outFile: "out.js" }, files: ["f1.ts", "f2.ts"] }));
|
||||
host.runQueuedTimeoutCallbacks();
|
||||
|
||||
baselineTsserverLogs("configuredProjects", "can update configured project when set of root files was not changed", projectService);
|
||||
@@ -477,7 +480,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
};
|
||||
const configFile = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({ files: ["src/file1.ts", "file3.ts"] }),
|
||||
content: jsonToReadableText({ files: ["src/file1.ts", "file3.ts"] }),
|
||||
};
|
||||
|
||||
const files = [file1, file2, file3, file4];
|
||||
@@ -540,7 +543,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
};
|
||||
const configFile = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({ files: ["src/file1.ts", "file3.ts"] }),
|
||||
content: jsonToReadableText({ files: ["src/file1.ts", "file3.ts"] }),
|
||||
};
|
||||
|
||||
const files = [file1, file2, file3];
|
||||
@@ -587,7 +590,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
};
|
||||
const config = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: { allowJs: true } }),
|
||||
content: jsonToReadableText({ compilerOptions: { allowJs: true } }),
|
||||
};
|
||||
const host = createServerHost([f1, f2, f3, config]);
|
||||
const originalGetFileSize = host.getFileSize;
|
||||
@@ -653,7 +656,7 @@ describe("unittests:: tsserver:: ConfiguredProjects", () => {
|
||||
it("when multiple projects are open, detects correct default project", () => {
|
||||
const barConfig: File = {
|
||||
path: `/user/username/projects/myproject/bar/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
include: ["index.ts"],
|
||||
compilerOptions: {
|
||||
lib: ["dom", "es2017"],
|
||||
@@ -669,7 +672,7 @@ export function bar() {
|
||||
};
|
||||
const fooConfig: File = {
|
||||
path: `/user/username/projects/myproject/foo/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
include: ["index.ts"],
|
||||
compilerOptions: {
|
||||
lib: ["es2017"],
|
||||
@@ -735,7 +738,7 @@ declare var console: {
|
||||
};
|
||||
const config: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
include: ["./src"],
|
||||
}),
|
||||
};
|
||||
@@ -752,7 +755,7 @@ declare var console: {
|
||||
withExclude ?
|
||||
{
|
||||
path: config.path,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
include: ["./src"],
|
||||
exclude: ["./src/sub"],
|
||||
}),
|
||||
@@ -852,7 +855,7 @@ foo();`,
|
||||
};
|
||||
const fooConfig: File = {
|
||||
path: `/user/username/projects/myproject/foo/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
include: ["index.ts"],
|
||||
compilerOptions: {
|
||||
declaration: true,
|
||||
@@ -892,13 +895,13 @@ foo();`,
|
||||
};
|
||||
const bravoExtendedConfig: File = {
|
||||
path: `/user/username/projects/myproject/extended/bravo.tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
extends: "./alpha.tsconfig.json",
|
||||
}),
|
||||
};
|
||||
const aConfig: File = {
|
||||
path: `/user/username/projects/myproject/a/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
extends: "../extended/alpha.tsconfig.json",
|
||||
files: ["a.ts"],
|
||||
}),
|
||||
@@ -909,7 +912,7 @@ foo();`,
|
||||
};
|
||||
const bConfig: File = {
|
||||
path: `/user/username/projects/myproject/b/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
extends: "../extended/bravo.tsconfig.json",
|
||||
files: ["b.ts"],
|
||||
}),
|
||||
@@ -932,7 +935,7 @@ foo();`,
|
||||
|
||||
host.writeFile(
|
||||
alphaExtendedConfig.path,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
strict: true,
|
||||
},
|
||||
@@ -942,7 +945,7 @@ foo();`,
|
||||
|
||||
host.writeFile(
|
||||
bravoExtendedConfig.path,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
extends: "./alpha.tsconfig.json",
|
||||
compilerOptions: {
|
||||
strict: false,
|
||||
@@ -953,7 +956,7 @@ foo();`,
|
||||
|
||||
host.writeFile(
|
||||
bConfig.path,
|
||||
JSON.stringify({
|
||||
jsonToReadableText({
|
||||
extends: "../extended/alpha.tsconfig.json",
|
||||
}),
|
||||
);
|
||||
@@ -1021,7 +1024,7 @@ describe("unittests:: tsserver:: ConfiguredProjects:: non-existing directories l
|
||||
};
|
||||
const config = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compiler: {},
|
||||
files: [],
|
||||
}),
|
||||
@@ -1049,7 +1052,7 @@ describe("unittests:: tsserver:: ConfiguredProjects:: non-existing directories l
|
||||
};
|
||||
const config = {
|
||||
path: `/user/username/projects/myproject/src/server/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compiler: {
|
||||
module: "commonjs",
|
||||
outDir: "../../build",
|
||||
@@ -1082,7 +1085,7 @@ describe("unittests:: tsserver:: ConfiguredProjects:: non-existing directories l
|
||||
};
|
||||
const configFile: File = {
|
||||
path: "/users/username/projects/project/tsconfig.json",
|
||||
content: JSON.stringify({ files: [file1.path], compilerOptions: { module: "amd" } }),
|
||||
content: jsonToReadableText({ files: [file1.path], compilerOptions: { module: "amd" } }),
|
||||
};
|
||||
const files = [file1, file2a, configFile, libFile];
|
||||
const host = createServerHost(files);
|
||||
@@ -1119,7 +1122,7 @@ describe("unittests:: tsserver:: ConfiguredProjects:: non-existing directories l
|
||||
};
|
||||
const configFile: File = {
|
||||
path: "/a/b/src/tsconfig.json",
|
||||
content: JSON.stringify({ files: ["file1.ts"] }),
|
||||
content: jsonToReadableText({ files: ["file1.ts"] }),
|
||||
};
|
||||
const nonLibFiles = [file1, module1, module2, module3, configFile];
|
||||
nonLibFiles.forEach(f => f.path = root + f.path);
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../harness/tsserverLogger";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
closeFilesForSession,
|
||||
@@ -20,7 +23,7 @@ function checkDeclarationFiles(file: File, session: TestSession): void {
|
||||
const project = ts.Debug.checkDefined(session.getProjectService().getDefaultProjectForFile(file.path as ts.server.NormalizedPath, /*ensureProject*/ false));
|
||||
const program = project.getCurrentProgram()!;
|
||||
const output = ts.getFileEmitOutput(program, ts.Debug.checkDefined(program.getSourceFile(file.path)), /*emitOnlyDtsFiles*/ true);
|
||||
session.logger.log(`ts.getFileEmitOutput: ${file.path}: ${JSON.stringify(output, undefined, " ")}`);
|
||||
session.logger.log(`ts.getFileEmitOutput: ${file.path}: ${jsonToReadableText(output)}`);
|
||||
closeFilesForSession([file], session);
|
||||
}
|
||||
|
||||
@@ -35,7 +38,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
|
||||
declarationMap: true,
|
||||
composite: true,
|
||||
};
|
||||
const configContent = JSON.stringify({ compilerOptions });
|
||||
const configContent = jsonToReadableText({ compilerOptions });
|
||||
const aTsconfig: File = { path: "/a/tsconfig.json", content: configContent };
|
||||
|
||||
const aDtsMapContent: ts.RawSourceMap = {
|
||||
@@ -48,7 +51,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
|
||||
};
|
||||
const aDtsMap: File = {
|
||||
path: "/a/bin/a.d.ts.map",
|
||||
content: JSON.stringify(aDtsMapContent),
|
||||
content: jsonToReadableText(aDtsMapContent),
|
||||
};
|
||||
const aDts: File = {
|
||||
path: "/a/bin/a.d.ts",
|
||||
@@ -72,7 +75,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
|
||||
};
|
||||
const bDtsMap: File = {
|
||||
path: "/b/bin/b.d.ts.map",
|
||||
content: JSON.stringify(bDtsMapContent),
|
||||
content: jsonToReadableText(bDtsMapContent),
|
||||
};
|
||||
const bDts: File = {
|
||||
// ${""} is need to mangle the sourceMappingURL part so it doesn't break the build
|
||||
@@ -97,7 +100,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
|
||||
|
||||
const userTsconfig: File = {
|
||||
path: "/user/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
file: ["user.ts"],
|
||||
references: [{ path: "../a" }, { path: "../b" }],
|
||||
}),
|
||||
@@ -271,14 +274,14 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
|
||||
const aTs: File = { path: "/a/a.ts", content: `function f() {}` };
|
||||
const aTsconfig: File = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: { declaration: true, declarationMap: true, outFile: "../bin/a.js" } }),
|
||||
content: jsonToReadableText({ compilerOptions: { declaration: true, declarationMap: true, outFile: "../bin/a.js" } }),
|
||||
};
|
||||
const bTs: File = { path: "/b/b.ts", content: `f();` };
|
||||
const bTsconfig: File = { path: "/b/tsconfig.json", content: JSON.stringify({ references: [{ path: "../a" }] }) };
|
||||
const bTsconfig: File = { path: "/b/tsconfig.json", content: jsonToReadableText({ references: [{ path: "../a" }] }) };
|
||||
const aDts: File = { path: "/bin/a.d.ts", content: `declare function f(): void;\n//# sourceMappingURL=a.d.ts.map` };
|
||||
const aDtsMap: File = {
|
||||
path: "/bin/a.d.ts.map",
|
||||
content: JSON.stringify({ version: 3, file: "a.d.ts", sourceRoot: "", sources: ["../a/a.ts"], names: [], mappings: "AAAA,iBAAS,CAAC,SAAK" }),
|
||||
content: jsonToReadableText({ version: 3, file: "a.d.ts", sourceRoot: "", sources: ["../a/a.ts"], names: [], mappings: "AAAA,iBAAS,CAAC,SAAK" }),
|
||||
};
|
||||
|
||||
const host = createServerHost([aTs, aTsconfig, bTs, bTsconfig, aDts, aDtsMap]);
|
||||
@@ -361,7 +364,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
|
||||
const aTs: File = { path: "/a/src/a.ts", content: "" };
|
||||
const aTsconfig: File = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
declaration: true,
|
||||
@@ -373,7 +376,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
|
||||
const bTs: File = { path: "/b/src/b.ts", content: "" };
|
||||
const bTsconfig: File = {
|
||||
path: "/b/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
outDir: "./build",
|
||||
@@ -403,7 +406,7 @@ describe("unittests:: tsserver:: with declaration file maps:: project references
|
||||
};
|
||||
const aDtsMapInlinedSources: File = {
|
||||
path: aDtsMap.path,
|
||||
content: JSON.stringify(aDtsInlinedSources),
|
||||
content: jsonToReadableText(aDtsInlinedSources),
|
||||
};
|
||||
const host = createServerHost([aTs, aDtsMapInlinedSources, aDts, bTs, bDtsMap, bDts, userTs, dummyFile]);
|
||||
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
|
||||
|
||||
@@ -5,6 +5,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../harness/tsserverLogger";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
closeFilesForSession,
|
||||
@@ -31,7 +34,7 @@ describe("unittests:: tsserver:: documentRegistry:: document registry in project
|
||||
};
|
||||
const configFile: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ files: ["index.ts"] }),
|
||||
content: jsonToReadableText({ files: ["index.ts"] }),
|
||||
};
|
||||
|
||||
function getProject(service: TestProjectService) {
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../harness/tsserverLogger";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createSession,
|
||||
@@ -16,7 +19,7 @@ describe("unittests:: tsserver:: duplicate packages", () => {
|
||||
// Tests that 'moduleSpecifiers.ts' will import from the redirecting file, and not from the file it redirects to, if that can provide a global module specifier.
|
||||
it("works with import fixes", () => {
|
||||
const packageContent = "export const foo: number;";
|
||||
const packageJsonContent = JSON.stringify({ name: "foo", version: "1.2.3" });
|
||||
const packageJsonContent = jsonToReadableText({ name: "foo", version: "1.2.3" });
|
||||
const aFooIndex: File = { path: "/a/node_modules/foo/index.d.ts", content: packageContent };
|
||||
const aFooPackage: File = { path: "/a/node_modules/foo/package.json", content: packageJsonContent };
|
||||
const bFooIndex: File = { path: "/b/node_modules/foo/index.d.ts", content: packageContent };
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../../harness/tsserverLogger";
|
||||
import * as ts from "../../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createSession,
|
||||
@@ -42,7 +45,7 @@ describe("unittests:: tsserver:: events:: LargeFileReferencedEvent with large fi
|
||||
};
|
||||
const tsconfig: File = {
|
||||
path: `/user/username/projects/myproject/tsconfig.json`,
|
||||
content: JSON.stringify({ files: ["src/file.ts", getLargeFile(useLargeTsFile)], compilerOptions: { target: 1, allowJs: true } }),
|
||||
content: jsonToReadableText({ files: ["src/file.ts", getLargeFile(useLargeTsFile)], compilerOptions: { target: 1, allowJs: true } }),
|
||||
};
|
||||
const files = [file, libFile, tsconfig];
|
||||
const session = createSessionWithEventHandler(files, useLargeTsFile);
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../../harness/tsserverLogger";
|
||||
import * as ts from "../../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createProjectService,
|
||||
@@ -30,7 +33,7 @@ describe("unittests:: tsserver:: events:: ProjectLanguageServiceStateEvent", ()
|
||||
};
|
||||
const configWithExclude = {
|
||||
path: config.path,
|
||||
content: JSON.stringify({ exclude: ["largefile.js"] }),
|
||||
content: jsonToReadableText({ exclude: ["largefile.js"] }),
|
||||
};
|
||||
const host = createServerHost([f1, f2, config]);
|
||||
const originalGetFileSize = host.getFileSize;
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../../harness/tsserverLogger";
|
||||
import * as ts from "../../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createSession,
|
||||
@@ -67,7 +70,7 @@ describe("unittests:: tsserver:: events:: ProjectLoadingStart and ProjectLoading
|
||||
};
|
||||
const configB: File = {
|
||||
path: configBPath,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
extends: "../a/tsconfig.json",
|
||||
}),
|
||||
};
|
||||
@@ -99,7 +102,7 @@ describe("unittests:: tsserver:: events:: ProjectLoadingStart and ProjectLoading
|
||||
};
|
||||
const aDTsMap: File = {
|
||||
path: `/user/username/projects/a/a.d.ts.map`,
|
||||
content: `{"version":3,"file":"a.d.ts","sourceRoot":"","sources":["./a.ts"],"names":[],"mappings":"AAAA,qBAAa,CAAC;CAAI"}`,
|
||||
content: jsonToReadableText({ version: 3, file: "a.d.ts", sourceRoot: "", sources: ["./a.ts"], names: [], mappings: "AAAA,qBAAa,CAAC;CAAI" }),
|
||||
};
|
||||
const bTs: File = {
|
||||
path: bTsPath,
|
||||
@@ -107,7 +110,7 @@ describe("unittests:: tsserver:: events:: ProjectLoadingStart and ProjectLoading
|
||||
};
|
||||
const configB: File = {
|
||||
path: configBPath,
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
...(disableSourceOfProjectReferenceRedirect && {
|
||||
compilerOptions: {
|
||||
disableSourceOfProjectReferenceRedirect,
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../../harness/tsserverLogger";
|
||||
import * as ts from "../../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createSession,
|
||||
@@ -52,7 +55,7 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {
|
||||
it(subScenario, () => {
|
||||
const config: File = {
|
||||
path: "/users/username/projects/project/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions,
|
||||
}),
|
||||
};
|
||||
@@ -125,7 +128,7 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {
|
||||
const additionalFiles = getAdditionalFileOrFolder ? getAdditionalFileOrFolder() : [];
|
||||
const configFile = {
|
||||
path: configFilePath,
|
||||
content: JSON.stringify(configObj || { compilerOptions: {} }),
|
||||
content: jsonToReadableText(configObj || { compilerOptions: {} }),
|
||||
};
|
||||
|
||||
const files: File[] = [file1Consumer1, moduleFile1, file1Consumer2, moduleFile2, ...additionalFiles, globalFile3, libFile, configFile];
|
||||
@@ -378,7 +381,7 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {
|
||||
};
|
||||
const configFile: File = {
|
||||
path: rootFolder + "a/b/project/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: { typeRoots: [] } }),
|
||||
content: jsonToReadableText({ compilerOptions: { typeRoots: [] } }),
|
||||
};
|
||||
|
||||
const host = createServerHost([file1, file3, libFile, configFile]);
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
createLoggerWithInMemoryLogs,
|
||||
} from "../../../harness/tsserverLogger";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createSession,
|
||||
@@ -34,7 +37,7 @@ const ambientDeclaration: File = {
|
||||
};
|
||||
const mobxPackageJson: File = {
|
||||
path: "/node_modules/mobx/package.json",
|
||||
content: `{ "name": "mobx", "version": "1.0.0" }`,
|
||||
content: jsonToReadableText({ name: "mobx", version: "1.0.0" }),
|
||||
};
|
||||
const mobxDts: File = {
|
||||
path: "/node_modules/mobx/index.d.ts",
|
||||
|
||||
@@ -3,6 +3,9 @@ import {
|
||||
} from "../../../harness/tsserverLogger";
|
||||
import * as Harness from "../../_namespaces/Harness";
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createProjectService,
|
||||
@@ -31,7 +34,7 @@ describe("unittests:: tsserver:: externalProjects", () => {
|
||||
};
|
||||
const config = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
include: [],
|
||||
}),
|
||||
};
|
||||
@@ -209,7 +212,7 @@ describe("unittests:: tsserver:: externalProjects", () => {
|
||||
};
|
||||
const config1 = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify(
|
||||
content: jsonToReadableText(
|
||||
{
|
||||
compilerOptions: {},
|
||||
files: ["f1.ts"],
|
||||
@@ -222,7 +225,7 @@ describe("unittests:: tsserver:: externalProjects", () => {
|
||||
};
|
||||
const config2 = {
|
||||
path: "/a/c/tsconfig.json",
|
||||
content: JSON.stringify(
|
||||
content: jsonToReadableText(
|
||||
{
|
||||
compilerOptions: {},
|
||||
files: ["f2.ts"],
|
||||
@@ -270,7 +273,7 @@ describe("unittests:: tsserver:: externalProjects", () => {
|
||||
};
|
||||
const configFile = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: {} }),
|
||||
content: jsonToReadableText({ compilerOptions: {} }),
|
||||
};
|
||||
const externalProjectName = "externalproject";
|
||||
const host = createServerHost([file1, configFile]);
|
||||
@@ -302,7 +305,7 @@ describe("unittests:: tsserver:: externalProjects", () => {
|
||||
};
|
||||
const configFile = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: {} }),
|
||||
content: jsonToReadableText({ compilerOptions: {} }),
|
||||
};
|
||||
const externalProjectName = "externalproject";
|
||||
const host = createServerHost([file1, file2, libFile, configFile]);
|
||||
@@ -600,7 +603,7 @@ describe("unittests:: tsserver:: externalProjects", () => {
|
||||
};
|
||||
const config1 = {
|
||||
path: "/src/tsconfig.json",
|
||||
content: JSON.stringify(
|
||||
content: jsonToReadableText(
|
||||
{
|
||||
compilerOptions: {
|
||||
module: "commonjs",
|
||||
@@ -616,7 +619,7 @@ describe("unittests:: tsserver:: externalProjects", () => {
|
||||
};
|
||||
const config2 = {
|
||||
path: config1.path,
|
||||
content: JSON.stringify(
|
||||
content: jsonToReadableText(
|
||||
{
|
||||
compilerOptions: {
|
||||
module: "commonjs",
|
||||
@@ -648,7 +651,7 @@ describe("unittests:: tsserver:: externalProjects", () => {
|
||||
};
|
||||
const config = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({
|
||||
content: jsonToReadableText({
|
||||
compilerOptions: {},
|
||||
include: [
|
||||
"src/**/*",
|
||||
@@ -675,7 +678,7 @@ describe("unittests:: tsserver:: externalProjects", () => {
|
||||
};
|
||||
const config = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({}),
|
||||
content: jsonToReadableText({}),
|
||||
};
|
||||
const projectFileName = "/a/b/project.csproj";
|
||||
const host = createServerHost([f1, config]);
|
||||
|
||||
Loaded 100 of 1709 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user