Refactor to write baseline of sourcemaps that are written

This commit is contained in:
Sheetal Nandi
2019-09-09 13:54:59 -07:00
parent fb453f8208
commit 566d32b2e8
11 changed files with 256 additions and 14893 deletions
@@ -67,12 +67,7 @@ namespace ts {
tick,
proj: "amdModulesWithOut",
rootNames: ["/src/app"],
expectedMapFileNames: [
outputFiles[project.lib][ext.jsmap],
outputFiles[project.lib][ext.dtsmap],
outputFiles[project.app][ext.jsmap],
outputFiles[project.app][ext.dtsmap],
],
baselineSourceMap: true,
expectedBuildInfoFilesForSectionBaselines: [
[outputFiles[project.lib][ext.buildinfo], outputFiles[project.lib][ext.js], outputFiles[project.lib][ext.dts]],
[outputFiles[project.app][ext.buildinfo], outputFiles[project.app][ext.js], outputFiles[project.app][ext.dts]]
@@ -221,12 +216,7 @@ ${internal} export enum internalEnum { a, b, c }`);
tick,
proj: "amdModulesWithOut",
rootNames: ["/src/app"],
expectedMapFileNames: [
libOutputFile[ext.jsmap],
libOutputFile[ext.dtsmap],
outputFiles[project.app][ext.jsmap],
outputFiles[project.app][ext.dtsmap],
],
baselineSourceMap: true,
expectedBuildInfoFilesForSectionBaselines: [
[libOutputFile[ext.buildinfo], libOutputFile[ext.js], libOutputFile[ext.dts]],
[outputFiles[project.app][ext.buildinfo], outputFiles[project.app][ext.js], outputFiles[project.app][ext.dts]]
+18 -10
View File
@@ -164,8 +164,10 @@ interface Symbol {
}
}
function generateSourceMapBaselineFiles(fs: vfs.FileSystem, mapFileNames: ReadonlyArray<string>) {
for (const mapFile of mapFileNames) {
function generateSourceMapBaselineFiles(fs: vfs.FileSystem, mapFileNames: Iterator<string>) {
while (true) {
const { value: mapFile, done } = mapFileNames.next();
if (done) break;
if (!fs.existsSync(mapFile)) continue;
const text = Harness.SourceMapRecorder.getSourceMapRecordWithVFS(fs, mapFile);
fs.writeFileSync(`${mapFile}.baseline.txt`, text);
@@ -233,17 +235,24 @@ interface Symbol {
fs: vfs.FileSystem;
tick: () => void;
rootNames: ReadonlyArray<string>;
expectedMapFileNames?: ReadonlyArray<string>;
baselineSourceMap?: true;
expectedBuildInfoFilesForSectionBaselines?: ReadonlyArray<BuildInfoSectionBaselineFiles>;
modifyFs: (fs: vfs.FileSystem) => void;
}
function build({ fs, tick, rootNames, expectedMapFileNames, expectedBuildInfoFilesForSectionBaselines, modifyFs }: BuildInput) {
function build({ fs, tick, rootNames, baselineSourceMap, expectedBuildInfoFilesForSectionBaselines, modifyFs }: BuildInput) {
const actualReadFileMap = createMap<number>();
modifyFs(fs);
tick();
const host = new fakes.SolutionBuilderHost(fs);
const writtenFiles = createMap<true>();
const originalWriteFile = host.writeFile;
host.writeFile = (fileName, content, writeByteOrderMark) => {
assert.isFalse(writtenFiles.has(fileName));
writtenFiles.set(fileName, true);
return originalWriteFile.call(host, fileName, content, writeByteOrderMark);
};
const builder = createSolutionBuilder(host, rootNames, { dry: false, force: false, verbose: true });
host.clearDiagnostics();
const originalReadFile = host.readFile;
@@ -255,7 +264,7 @@ interface Symbol {
return originalReadFile.call(host, path);
};
builder.build();
if (expectedMapFileNames) generateSourceMapBaselineFiles(fs, expectedMapFileNames);
if (baselineSourceMap) generateSourceMapBaselineFiles(fs, mapDefinedIterator(writtenFiles.keys(), f => f.endsWith(".map") ? f : undefined));
generateBuildInfoSectionBaselineFiles(fs, expectedBuildInfoFilesForSectionBaselines || emptyArray);
fs.makeReadonly();
return { fs, actualReadFileMap, host, builder };
@@ -302,8 +311,6 @@ Mismatch Actual(path, actual, expected): ${JSON.stringify(arrayFrom(mapDefinedIt
tick: () => void;
proj: string;
rootNames: ReadonlyArray<string>;
/** map file names to generate baseline of */
expectedMapFileNames?: ReadonlyArray<string>;
expectedBuildInfoFilesForSectionBaselines?: ReadonlyArray<BuildInfoSectionBaselineFiles>;
lastProjectOutput: string;
initialBuild: BuildState;
@@ -313,11 +320,12 @@ Mismatch Actual(path, actual, expected): ${JSON.stringify(arrayFrom(mapDefinedIt
incrementalHeaderChangedBuild?: BuildState;
baselineOnly?: true;
verifyDiagnostics?: true;
baselineSourceMap?: true;
}
export function verifyTsbuildOutput({
scenario, projFs, time, tick, proj, rootNames, outputFiles, baselineOnly, verifyDiagnostics,
expectedMapFileNames, expectedBuildInfoFilesForSectionBaselines, lastProjectOutput,
baselineSourceMap, expectedBuildInfoFilesForSectionBaselines, lastProjectOutput,
initialBuild, incrementalDtsChangedBuild, incrementalDtsUnchangedBuild, incrementalHeaderChangedBuild
}: VerifyTsBuildInput) {
describe(`tsc --b ${proj}:: ${scenario}`, () => {
@@ -330,7 +338,7 @@ Mismatch Actual(path, actual, expected): ${JSON.stringify(arrayFrom(mapDefinedIt
fs: projFs().shadow(),
tick,
rootNames,
expectedMapFileNames,
baselineSourceMap,
expectedBuildInfoFilesForSectionBaselines,
modifyFs: initialBuild.modifyFs,
});
@@ -374,7 +382,7 @@ Mismatch Actual(path, actual, expected): ${JSON.stringify(arrayFrom(mapDefinedIt
fs: newFs,
tick,
rootNames,
expectedMapFileNames,
baselineSourceMap,
expectedBuildInfoFilesForSectionBaselines,
modifyFs: incrementalModifyFs,
}));
+1 -9
View File
@@ -55,14 +55,6 @@ namespace ts {
]
]
];
const expectedMapFileNames = [
outputFiles[project.first][ext.jsmap],
outputFiles[project.first][ext.dtsmap],
outputFiles[project.second][ext.jsmap],
outputFiles[project.second][ext.dtsmap],
outputFiles[project.third][ext.jsmap],
outputFiles[project.third][ext.dtsmap]
];
const expectedTsbuildInfoFileNames: ReadonlyArray<BuildInfoSectionBaselineFiles> = [
[outputFiles[project.first][ext.buildinfo], outputFiles[project.first][ext.js], outputFiles[project.first][ext.dts]],
[outputFiles[project.second][ext.buildinfo], outputFiles[project.second][ext.js], outputFiles[project.second][ext.dts]],
@@ -286,7 +278,7 @@ namespace ts {
tick,
proj: "outfile-concat",
rootNames: ["/src/third"],
expectedMapFileNames,
baselineSourceMap: true,
expectedBuildInfoFilesForSectionBaselines: expectedBuildInfoFilesForSectionBaselines || expectedTsbuildInfoFileNames,
lastProjectOutput: outputFiles[project.third][ext.js],
initialBuild: {
+3 -15
View File
@@ -612,11 +612,7 @@ export class cNew {}`);
tick,
proj: "sample1",
rootNames: ["/src/tests"],
expectedMapFileNames: [
"/src/core/anotherModule.d.ts.map",
"/src/core/index.d.ts.map",
"/src/logic/index.js.map"
],
baselineSourceMap: true,
lastProjectOutput: "/src/tests/index.js",
initialBuild,
incrementalDtsChangedBuild: {
@@ -722,11 +718,7 @@ class someClass { }`),
tick,
proj: "sample1",
rootNames: ["/src/tests"],
expectedMapFileNames: [
"/src/core/anotherModule.d.ts.map",
"/src/core/index.d.ts.map",
"/src/logic/index.js.map"
],
baselineSourceMap: true,
lastProjectOutput: "/src/tests/index.js",
initialBuild,
incrementalDtsChangedBuild: {
@@ -790,11 +782,7 @@ class someClass { }`),
tick,
proj: "sample1",
rootNames: ["/src/tests"],
expectedMapFileNames: [
"/src/core/anotherModule.d.ts.map",
"/src/core/index.d.ts.map",
"/src/logic/index.js.map"
],
baselineSourceMap: true,
lastProjectOutput: "/src/tests/index.js",
initialBuild: {
modifyFs: fs => replaceText(fs, "/src/logic/tsconfig.json", `"composite": true,`, `"composite": true,
@@ -521,6 +521,123 @@ declare const globalConst = 10;
//// [/src/module.d.ts.map]
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["lib/file0.ts","lib/file1.ts","lib/file2.ts","lib/global.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,MAAM,KAAK,CAAC;;ICAlB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;;;ICApB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;;ACApB,QAAA,MAAM,WAAW,KAAK,CAAC"}
//// [/src/module.d.ts.map.baseline.txt]
===================================================================
JsFile: module.d.ts
mapUrl: module.d.ts.map
sourceRoot:
sources: lib/file0.ts,lib/file1.ts,lib/file2.ts,lib/global.ts
===================================================================
-------------------------------------------------------------------
emittedFile:/src/module.d.ts
sourceFile:lib/file0.ts
-------------------------------------------------------------------
>>>declare const myGlob = 20;
1 >
2 >^^^^^^^^
3 > ^^^^^^
4 > ^^^^^^
5 > ^^^^^
6 > ^
7 > ^^^->
1 >
2 >
3 > const
4 > myGlob
5 > = 20
6 > ;
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(1, 9) Source(1, 1) + SourceIndex(0)
3 >Emitted(1, 15) Source(1, 7) + SourceIndex(0)
4 >Emitted(1, 21) Source(1, 13) + SourceIndex(0)
5 >Emitted(1, 26) Source(1, 18) + SourceIndex(0)
6 >Emitted(1, 27) Source(1, 19) + SourceIndex(0)
---
-------------------------------------------------------------------
emittedFile:/src/module.d.ts
sourceFile:lib/file1.ts
-------------------------------------------------------------------
>>>declare module "lib/file1" {
>>> export const x = 10;
1->^^^^
2 > ^^^^^^
3 > ^
4 > ^^^^^^
5 > ^
6 > ^^^^^
7 > ^
1->
2 > export
3 >
4 > const
5 > x
6 > = 10
7 > ;
1->Emitted(3, 5) Source(1, 1) + SourceIndex(1)
2 >Emitted(3, 11) Source(1, 7) + SourceIndex(1)
3 >Emitted(3, 12) Source(1, 8) + SourceIndex(1)
4 >Emitted(3, 18) Source(1, 14) + SourceIndex(1)
5 >Emitted(3, 19) Source(1, 15) + SourceIndex(1)
6 >Emitted(3, 24) Source(1, 20) + SourceIndex(1)
7 >Emitted(3, 25) Source(1, 21) + SourceIndex(1)
---
-------------------------------------------------------------------
emittedFile:/src/module.d.ts
sourceFile:lib/file2.ts
-------------------------------------------------------------------
>>>}
>>>declare module "lib/file2" {
>>> export const y = 20;
1 >^^^^
2 > ^^^^^^
3 > ^
4 > ^^^^^^
5 > ^
6 > ^^^^^
7 > ^
1 >
2 > export
3 >
4 > const
5 > y
6 > = 20
7 > ;
1 >Emitted(6, 5) Source(1, 1) + SourceIndex(2)
2 >Emitted(6, 11) Source(1, 7) + SourceIndex(2)
3 >Emitted(6, 12) Source(1, 8) + SourceIndex(2)
4 >Emitted(6, 18) Source(1, 14) + SourceIndex(2)
5 >Emitted(6, 19) Source(1, 15) + SourceIndex(2)
6 >Emitted(6, 24) Source(1, 20) + SourceIndex(2)
7 >Emitted(6, 25) Source(1, 21) + SourceIndex(2)
---
-------------------------------------------------------------------
emittedFile:/src/module.d.ts
sourceFile:lib/global.ts
-------------------------------------------------------------------
>>>}
>>>declare const globalConst = 10;
1 >
2 >^^^^^^^^
3 > ^^^^^^
4 > ^^^^^^^^^^^
5 > ^^^^^
6 > ^
7 > ^^^^->
1 >
2 >
3 > const
4 > globalConst
5 > = 10
6 > ;
1 >Emitted(8, 1) Source(1, 1) + SourceIndex(3)
2 >Emitted(8, 9) Source(1, 1) + SourceIndex(3)
3 >Emitted(8, 15) Source(1, 7) + SourceIndex(3)
4 >Emitted(8, 26) Source(1, 18) + SourceIndex(3)
5 >Emitted(8, 31) Source(1, 23) + SourceIndex(3)
6 >Emitted(8, 32) Source(1, 24) + SourceIndex(3)
---
>>>//# sourceMappingURL=module.d.ts.map
//// [/src/module.js]
var myGlob = 20;
define("lib/file1", ["require", "exports"], function (require, exports) {
@@ -539,6 +656,121 @@ var globalConst = 10;
//// [/src/module.js.map]
{"version":3,"file":"module.js","sourceRoot":"","sources":["lib/file0.ts","lib/file1.ts","lib/file2.ts","lib/global.ts"],"names":[],"mappings":"AAAA,IAAM,MAAM,GAAG,EAAE,CAAC;;;;ICAL,QAAA,CAAC,GAAG,EAAE,CAAC;;;;;ICAP,QAAA,CAAC,GAAG,EAAE,CAAC;;ACApB,IAAM,WAAW,GAAG,EAAE,CAAC"}
//// [/src/module.js.map.baseline.txt]
===================================================================
JsFile: module.js
mapUrl: module.js.map
sourceRoot:
sources: lib/file0.ts,lib/file1.ts,lib/file2.ts,lib/global.ts
===================================================================
-------------------------------------------------------------------
emittedFile:/src/module.js
sourceFile:lib/file0.ts
-------------------------------------------------------------------
>>>var myGlob = 20;
1 >
2 >^^^^
3 > ^^^^^^
4 > ^^^
5 > ^^
6 > ^
7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
2 >const
3 > myGlob
4 > =
5 > 20
6 > ;
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(1, 5) Source(1, 7) + SourceIndex(0)
3 >Emitted(1, 11) Source(1, 13) + SourceIndex(0)
4 >Emitted(1, 14) Source(1, 16) + SourceIndex(0)
5 >Emitted(1, 16) Source(1, 18) + SourceIndex(0)
6 >Emitted(1, 17) Source(1, 19) + SourceIndex(0)
---
-------------------------------------------------------------------
emittedFile:/src/module.js
sourceFile:lib/file1.ts
-------------------------------------------------------------------
>>>define("lib/file1", ["require", "exports"], function (require, exports) {
>>> "use strict";
>>> Object.defineProperty(exports, "__esModule", { value: true });
>>> exports.x = 10;
1->^^^^
2 > ^^^^^^^^
3 > ^
4 > ^^^
5 > ^^
6 > ^
1->export const
2 >
3 > x
4 > =
5 > 10
6 > ;
1->Emitted(5, 5) Source(1, 14) + SourceIndex(1)
2 >Emitted(5, 13) Source(1, 14) + SourceIndex(1)
3 >Emitted(5, 14) Source(1, 15) + SourceIndex(1)
4 >Emitted(5, 17) Source(1, 18) + SourceIndex(1)
5 >Emitted(5, 19) Source(1, 20) + SourceIndex(1)
6 >Emitted(5, 20) Source(1, 21) + SourceIndex(1)
---
-------------------------------------------------------------------
emittedFile:/src/module.js
sourceFile:lib/file2.ts
-------------------------------------------------------------------
>>>});
>>>define("lib/file2", ["require", "exports"], function (require, exports) {
>>> "use strict";
>>> Object.defineProperty(exports, "__esModule", { value: true });
>>> exports.y = 20;
1 >^^^^
2 > ^^^^^^^^
3 > ^
4 > ^^^
5 > ^^
6 > ^
1 >export const
2 >
3 > y
4 > =
5 > 20
6 > ;
1 >Emitted(10, 5) Source(1, 14) + SourceIndex(2)
2 >Emitted(10, 13) Source(1, 14) + SourceIndex(2)
3 >Emitted(10, 14) Source(1, 15) + SourceIndex(2)
4 >Emitted(10, 17) Source(1, 18) + SourceIndex(2)
5 >Emitted(10, 19) Source(1, 20) + SourceIndex(2)
6 >Emitted(10, 20) Source(1, 21) + SourceIndex(2)
---
-------------------------------------------------------------------
emittedFile:/src/module.js
sourceFile:lib/global.ts
-------------------------------------------------------------------
>>>});
>>>var globalConst = 10;
1 >
2 >^^^^
3 > ^^^^^^^^^^^
4 > ^^^
5 > ^^
6 > ^
7 > ^^^^^^^^^^^^->
1 >
2 >const
3 > globalConst
4 > =
5 > 10
6 > ;
1 >Emitted(12, 1) Source(1, 1) + SourceIndex(3)
2 >Emitted(12, 5) Source(1, 7) + SourceIndex(3)
3 >Emitted(12, 16) Source(1, 18) + SourceIndex(3)
4 >Emitted(12, 19) Source(1, 21) + SourceIndex(3)
5 >Emitted(12, 21) Source(1, 23) + SourceIndex(3)
6 >Emitted(12, 22) Source(1, 24) + SourceIndex(3)
---
>>>//# sourceMappingURL=module.js.map
//// [/src/module.tsbuildinfo]
{
"bundle": {