Skip to content

Commit 131890a

Browse files
committed
Add vfs diff, update tsbuild test
1 parent 61fb222 commit 131890a

8 files changed

Lines changed: 388 additions & 147 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@types/minimatch": "latest",
4646
"@types/minimist": "latest",
4747
"@types/mkdirp": "latest",
48-
"@types/mocha": "latest",
48+
"@types/mocha": "^5.2.2",
4949
"@types/node": "8.5.5",
5050
"@types/q": "latest",
5151
"@types/run-sequence": "latest",

src/harness/vfs.ts

Lines changed: 248 additions & 21 deletions
Large diffs are not rendered by default.

src/testRunner/unittests/tsbuild.ts

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ts {
1212

1313
export namespace Sample1 {
1414
tick();
15-
const projFs = loadProjectFromDisk("../../tests/projects/sample1");
15+
const projFs = loadProjectFromDisk("tests/projects/sample1");
1616

1717
const allExpectedOutputs = ["/src/tests/index.js",
1818
"/src/core/index.js", "/src/core/index.d.ts",
@@ -236,40 +236,33 @@ namespace ts {
236236
}
237237

238238
export namespace OutFile {
239-
const outFileFs = loadProjectFromDisk("../../tests/projects/outfile-concat");
239+
const outFileFs = loadProjectFromDisk("tests/projects/outfile-concat");
240240

241241
describe("tsbuild - baseline sectioned sourcemaps", () => {
242-
const fs = outFileFs.shadow();
243-
const host = new fakes.CompilerHost(fs);
244-
const builder = createSolutionBuilder(host, buildHost, ["/src/third"], { dry: false, force: false, verbose: false });
245-
clearDiagnostics();
246-
builder.buildAllProjects();
247-
assertDiagnosticMessages(/*none*/);
248-
249-
const files = [
250-
"/src/third/thirdjs/output/third-output.js",
251-
"/src/third/thirdjs/output/third-output.js.map"
252-
];
253-
254-
for (const file of files) {
255-
it(`Generates files matching the baseline - ${file}`, () => {
256-
Harness.Baseline.runBaseline(getBaseFileName(file), () => {
257-
return fs.readFileSync(file, "utf-8");
258-
});
259-
});
260-
}
261-
262-
it(`Generates files matching the baseline - file listing for outFile-concat`, () => {
263-
Harness.Baseline.runBaseline("outfile-concat-fileListing.txt", () => {
264-
return fs.getFileListing();
242+
let fs: vfs.FileSystem | undefined;
243+
before(() => {
244+
fs = outFileFs.shadow();
245+
const host = new fakes.CompilerHost(fs);
246+
const builder = createSolutionBuilder(host, buildHost, ["/src/third"], { dry: false, force: false, verbose: false });
247+
clearDiagnostics();
248+
builder.buildAllProjects();
249+
assertDiagnosticMessages(/*none*/);
250+
});
251+
after(() => {
252+
fs = undefined;
253+
});
254+
it(`Generates files matching the baseline`, () => {
255+
Harness.Baseline.runBaseline("outfile-concat.js", () => {
256+
const patch = fs!.diff();
257+
// tslint:disable-next-line:no-null-keyword
258+
return patch ? vfs.formatPatch(patch) : null;
265259
});
266260
});
267261
});
268262
}
269263

270264
describe("tsbuild - graph-ordering", () => {
271-
const fs = new vfs.FileSystem(false);
272-
const host = new fakes.CompilerHost(fs);
265+
let host: fakes.CompilerHost | undefined;
273266
const deps: [string, string][] = [
274267
["A", "B"],
275268
["B", "C"],
@@ -280,7 +273,15 @@ namespace ts {
280273
["F", "E"]
281274
];
282275

283-
writeProjects(fs, ["A", "B", "C", "D", "E", "F", "G"], deps);
276+
before(() => {
277+
const fs = new vfs.FileSystem(false);
278+
host = new fakes.CompilerHost(fs);
279+
writeProjects(fs, ["A", "B", "C", "D", "E", "F", "G"], deps);
280+
});
281+
282+
after(() => {
283+
host = undefined;
284+
});
284285

285286
it("orders the graph correctly - specify two roots", () => {
286287
checkGraphOrdering(["A", "G"], ["A", "B", "C", "D", "E", "G"]);
@@ -299,7 +300,7 @@ namespace ts {
299300
});
300301

301302
function checkGraphOrdering(rootNames: string[], expectedBuildSet: string[]) {
302-
const builder = createSolutionBuilder(host, buildHost, rootNames, { dry: true, force: false, verbose: false });
303+
const builder = createSolutionBuilder(host!, buildHost, rootNames, { dry: true, force: false, verbose: false });
303304

304305
const projFileNames = rootNames.map(getProjectFileName);
305306
const graph = builder.getBuildGraph(projFileNames);
@@ -394,32 +395,27 @@ namespace ts {
394395
}
395396

396397
function loadProjectFromDisk(root: string): vfs.FileSystem {
397-
const fs = new vfs.FileSystem(/*ignoreCase*/ false, { time });
398-
const rootPath = resolvePath(__dirname, root);
399-
loadFsMirror(fs, rootPath, "/src");
400-
fs.mkdirpSync("/lib");
401-
const libs = ["es5", "dom", "webworker.importscripts", "scripthost"];
402-
for (const lib of libs) {
403-
const content = Harness.IO.readFile(combinePaths(Harness.libFolder, `lib.${lib}.d.ts`));
404-
if (content === undefined) {
405-
throw new Error(`Failed to read lib ${lib}`);
406-
}
407-
fs.writeFileSync(`/lib/lib.${lib}.d.ts`, content);
408-
}
409-
fs.writeFileSync("/lib/lib.d.ts", Harness.IO.readFile(combinePaths(Harness.libFolder, "lib.d.ts"))!);
410-
fs.meta.set("defaultLibLocation", "/lib");
398+
const resolver = vfs.createResolver(Harness.IO);
399+
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
400+
files: {
401+
["/lib"]: new vfs.Mount(vpath.resolve(Harness.IO.getWorkspaceRoot(), "built/local"), patchResolver(resolver)),
402+
["/src"]: new vfs.Mount(vpath.resolve(Harness.IO.getWorkspaceRoot(), root), resolver)
403+
},
404+
cwd: "/",
405+
meta: { defaultLibLocation: "/lib" },
406+
time
407+
});
411408
fs.makeReadonly();
412409
return fs;
413-
}
414-
415-
function loadFsMirror(vfs: vfs.FileSystem, localRoot: string, virtualRoot: string) {
416-
vfs.mkdirpSync(virtualRoot);
417-
for (const path of Harness.IO.readDirectory(localRoot)) {
418-
const file = getBaseFileName(path);
419-
vfs.writeFileSync(virtualRoot + "/" + file, Harness.IO.readFile(localRoot + "/" + file)!);
420-
}
421-
for (const dir of Harness.IO.getDirectories(localRoot)) {
422-
loadFsMirror(vfs, localRoot + "/" + dir, virtualRoot + "/" + dir);
410+
function patchResolver(resolver: vfs.FileSystemResolver): vfs.FileSystemResolver {
411+
const allowedFiles = ["lib.d.ts", "lib.dom.d.ts", "lib.es5.d.ts", "lib.scripthost.d.ts", "lib.webworker.importscripts.d.ts"];
412+
return {
413+
...resolver,
414+
readdirSync(path: string) {
415+
const files = resolver.readdirSync(path);
416+
return files.filter(file => allowedFiles.indexOf(file) !== -1);
417+
}
418+
};
423419
}
424420
}
425421
}

tests/baselines/reference/outfile-concat-fileListing.txt

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/baselines/reference/outfile-concat.js

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,88 @@
1+
//// [/src/2/second-output.d.ts]
2+
declare namespace N {
3+
}
4+
declare namespace N {
5+
}
6+
declare class C {
7+
doSomething(): void;
8+
}
9+
//# sourceMappingURL=second-output.d.ts.map
10+
11+
//// [/src/2/second-output.d.ts.map]
12+
{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;ACVD;IACI,WAAW;CAGd"}
13+
14+
//// [/src/2/second-output.js]
15+
var N;
16+
(function (N) {
17+
function f() {
18+
console.log('testing');
19+
}
20+
f();
21+
})(N || (N = {}));
22+
var C = (function () {
23+
function C() {
24+
}
25+
C.prototype.doSomething = function () {
26+
console.log("something got done");
27+
};
28+
return C;
29+
}());
30+
//# sourceMappingURL=second-output.js.map
31+
32+
//// [/src/2/second-output.js.map]
33+
{"version":3,"file":"second-output.js","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAIA,IAAU,CAAC,CAMV;AAND,WAAU,CAAC;IACP;QACI,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IAED,CAAC,EAAE,CAAC;AACR,CAAC,EANS,CAAC,KAAD,CAAC,QAMV;ACVD;IAAA;IAIA,CAAC;IAHG,uBAAW,GAAX;QACI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IACtC,CAAC;IACL,QAAC;AAAD,CAAC,AAJD,IAIC"}
34+
35+
//// [/src/first/bin/first-output.d.ts]
36+
interface TheFirst {
37+
none: any;
38+
}
39+
declare const s = "Hello, world";
40+
interface NoJsForHereEither {
41+
none: any;
42+
}
43+
declare function f(): string;
44+
//# sourceMappingURL=first-output.d.ts.map
45+
46+
//// [/src/first/bin/first-output.d.ts.map]
47+
{"version":3,"file":"first-output.d.ts","sourceRoot":"","sources":["../first_part1.ts","../first_part2.ts","../first_part3.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IACd,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;AERD,6BAEC"}
48+
49+
//// [/src/first/bin/first-output.js]
50+
var s = "Hello, world";
51+
console.log(s);
52+
console.log(f());
53+
function f() {
54+
return "JS does hoists";
55+
}
56+
//# sourceMappingURL=first-output.js.map
57+
58+
//// [/src/first/bin/first-output.js.map]
59+
{"version":3,"file":"first-output.js","sourceRoot":"","sources":["../first_part1.ts","../first_part2.ts","../first_part3.ts"],"names":[],"mappings":"AAIA,IAAM,CAAC,GAAG,cAAc,CAAC;AAMzB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;ACVf,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;ACAjB;IACI,OAAO,gBAAgB,CAAC;AAC5B,CAAC"}
60+
61+
//// [/src/third/thirdjs/output/third-output.d.ts]
62+
interface TheFirst {
63+
none: any;
64+
}
65+
declare const s = "Hello, world";
66+
interface NoJsForHereEither {
67+
none: any;
68+
}
69+
declare function f(): string;
70+
//# sourceMappingURL=first-output.d.ts.map
71+
declare namespace N {
72+
}
73+
declare namespace N {
74+
}
75+
declare class C {
76+
doSomething(): void;
77+
}
78+
//# sourceMappingURL=second-output.d.ts.map
79+
declare var c: C;
80+
//# sourceMappingURL=third-output.d.ts.map
81+
82+
//// [/src/third/thirdjs/output/third-output.d.ts.map]
83+
{"version":3,"file":"third-output.d.ts","sections":[{"offset":{"line":0,"column":0},"map":{"version":3,"file":"first-output.d.ts","sourceRoot":"","sources":["../first_part1.ts","../first_part2.ts","../first_part3.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IACd,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;AERD,6BAEC"}},{"offset":{"line":9,"column":0},"map":{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;ACVD;IACI,WAAW;CAGd"}},{"offset":{"line":16,"column":43},"map":{"version":3,"file":"third-output.d.ts","sourceRoot":"","sources":["../../third_part1.ts"],"names":[],"mappings":";AAAA,QAAA,IAAI,CAAC,GAAU,CAAC"}}]}
84+
85+
//// [/src/third/thirdjs/output/third-output.js]
186
var s = "Hello, world";
287
console.log(s);
388
console.log(f());
@@ -23,4 +108,8 @@ var C = (function () {
23108
//# sourceMappingURL=second-output.js.map
24109
var c = new C();
25110
c.doSomething();
26-
//# sourceMappingURL=third-output.js.map
111+
//# sourceMappingURL=third-output.js.map
112+
113+
//// [/src/third/thirdjs/output/third-output.js.map]
114+
{"version":3,"file":"third-output.js","sections":[{"offset":{"line":0,"column":0},"map":{"version":3,"file":"first-output.js","sourceRoot":"","sources":["../first_part1.ts","../first_part2.ts","../first_part3.ts"],"names":[],"mappings":"AAIA,IAAM,CAAC,GAAG,cAAc,CAAC;AAMzB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;ACVf,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;ACAjB;IACI,OAAO,gBAAgB,CAAC;AAC5B,CAAC"}},{"offset":{"line":7,"column":0},"map":{"version":3,"file":"second-output.js","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAIA,IAAU,CAAC,CAMV;AAND,WAAU,CAAC;IACP;QACI,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IAED,CAAC,EAAE,CAAC;AACR,CAAC,EANS,CAAC,KAAD,CAAC,QAMV;ACVD;IAAA;IAIA,CAAC;IAHG,uBAAW,GAAX;QACI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IACtC,CAAC;IACL,QAAC;AAAD,CAAC,AAJD,IAIC"}},{"offset":{"line":22,"column":41},"map":{"version":3,"file":"third-output.js","sourceRoot":"","sources":["../../third_part1.ts"],"names":[],"mappings":";AAAA,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;AAChB,CAAC,CAAC,WAAW,EAAE,CAAC"}}]}
115+

tests/baselines/reference/outfile-concat.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/baselines/reference/third-output.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/baselines/reference/third-output.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)