Merge branch 'baselining' into resolution

This commit is contained in:
Sheetal Nandi
2019-09-24 09:53:13 -07:00
121 changed files with 811 additions and 801 deletions

View File

@@ -1,7 +1,6 @@
namespace ts {
describe("unittests:: tsbuild:: outFile:: on amd modules with --out", () => {
let outFileFs: vfs.FileSystem;
const { time, tick } = getTime();
const enum project { lib, app }
function relName(path: string) { return path.slice(1); }
type Sources = [string, readonly string[]];
@@ -25,7 +24,7 @@ namespace ts {
]
];
before(() => {
outFileFs = loadProjectFromDisk("tests/projects/amdModulesWithOut", time);
outFileFs = loadProjectFromDisk("tests/projects/amdModulesWithOut");
});
after(() => {
outFileFs = undefined!;
@@ -46,7 +45,6 @@ namespace ts {
scenario: "amdModulesWithOut",
subScenario,
fs: () => outFileFs,
tick,
commandLineArgs: ["--b", "/src/app", "--verbose"],
baselineSourceMap: true,
modifyFs,

View File

@@ -1,10 +1,8 @@
namespace ts {
describe("unittests:: tsbuild:: on demo project", () => {
let projFs: vfs.FileSystem;
const { time } = getTime();
before(() => {
projFs = loadProjectFromDisk("tests/projects/demo", time);
projFs = loadProjectFromDisk("tests/projects/demo");
});
after(() => {

View File

@@ -1,9 +1,8 @@
namespace ts {
describe("unittests:: tsbuild:: on project with emitDeclarationOnly set to true", () => {
let projFs: vfs.FileSystem;
const { time, tick } = getTime();
before(() => {
projFs = loadProjectFromDisk("tests/projects/emitDeclarationOnly", time);
projFs = loadProjectFromDisk("tests/projects/emitDeclarationOnly");
});
after(() => {
projFs = undefined!;
@@ -13,7 +12,6 @@ namespace ts {
verifyTscIncrementalEdits({
subScenario: `only dts output in circular import project with emitDeclarationOnly${disableMap ? "" : " and declarationMap"}`,
fs: () => projFs,
tick,
scenario: "emitDeclarationOnly",
commandLineArgs: ["--b", "/src", "--verbose"],
modifyFs: disableMap ?
@@ -31,7 +29,6 @@ namespace ts {
verifyTscIncrementalEdits({
subScenario: `only dts output in non circular imports project with emitDeclarationOnly`,
fs: () => projFs,
tick,
scenario: "emitDeclarationOnly",
commandLineArgs: ["--b", "/src", "--verbose"],
modifyFs: fs => {

View File

@@ -113,9 +113,11 @@ interface Symbol {
}
`;
/**
* Load project from disk into /src folder
*/
export function loadProjectFromDisk(
root: string,
time?: vfs.FileSystemOptions["time"],
libContentToAppend?: string
): vfs.FileSystem {
const resolver = vfs.createResolver(Harness.IO);
@@ -125,22 +127,22 @@ interface Symbol {
},
cwd: "/",
meta: { defaultLibLocation: "/lib" },
time
});
addLibAndMakeReadonly(fs, libContentToAppend);
return fs;
}
/**
* All the files must be in /src
*/
export function loadProjectFromFiles(
files: vfs.FileSet,
time?: vfs.FileSystemOptions["time"],
libContentToAppend?: string
): vfs.FileSystem {
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
files,
cwd: "/",
meta: { defaultLibLocation: "/lib" },
time
});
addLibAndMakeReadonly(fs, libContentToAppend);
return fs;
@@ -152,6 +154,26 @@ interface Symbol {
fs.makeReadonly();
}
/**
* Gets the FS mountuing existing fs's /src and /lib folder
*/
export function getFsWithTime(baseFs: vfs.FileSystem) {
const { time, tick } = getTime();
const host = new fakes.System(baseFs) as any as vfs.FileSystemResolverHost;
host.getWorkspaceRoot = notImplemented;
const resolver = vfs.createResolver(host);
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
files: {
["/src"]: new vfs.Mount("/src", resolver),
["/lib"]: new vfs.Mount("/lib", resolver)
},
cwd: "/",
meta: { defaultLibLocation: "/lib" },
time
});
return { fs, time, tick };
}
export function verifyOutputsPresent(fs: vfs.FileSystem, outputs: readonly string[]) {
for (const output of outputs) {
assert(fs.existsSync(output), `Expect file ${output} to exist`);
@@ -257,22 +279,24 @@ interface Symbol {
}
export interface VerifyTsBuildInput extends TscCompile {
tick: () => void;
incrementalScenarios: TscIncremental[];
}
export function verifyTscIncrementalEdits({
subScenario, fs, tick, scenario, commandLineArgs,
subScenario, fs, scenario, commandLineArgs,
baselineSourceMap, modifyFs, baselineReadFileCalls,
incrementalScenarios
}: VerifyTsBuildInput) {
describe(`tsc --b ${scenario}:: ${subScenario}`, () => {
let tick: () => void;
let sys: TscCompileSystem;
before(() => {
let baseFs: vfs.FileSystem;
({ fs: baseFs, tick } = getFsWithTime(fs()));
sys = tscCompile({
scenario,
subScenario,
fs,
fs: () => baseFs.makeReadonly(),
commandLineArgs,
modifyFs: fs => {
if (modifyFs) modifyFs(fs);
@@ -285,6 +309,7 @@ interface Symbol {
});
after(() => {
sys = undefined!;
tick = undefined!;
});
describe("initialBuild", () => {
verifyTscBaseline(() => sys);

View File

@@ -1,9 +1,8 @@
namespace ts {
describe("unittests:: tsbuild:: inferredTypeFromTransitiveModule::", () => {
let projFs: vfs.FileSystem;
const { time, tick } = getTime();
before(() => {
projFs = loadProjectFromDisk("tests/projects/inferredTypeFromTransitiveModule", time);
projFs = loadProjectFromDisk("tests/projects/inferredTypeFromTransitiveModule");
});
after(() => {
projFs = undefined!;
@@ -13,7 +12,6 @@ namespace ts {
scenario: "inferredTypeFromTransitiveModule",
subScenario: "inferred type from transitive module",
fs: () => projFs,
tick,
commandLineArgs: ["--b", "/src", "--verbose"],
incrementalScenarios: [{
buildKind: BuildKind.IncrementalDtsChange,
@@ -24,7 +22,6 @@ namespace ts {
verifyTscIncrementalEdits({
subScenario: "inferred type from transitive module with isolatedModules",
fs: () => projFs,
tick,
scenario: "inferredTypeFromTransitiveModule",
commandLineArgs: ["--b", "/src", "--verbose"],
modifyFs: changeToIsolatedModules,
@@ -38,7 +35,6 @@ namespace ts {
scenario: "inferredTypeFromTransitiveModule",
subScenario: "reports errors in files affected by change in signature with isolatedModules",
fs: () => projFs,
tick,
commandLineArgs: ["--b", "/src", "--verbose"],
modifyFs: fs => {
changeToIsolatedModules(fs);

View File

@@ -1,9 +1,8 @@
namespace ts {
describe("unittests:: tsbuild:: lateBoundSymbol:: interface is merged and contains late bound member", () => {
let projFs: vfs.FileSystem;
const { time, tick } = getTime();
before(() => {
projFs = loadProjectFromDisk("tests/projects/lateBoundSymbol", time);
projFs = loadProjectFromDisk("tests/projects/lateBoundSymbol");
});
after(() => {
projFs = undefined!; // Release the contents
@@ -12,7 +11,6 @@ namespace ts {
verifyTscIncrementalEdits({
subScenario: "interface is merged and contains late bound member",
fs: () => projFs,
tick,
scenario: "lateBoundSymbol",
commandLineArgs: ["--b", "/src/tsconfig.json", "--verbose"],
incrementalScenarios: [{

View File

@@ -1,17 +1,16 @@
namespace ts {
// https://github.com/microsoft/TypeScript/issues/31696
describe("unittests:: tsbuild:: moduleSpecifiers:: synthesized module specifiers to referenced projects resolve correctly", () => {
const { time } = getTime();
verifyTsc({
scenario: "moduleSpecifiers",
subScenario: `synthesized module specifiers resolve correctly`,
fs: () => loadProjectFromFiles({
"/src/common/nominal.ts": utils.dedent`
"/src/solution/common/nominal.ts": utils.dedent`
export declare type Nominal<T, Name extends string> = T & {
[Symbol.species]: Name;
};
`,
"/src/common/tsconfig.json": utils.dedent`
"/src/solution/common/tsconfig.json": utils.dedent`
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
@@ -19,12 +18,12 @@ namespace ts {
},
"include": ["nominal.ts"]
}`,
"/src/sub-project/index.ts": utils.dedent`
"/src/solution/sub-project/index.ts": utils.dedent`
import { Nominal } from '../common/nominal';
export type MyNominal = Nominal<string, 'MyNominal'>;
`,
"/src/sub-project/tsconfig.json": utils.dedent`
"/src/solution/sub-project/tsconfig.json": utils.dedent`
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
@@ -35,7 +34,7 @@ namespace ts {
],
"include": ["./index.ts"]
}`,
"/src/sub-project-2/index.ts": utils.dedent`
"/src/solution/sub-project-2/index.ts": utils.dedent`
import { MyNominal } from '../sub-project/index';
const variable = {
@@ -46,7 +45,7 @@ namespace ts {
return 'key';
}
`,
"/src/sub-project-2/tsconfig.json": utils.dedent`
"/src/solution/sub-project-2/tsconfig.json": utils.dedent`
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
@@ -57,7 +56,7 @@ namespace ts {
],
"include": ["./index.ts"]
}`,
"/src/tsconfig.json": utils.dedent`
"/src/solution/tsconfig.json": utils.dedent`
{
"compilerOptions": {
"composite": true
@@ -68,7 +67,7 @@ namespace ts {
],
"include": []
}`,
"/tsconfig.base.json": utils.dedent`
"/src/tsconfig.base.json": utils.dedent`
{
"compilerOptions": {
"skipLibCheck": true,
@@ -76,17 +75,17 @@ namespace ts {
"outDir": "lib",
}
}`,
"/tsconfig.json": utils.dedent`{
"/src/tsconfig.json": utils.dedent`{
"compilerOptions": {
"composite": true
},
"references": [
{ "path": "./src" }
{ "path": "./solution" }
],
"include": []
}`
}, time, symbolLibContent),
commandLineArgs: ["-b", "/", "--verbose"]
}, symbolLibContent),
commandLineArgs: ["-b", "/src", "--verbose"]
});
});
}

View File

@@ -56,7 +56,6 @@ namespace ts {
]
];
const relSources = sources.map(([config, sources]) => [relName(config), sources.map(relName)]) as any as [Sources, Sources, Sources];
const { time, tick } = getTime();
let expectedOutputFiles = [
...outputFiles[project.first],
...outputFiles[project.second],
@@ -72,7 +71,7 @@ namespace ts {
[Diagnostics.Building_project_0, sources[project.third][source.config]]
];
before(() => {
outFileFs = loadProjectFromDisk("tests/projects/outfile-concat", time);
outFileFs = loadProjectFromDisk("tests/projects/outfile-concat");
});
after(() => {
outFileFs = undefined!;
@@ -123,7 +122,6 @@ namespace ts {
const input: VerifyTsBuildInput = {
subScenario,
fs: () => outFileFs,
tick,
scenario: "outfile-concat",
commandLineArgs: ["--b", "/src/third", "--verbose"],
baselineSourceMap: true,
@@ -191,7 +189,7 @@ namespace ts {
});
it("verify buildInfo absence results in new build", () => {
const fs = outFileFs.shadow();
const { fs, tick } = getFsWithTime(outFileFs);
const expectedOutputs = [
...outputFiles[project.first],
...outputFiles[project.second],
@@ -205,7 +203,11 @@ namespace ts {
verifyOutputsPresent(fs, expectedOutputs);
// Delete bundle info
host.clearDiagnostics();
tick();
host.deleteFile(outputFiles[project.first][ext.buildinfo]);
tick();
builder = createSolutionBuilder(host);
builder.build();
host.assertDiagnosticMessages(
@@ -232,14 +234,16 @@ namespace ts {
});
it("rebuilds completely when version in tsbuildinfo doesnt match ts version", () => {
const fs = outFileFs.shadow();
const { fs, tick } = getFsWithTime(outFileFs);
const host = fakes.SolutionBuilderHost.create(fs);
let builder = createSolutionBuilder(host);
builder.build();
host.assertDiagnosticMessages(...initialExpectedDiagnostics);
host.clearDiagnostics();
tick();
builder = createSolutionBuilder(host);
changeCompilerVersion(host);
tick();
builder.build();
host.assertDiagnosticMessages(
getExpectedDiagnosticForProjectsInBuild(relSources[project.first][source.config], relSources[project.second][source.config], relSources[project.third][source.config]),
@@ -253,7 +257,7 @@ namespace ts {
});
it("rebuilds completely when command line incremental flag changes between non dts changes", () => {
const fs = outFileFs.shadow();
const { fs, tick } = getFsWithTime(outFileFs);
// Make non composite third project
replaceText(fs, sources[project.third][source.config], `"composite": true,`, "");

View File

@@ -1,10 +1,9 @@
namespace ts {
describe("unittests:: tsbuild:: with resolveJsonModule option on project resolveJsonModuleAndComposite", () => {
let projFs: vfs.FileSystem;
const { time, tick } = getTime();
const allExpectedOutputs = ["/src/dist/src/index.js", "/src/dist/src/index.d.ts", "/src/dist/src/hello.json"];
before(() => {
projFs = loadProjectFromDisk("tests/projects/resolveJsonModuleAndComposite", time);
projFs = loadProjectFromDisk("tests/projects/resolveJsonModuleAndComposite");
});
after(() => {
@@ -65,7 +64,7 @@ export default hello.hello`);
});
it("with resolveJsonModule and sourceMap", () => {
const fs = projFs.shadow();
const { fs, tick } = getFsWithTime(projFs);
const configFile = "src/tsconfig_withFiles.json";
replaceText(fs, configFile, `"composite": true,`, `"composite": true, "sourceMap": true,`);
const host = fakes.SolutionBuilderHost.create(fs);
@@ -88,7 +87,7 @@ export default hello.hello`);
});
it("with resolveJsonModule and without outDir", () => {
const fs = projFs.shadow();
const { fs, tick } = getFsWithTime(projFs);
const configFile = "src/tsconfig_withFiles.json";
replaceText(fs, configFile, `"outDir": "dist",`, "");
const host = fakes.SolutionBuilderHost.create(fs);
@@ -112,10 +111,9 @@ export default hello.hello`);
});
describe("unittests:: tsbuild:: with resolveJsonModule option on project importJsonFromProjectReference", () => {
const { time, tick } = getTime();
let projFs: vfs.FileSystem;
before(() => {
projFs = loadProjectFromDisk("tests/projects/importJsonFromProjectReference", time);
projFs = loadProjectFromDisk("tests/projects/importJsonFromProjectReference");
});
after(() => {
@@ -124,7 +122,7 @@ export default hello.hello`);
it("when importing json module from project reference", () => {
const expectedOutput = "/src/main/index.js";
const fs = projFs.shadow();
const { fs, tick } = getFsWithTime(projFs);
const configFile = "src/tsconfig.json";
const stringsConfigFile = "src/strings/tsconfig.json";
const mainConfigFile = "src/main/tsconfig.json";

View File

@@ -1,14 +1,13 @@
namespace ts {
describe("unittests:: tsbuild:: on 'sample1' project", () => {
let projFs: vfs.FileSystem;
const { time, tick } = getTime();
const testsOutputs = ["/src/tests/index.js", "/src/tests/index.d.ts", "/src/tests/tsconfig.tsbuildinfo"];
const logicOutputs = ["/src/logic/index.js", "/src/logic/index.js.map", "/src/logic/index.d.ts", "/src/logic/tsconfig.tsbuildinfo"];
const coreOutputs = ["/src/core/index.js", "/src/core/index.d.ts", "/src/core/index.d.ts.map", "/src/core/tsconfig.tsbuildinfo"];
const allExpectedOutputs = [...testsOutputs, ...logicOutputs, ...coreOutputs];
before(() => {
projFs = loadProjectFromDisk("tests/projects/sample1", time);
projFs = loadProjectFromDisk("tests/projects/sample1");
});
after(() => {
@@ -93,7 +92,7 @@ namespace ts {
});
it("indicates that it would skip builds during a dry build", () => {
const fs = projFs.shadow();
const { fs, tick } = getFsWithTime(projFs);
const host = fakes.SolutionBuilderHost.create(fs);
let builder = createSolutionBuilder(host, ["/src/tests"], { dry: false, force: false, verbose: false });
@@ -160,7 +159,7 @@ namespace ts {
describe("force builds", () => {
it("always builds under --force", () => {
const fs = projFs.shadow();
const { fs, time, tick } = getFsWithTime(projFs);
const host = fakes.SolutionBuilderHost.create(fs);
let builder = createSolutionBuilder(host, ["/src/tests"], { dry: false, force: true, verbose: false });
@@ -187,7 +186,7 @@ namespace ts {
describe("can detect when and what to rebuild", () => {
function initializeWithBuild(opts?: BuildOptions) {
const fs = projFs.shadow();
const { fs, tick } = getFsWithTime(projFs);
const host = fakes.SolutionBuilderHost.create(fs);
let builder = createSolutionBuilder(host, ["/src/tests"], { verbose: true });
builder.build();
@@ -273,7 +272,7 @@ namespace ts {
});
it("does not rebuild if there is no program and bundle in the ts build info event if version doesnt match ts version", () => {
const fs = projFs.shadow();
const { fs, tick } = getFsWithTime(projFs);
const host = fakes.SolutionBuilderHost.create(fs, /*options*/ undefined, /*setParentNodes*/ undefined, createAbstractBuilder);
let builder = createSolutionBuilder(host, ["/src/tests"], { verbose: true });
builder.build();
@@ -329,7 +328,7 @@ namespace ts {
});
it("rebuilds when extended config file changes", () => {
const fs = projFs.shadow();
const { fs, tick } = getFsWithTime(projFs);
fs.writeFileSync("/src/tests/tsconfig.base.json", JSON.stringify({ compilerOptions: { target: "es3" } }));
replaceText(fs, "/src/tests/tsconfig.json", `"references": [`, `"extends": "./tsconfig.base.json", "references": [`);
const host = fakes.SolutionBuilderHost.create(fs);
@@ -462,7 +461,7 @@ namespace ts {
describe("project invalidation", () => {
it("invalidates projects correctly", () => {
const fs = projFs.shadow();
const { fs, time, tick } = getFsWithTime(projFs);
const host = fakes.SolutionBuilderHost.create(fs);
const builder = createSolutionBuilder(host, ["/src/tests"], { dry: false, force: false, verbose: false });
@@ -571,7 +570,6 @@ export class cNew {}`);
verifyTscIncrementalEdits({
subScenario: "sample",
fs: () => projFs,
tick,
scenario: "sample1",
commandLineArgs: ["--b", "/src/tests", "--verbose"],
baselineSourceMap: true,
@@ -610,7 +608,6 @@ class someClass { }`),
verifyTscIncrementalEdits({
subScenario: "when declaration option changes",
fs: () => projFs,
tick,
scenario: "sample1",
commandLineArgs: ["--b", "/src/core", "--verbose"],
modifyFs: fs => fs.writeFileSync("/src/core/tsconfig.json", `{
@@ -628,7 +625,6 @@ class someClass { }`),
verifyTscIncrementalEdits({
subScenario: "when target option changes",
fs: () => projFs,
tick,
scenario: "sample1",
commandLineArgs: ["--b", "/src/core", "--verbose"],
modifyFs: fs => {
@@ -655,7 +651,6 @@ class someClass { }`),
verifyTscIncrementalEdits({
subScenario: "when module option changes",
fs: () => projFs,
tick,
scenario: "sample1",
commandLineArgs: ["--b", "/src/core", "--verbose"],
modifyFs: fs => fs.writeFileSync("/src/core/tsconfig.json", `{
@@ -673,7 +668,6 @@ class someClass { }`),
verifyTscIncrementalEdits({
subScenario: "when esModuleInterop option changes",
fs: () => projFs,
tick,
scenario: "sample1",
commandLineArgs: ["--b", "/src/tests", "--verbose"],
modifyFs: fs => fs.writeFileSync("/src/tests/tsconfig.json", `{

View File

@@ -228,7 +228,10 @@ namespace ts {
describe(input.subScenario, () => {
let sys: TscCompileSystem;
before(() => {
sys = tscCompile(input);
sys = tscCompile({
...input,
fs: () => getFsWithTime(input.fs()).fs.makeReadonly()
});
});
after(() => {
sys = undefined!;