Skip to content

Commit 096d6db

Browse files
committed
Make time and tick local to test case so it doesnt affect the baseline
1 parent b762770 commit 096d6db

File tree

121 files changed

+803
-799
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+803
-799
lines changed

src/testRunner/unittests/tsbuild/amdModulesWithOut.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: outFile:: on amd modules with --out", () => {
33
let outFileFs: vfs.FileSystem;
4-
const { time, tick } = getTime();
54
const enum project { lib, app }
65
function relName(path: string) { return path.slice(1); }
76
type Sources = [string, readonly string[]];
@@ -25,7 +24,7 @@ namespace ts {
2524
]
2625
];
2726
before(() => {
28-
outFileFs = loadProjectFromDisk("tests/projects/amdModulesWithOut", time);
27+
outFileFs = loadProjectFromDisk("tests/projects/amdModulesWithOut");
2928
});
3029
after(() => {
3130
outFileFs = undefined!;
@@ -46,7 +45,6 @@ namespace ts {
4645
scenario: "amdModulesWithOut",
4746
subScenario,
4847
fs: () => outFileFs,
49-
tick,
5048
commandLineArgs: ["--b", "/src/app", "--verbose"],
5149
baselineSourceMap: true,
5250
modifyFs,

src/testRunner/unittests/tsbuild/demo.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: on demo project", () => {
33
let projFs: vfs.FileSystem;
4-
const { time } = getTime();
5-
64
before(() => {
7-
projFs = loadProjectFromDisk("tests/projects/demo", time);
5+
projFs = loadProjectFromDisk("tests/projects/demo");
86
});
97

108
after(() => {

src/testRunner/unittests/tsbuild/emitDeclarationOnly.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: on project with emitDeclarationOnly set to true", () => {
33
let projFs: vfs.FileSystem;
4-
const { time, tick } = getTime();
54
before(() => {
6-
projFs = loadProjectFromDisk("tests/projects/emitDeclarationOnly", time);
5+
projFs = loadProjectFromDisk("tests/projects/emitDeclarationOnly");
76
});
87
after(() => {
98
projFs = undefined!;
@@ -13,7 +12,6 @@ namespace ts {
1312
verifyTscIncrementalEdits({
1413
subScenario: `only dts output in circular import project with emitDeclarationOnly${disableMap ? "" : " and declarationMap"}`,
1514
fs: () => projFs,
16-
tick,
1715
scenario: "emitDeclarationOnly",
1816
commandLineArgs: ["--b", "/src", "--verbose"],
1917
modifyFs: disableMap ?
@@ -31,7 +29,6 @@ namespace ts {
3129
verifyTscIncrementalEdits({
3230
subScenario: `only dts output in non circular imports project with emitDeclarationOnly`,
3331
fs: () => projFs,
34-
tick,
3532
scenario: "emitDeclarationOnly",
3633
commandLineArgs: ["--b", "/src", "--verbose"],
3734
modifyFs: fs => {

src/testRunner/unittests/tsbuild/helpers.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ interface Symbol {
113113
}
114114
`;
115115

116+
/**
117+
* Load project from disk into /src folder
118+
*/
116119
export function loadProjectFromDisk(
117120
root: string,
118-
time?: vfs.FileSystemOptions["time"],
119121
libContentToAppend?: string
120122
): vfs.FileSystem {
121123
const resolver = vfs.createResolver(Harness.IO);
@@ -125,22 +127,22 @@ interface Symbol {
125127
},
126128
cwd: "/",
127129
meta: { defaultLibLocation: "/lib" },
128-
time
129130
});
130131
addLibAndMakeReadonly(fs, libContentToAppend);
131132
return fs;
132133
}
133134

135+
/**
136+
* All the files must be in /src
137+
*/
134138
export function loadProjectFromFiles(
135139
files: vfs.FileSet,
136-
time?: vfs.FileSystemOptions["time"],
137140
libContentToAppend?: string
138141
): vfs.FileSystem {
139142
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
140143
files,
141144
cwd: "/",
142145
meta: { defaultLibLocation: "/lib" },
143-
time
144146
});
145147
addLibAndMakeReadonly(fs, libContentToAppend);
146148
return fs;
@@ -152,6 +154,26 @@ interface Symbol {
152154
fs.makeReadonly();
153155
}
154156

157+
/**
158+
* Gets the FS mountuing existing fs's /src and /lib folder
159+
*/
160+
export function getFsWithTime(baseFs: vfs.FileSystem) {
161+
const { time, tick } = getTime();
162+
const host = new fakes.System(baseFs) as any as vfs.FileSystemResolverHost;
163+
host.getWorkspaceRoot = notImplemented;
164+
const resolver = vfs.createResolver(host);
165+
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
166+
files: {
167+
["/src"]: new vfs.Mount("/src", resolver),
168+
["/lib"]: new vfs.Mount("/lib", resolver)
169+
},
170+
cwd: "/",
171+
meta: { defaultLibLocation: "/lib" },
172+
time
173+
});
174+
return { fs, time, tick };
175+
}
176+
155177
export function verifyOutputsPresent(fs: vfs.FileSystem, outputs: readonly string[]) {
156178
for (const output of outputs) {
157179
assert(fs.existsSync(output), `Expect file ${output} to exist`);
@@ -257,22 +279,24 @@ interface Symbol {
257279
}
258280

259281
export interface VerifyTsBuildInput extends TscCompile {
260-
tick: () => void;
261282
incrementalScenarios: TscIncremental[];
262283
}
263284

264285
export function verifyTscIncrementalEdits({
265-
subScenario, fs, tick, scenario, commandLineArgs,
286+
subScenario, fs, scenario, commandLineArgs,
266287
baselineSourceMap, modifyFs, baselineReadFileCalls,
267288
incrementalScenarios
268289
}: VerifyTsBuildInput) {
269290
describe(`tsc --b ${scenario}:: ${subScenario}`, () => {
291+
let tick: () => void;
270292
let sys: TscCompileSystem;
271293
before(() => {
294+
let baseFs: vfs.FileSystem;
295+
({ fs: baseFs, tick } = getFsWithTime(fs()));
272296
sys = tscCompile({
273297
scenario,
274298
subScenario,
275-
fs,
299+
fs: () => baseFs.makeReadonly(),
276300
commandLineArgs,
277301
modifyFs: fs => {
278302
if (modifyFs) modifyFs(fs);
@@ -285,6 +309,7 @@ interface Symbol {
285309
});
286310
after(() => {
287311
sys = undefined!;
312+
tick = undefined!;
288313
});
289314
describe("initialBuild", () => {
290315
verifyTscBaseline(() => sys);

src/testRunner/unittests/tsbuild/inferredTypeFromTransitiveModule.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: inferredTypeFromTransitiveModule::", () => {
33
let projFs: vfs.FileSystem;
4-
const { time, tick } = getTime();
54
before(() => {
6-
projFs = loadProjectFromDisk("tests/projects/inferredTypeFromTransitiveModule", time);
5+
projFs = loadProjectFromDisk("tests/projects/inferredTypeFromTransitiveModule");
76
});
87
after(() => {
98
projFs = undefined!;
@@ -13,7 +12,6 @@ namespace ts {
1312
scenario: "inferredTypeFromTransitiveModule",
1413
subScenario: "inferred type from transitive module",
1514
fs: () => projFs,
16-
tick,
1715
commandLineArgs: ["--b", "/src", "--verbose"],
1816
incrementalScenarios: [{
1917
buildKind: BuildKind.IncrementalDtsChange,
@@ -24,7 +22,6 @@ namespace ts {
2422
verifyTscIncrementalEdits({
2523
subScenario: "inferred type from transitive module with isolatedModules",
2624
fs: () => projFs,
27-
tick,
2825
scenario: "inferredTypeFromTransitiveModule",
2926
commandLineArgs: ["--b", "/src", "--verbose"],
3027
modifyFs: changeToIsolatedModules,
@@ -38,7 +35,6 @@ namespace ts {
3835
scenario: "inferredTypeFromTransitiveModule",
3936
subScenario: "reports errors in files affected by change in signature with isolatedModules",
4037
fs: () => projFs,
41-
tick,
4238
commandLineArgs: ["--b", "/src", "--verbose"],
4339
modifyFs: fs => {
4440
changeToIsolatedModules(fs);

src/testRunner/unittests/tsbuild/lateBoundSymbol.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: lateBoundSymbol:: interface is merged and contains late bound member", () => {
33
let projFs: vfs.FileSystem;
4-
const { time, tick } = getTime();
54
before(() => {
6-
projFs = loadProjectFromDisk("tests/projects/lateBoundSymbol", time);
5+
projFs = loadProjectFromDisk("tests/projects/lateBoundSymbol");
76
});
87
after(() => {
98
projFs = undefined!; // Release the contents
@@ -12,7 +11,6 @@ namespace ts {
1211
verifyTscIncrementalEdits({
1312
subScenario: "interface is merged and contains late bound member",
1413
fs: () => projFs,
15-
tick,
1614
scenario: "lateBoundSymbol",
1715
commandLineArgs: ["--b", "/src/tsconfig.json", "--verbose"],
1816
incrementalScenarios: [{
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
namespace ts {
22
// https://github.com/microsoft/TypeScript/issues/31696
33
describe("unittests:: tsbuild:: moduleSpecifiers:: synthesized module specifiers to referenced projects resolve correctly", () => {
4-
const { time } = getTime();
54
verifyTsc({
65
scenario: "moduleSpecifiers",
76
subScenario: `synthesized module specifiers resolve correctly`,
87
fs: () => loadProjectFromFiles({
9-
"/src/common/nominal.ts": utils.dedent`
8+
"/src/solution/common/nominal.ts": utils.dedent`
109
export declare type Nominal<T, Name extends string> = T & {
1110
[Symbol.species]: Name;
1211
};
1312
`,
14-
"/src/common/tsconfig.json": utils.dedent`
13+
"/src/solution/common/tsconfig.json": utils.dedent`
1514
{
1615
"extends": "../../tsconfig.base.json",
1716
"compilerOptions": {
1817
"composite": true
1918
},
2019
"include": ["nominal.ts"]
2120
}`,
22-
"/src/sub-project/index.ts": utils.dedent`
21+
"/src/solution/sub-project/index.ts": utils.dedent`
2322
import { Nominal } from '../common/nominal';
2423
2524
export type MyNominal = Nominal<string, 'MyNominal'>;
2625
`,
27-
"/src/sub-project/tsconfig.json": utils.dedent`
26+
"/src/solution/sub-project/tsconfig.json": utils.dedent`
2827
{
2928
"extends": "../../tsconfig.base.json",
3029
"compilerOptions": {
@@ -35,7 +34,7 @@ namespace ts {
3534
],
3635
"include": ["./index.ts"]
3736
}`,
38-
"/src/sub-project-2/index.ts": utils.dedent`
37+
"/src/solution/sub-project-2/index.ts": utils.dedent`
3938
import { MyNominal } from '../sub-project/index';
4039
4140
const variable = {
@@ -46,7 +45,7 @@ namespace ts {
4645
return 'key';
4746
}
4847
`,
49-
"/src/sub-project-2/tsconfig.json": utils.dedent`
48+
"/src/solution/sub-project-2/tsconfig.json": utils.dedent`
5049
{
5150
"extends": "../../tsconfig.base.json",
5251
"compilerOptions": {
@@ -57,7 +56,7 @@ namespace ts {
5756
],
5857
"include": ["./index.ts"]
5958
}`,
60-
"/src/tsconfig.json": utils.dedent`
59+
"/src/solution/tsconfig.json": utils.dedent`
6160
{
6261
"compilerOptions": {
6362
"composite": true
@@ -68,25 +67,25 @@ namespace ts {
6867
],
6968
"include": []
7069
}`,
71-
"/tsconfig.base.json": utils.dedent`
70+
"/src/tsconfig.base.json": utils.dedent`
7271
{
7372
"compilerOptions": {
7473
"skipLibCheck": true,
7574
"rootDir": "./",
7675
"outDir": "lib",
7776
}
7877
}`,
79-
"/tsconfig.json": utils.dedent`{
78+
"/src/tsconfig.json": utils.dedent`{
8079
"compilerOptions": {
8180
"composite": true
8281
},
8382
"references": [
84-
{ "path": "./src" }
83+
{ "path": "./solution" }
8584
],
8685
"include": []
8786
}`
88-
}, time, symbolLibContent),
89-
commandLineArgs: ["-b", "/", "--verbose"]
87+
}, symbolLibContent),
88+
commandLineArgs: ["-b", "/src", "--verbose"]
9089
});
9190
});
9291
}

src/testRunner/unittests/tsbuild/outFile.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ namespace ts {
5656
]
5757
];
5858
const relSources = sources.map(([config, sources]) => [relName(config), sources.map(relName)]) as any as [Sources, Sources, Sources];
59-
const { time, tick } = getTime();
6059
let expectedOutputFiles = [
6160
...outputFiles[project.first],
6261
...outputFiles[project.second],
@@ -72,7 +71,7 @@ namespace ts {
7271
[Diagnostics.Building_project_0, sources[project.third][source.config]]
7372
];
7473
before(() => {
75-
outFileFs = loadProjectFromDisk("tests/projects/outfile-concat", time);
74+
outFileFs = loadProjectFromDisk("tests/projects/outfile-concat");
7675
});
7776
after(() => {
7877
outFileFs = undefined!;
@@ -123,7 +122,6 @@ namespace ts {
123122
const input: VerifyTsBuildInput = {
124123
subScenario,
125124
fs: () => outFileFs,
126-
tick,
127125
scenario: "outfile-concat",
128126
commandLineArgs: ["--b", "/src/third", "--verbose"],
129127
baselineSourceMap: true,
@@ -253,7 +251,7 @@ namespace ts {
253251
});
254252

255253
it("rebuilds completely when command line incremental flag changes between non dts changes", () => {
256-
const fs = outFileFs.shadow();
254+
const { fs, tick } = getFsWithTime(outFileFs);
257255
// Make non composite third project
258256
replaceText(fs, sources[project.third][source.config], `"composite": true,`, "");
259257

src/testRunner/unittests/tsbuild/resolveJsonModule.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: with resolveJsonModule option on project resolveJsonModuleAndComposite", () => {
33
let projFs: vfs.FileSystem;
4-
const { time, tick } = getTime();
54
const allExpectedOutputs = ["/src/dist/src/index.js", "/src/dist/src/index.d.ts", "/src/dist/src/hello.json"];
65
before(() => {
7-
projFs = loadProjectFromDisk("tests/projects/resolveJsonModuleAndComposite", time);
6+
projFs = loadProjectFromDisk("tests/projects/resolveJsonModuleAndComposite");
87
});
98

109
after(() => {
@@ -65,7 +64,7 @@ export default hello.hello`);
6564
});
6665

6766
it("with resolveJsonModule and sourceMap", () => {
68-
const fs = projFs.shadow();
67+
const { fs, tick } = getFsWithTime(projFs);
6968
const configFile = "src/tsconfig_withFiles.json";
7069
replaceText(fs, configFile, `"composite": true,`, `"composite": true, "sourceMap": true,`);
7170
const host = fakes.SolutionBuilderHost.create(fs);
@@ -88,7 +87,7 @@ export default hello.hello`);
8887
});
8988

9089
it("with resolveJsonModule and without outDir", () => {
91-
const fs = projFs.shadow();
90+
const { fs, tick } = getFsWithTime(projFs);
9291
const configFile = "src/tsconfig_withFiles.json";
9392
replaceText(fs, configFile, `"outDir": "dist",`, "");
9493
const host = fakes.SolutionBuilderHost.create(fs);
@@ -112,10 +111,9 @@ export default hello.hello`);
112111
});
113112

114113
describe("unittests:: tsbuild:: with resolveJsonModule option on project importJsonFromProjectReference", () => {
115-
const { time, tick } = getTime();
116114
let projFs: vfs.FileSystem;
117115
before(() => {
118-
projFs = loadProjectFromDisk("tests/projects/importJsonFromProjectReference", time);
116+
projFs = loadProjectFromDisk("tests/projects/importJsonFromProjectReference");
119117
});
120118

121119
after(() => {
@@ -124,7 +122,7 @@ export default hello.hello`);
124122

125123
it("when importing json module from project reference", () => {
126124
const expectedOutput = "/src/main/index.js";
127-
const fs = projFs.shadow();
125+
const { fs, tick } = getFsWithTime(projFs);
128126
const configFile = "src/tsconfig.json";
129127
const stringsConfigFile = "src/strings/tsconfig.json";
130128
const mainConfigFile = "src/main/tsconfig.json";

0 commit comments

Comments
 (0)