Skip to content

Commit 9acff37

Browse files
committed
Add test to test the readFile called on prepend input file for emitting and verifying emit
1 parent 71d70ef commit 9acff37

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/testRunner/unittests/tsbuild.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,20 @@ export const b = new A();`);
469469

470470
describe("unittests:: tsbuild - baseline sectioned sourcemaps", () => {
471471
let fs: vfs.FileSystem | undefined;
472+
const actualReadFileMap = createMap<number>();
472473
before(() => {
473474
fs = outFileFs.shadow();
474475
const host = new fakes.SolutionBuilderHost(fs);
475476
const builder = createSolutionBuilder(host, ["/src/third"], { dry: false, force: false, verbose: false });
476477
host.clearDiagnostics();
478+
const originalReadFile = host.readFile;
479+
host.readFile = path => {
480+
// Dont record libs
481+
if (path.startsWith("/src/")) {
482+
actualReadFileMap.set(path, (actualReadFileMap.get(path) || 0) + 1);
483+
}
484+
return originalReadFile.call(host, path);
485+
};
477486
builder.buildAllProjects();
478487
host.assertDiagnosticMessages(/*none*/);
479488
});
@@ -485,6 +494,39 @@ export const b = new A();`);
485494
// tslint:disable-next-line:no-null-keyword
486495
Harness.Baseline.runBaseline("outfile-concat.js", patch ? vfs.formatPatch(patch) : null);
487496
});
497+
it("verify readFile calls", () => {
498+
const expectedMap = createMap<number>();
499+
// Configs
500+
expectedMap.set("/src/third/tsconfig.json", 1);
501+
expectedMap.set("/src/second/tsconfig.json", 1);
502+
expectedMap.set("/src/first/tsconfig.json", 1);
503+
504+
// Source files
505+
expectedMap.set("/src/third/third_part1.ts", 1);
506+
expectedMap.set("/src/second/second_part1.ts", 1);
507+
expectedMap.set("/src/second/second_part2.ts", 1);
508+
expectedMap.set("/src/first/first_PART1.ts", 1);
509+
expectedMap.set("/src/first/first_part2.ts", 1);
510+
expectedMap.set("/src/first/first_part3.ts", 1);
511+
512+
// outputs
513+
expectedMap.set("/src/first/bin/first-output.js", 2);
514+
expectedMap.set("/src/first/bin/first-output.js.map", 2);
515+
// 1 for reading source File, 2 for forEachEmittedFiles (verifying compiler Options and actual emit)when prepend array is created
516+
expectedMap.set("/src/first/bin/first-output.d.ts", 3);
517+
expectedMap.set("/src/first/bin/first-output.d.ts.map", 2);
518+
expectedMap.set("/src/2/second-output.js", 2);
519+
expectedMap.set("/src/2/second-output.js.map", 2);
520+
// 1 for reading source File, 2 for forEachEmittedFiles (verifying compiler Options and actual emit)when prepend array is created
521+
expectedMap.set("/src/2/second-output.d.ts", 3);
522+
expectedMap.set("/src/2/second-output.d.ts.map", 2);
523+
524+
assert.equal(actualReadFileMap.size, expectedMap.size, `Expected: ${JSON.stringify(arrayFrom(expectedMap.entries()))} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`);
525+
actualReadFileMap.forEach((value, key) => {
526+
const expected = expectedMap.get(key);
527+
assert.equal(value, expected, `Expected: ${JSON.stringify(arrayFrom(expectedMap.entries()))} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`);
528+
});
529+
});
488530
});
489531

490532
describe("unittests:: tsbuild - downstream prepend projects always get rebuilt", () => {

0 commit comments

Comments
 (0)