Skip to content

Some refactoring for baselining for easy update #48516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/executeCommandLine/executeCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ namespace ts {
return false;
}

export type ExecuteCommandLineCallbacks = (program: Program | EmitAndSemanticDiagnosticsBuilderProgram | ParsedCommandLine) => void;
export type ExecuteCommandLineCallbacks = (program: Program | BuilderProgram | ParsedCommandLine) => void;
export function executeCommandLine(
system: System,
cb: ExecuteCommandLineCallbacks,
Expand Down
21 changes: 11 additions & 10 deletions src/harness/fakesHosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,18 +511,19 @@ ${indentText}${text}`;
buildInfo.version = ts.version;
return ts.getBuildInfoText(buildInfo);
};
return patchHostForBuildInfoWrite(sys, version);
}

export function patchHostForBuildInfoWrite<T extends ts.System>(sys: T, version: string) {
const originalWrite = sys.write;
sys.write = msg => originalWrite.call(sys, msg.replace(ts.version, version));

if (sys.writeFile) {
const originalWriteFile = sys.writeFile;
sys.writeFile = (fileName: string, content: string, writeByteOrderMark: boolean) => {
if (!ts.isBuildInfoFile(fileName)) return originalWriteFile.call(sys, fileName, content, writeByteOrderMark);
const buildInfo = ts.getBuildInfo(content);
buildInfo.version = version;
originalWriteFile.call(sys, fileName, ts.getBuildInfoText(buildInfo), writeByteOrderMark);
};
}
const originalWriteFile = sys.writeFile;
sys.writeFile = (fileName: string, content: string, writeByteOrderMark: boolean) => {
if (!ts.isBuildInfoFile(fileName)) return originalWriteFile.call(sys, fileName, content, writeByteOrderMark);
const buildInfo = ts.getBuildInfo(content);
buildInfo.version = version;
originalWriteFile.call(sys, fileName, ts.getBuildInfoText(buildInfo), writeByteOrderMark);
};
return sys;
}

Expand Down
15 changes: 14 additions & 1 deletion src/harness/vfsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,11 @@ namespace vfs {
const baseBuffer = base._getBuffer(baseNode);

// no difference if both buffers are the same reference
if (changedBuffer === baseBuffer) return false;
if (changedBuffer === baseBuffer) {
if (!options.includeChangedFileWithSameContent || changedNode.mtimeMs === baseNode.mtimeMs) return false;
container[basename] = new SameFileWithModifiedTime(changedBuffer);
return true;
}

// no difference if both buffers are identical
if (Buffer.compare(changedBuffer, baseBuffer) === 0) {
Expand Down Expand Up @@ -1391,6 +1395,12 @@ namespace vfs {
}
}

export class SameFileWithModifiedTime extends File {
constructor(data: Buffer | string, metaAndEncoding?: { encoding?: string, meta?: Record<string, any> }) {
super(data, metaAndEncoding);
}
}

/** Extended options for a hard link in a `FileSet` */
export class Link {
public readonly path: string;
Expand Down Expand Up @@ -1579,6 +1589,9 @@ namespace vfs {
else if (entry instanceof Directory) {
text += formatPatchWorker(file, entry.files);
}
else if (entry instanceof SameFileWithModifiedTime) {
text += `//// [${file}] file changed its modified time\r\n`;
}
else if (entry instanceof SameFileContentFile) {
text += `//// [${file}] file written with same contents\r\n`;
}
Expand Down
54 changes: 15 additions & 39 deletions src/testRunner/unittests/tsbuild/amdModulesWithOut.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
namespace ts {
describe("unittests:: tsbuild:: outFile:: on amd modules with --out", () => {
let outFileFs: vfs.FileSystem;
const enum Project { lib, app }
function relName(path: string) {
return path.slice(1);
}
type Sources = [string, readonly string[]];
const enum Source { config, ts }
const sources: [Sources, Sources] = [
[
"/src/lib/tsconfig.json",
[
"/src/lib/file0.ts",
"/src/lib/file1.ts",
"/src/lib/file2.ts",
"/src/lib/global.ts",
]
],
[
"/src/app/tsconfig.json",
[
"/src/app/file3.ts",
"/src/app/file4.ts"
]
]
];
before(() => {
outFileFs = loadProjectFromDisk("tests/projects/amdModulesWithOut");
});
Expand Down Expand Up @@ -53,7 +29,7 @@ namespace ts {
incrementalScenarios: [
{
buildKind: BuildKind.IncrementalDtsUnchanged,
modifyFs: fs => appendText(fs, relName(sources[Project.lib][Source.ts][1]), "console.log(x);")
modifyFs: fs => appendText(fs, "/src/lib/file1.ts", "console.log(x);")
},
...(modifyAgainFs ? [{
buildKind: BuildKind.IncrementalHeadersChange,
Expand All @@ -73,15 +49,15 @@ namespace ts {
verifyOutFileScenario({
subScenario: "multiple prologues in all projects",
modifyFs: fs => {
enableStrict(fs, sources[Project.lib][Source.config]);
addTestPrologue(fs, sources[Project.lib][Source.ts][0], `"myPrologue"`);
addTestPrologue(fs, sources[Project.lib][Source.ts][2], `"myPrologueFile"`);
addTestPrologue(fs, sources[Project.lib][Source.ts][3], `"myPrologue3"`);
enableStrict(fs, sources[Project.app][Source.config]);
addTestPrologue(fs, sources[Project.app][Source.ts][0], `"myPrologue"`);
addTestPrologue(fs, sources[Project.app][Source.ts][1], `"myPrologue2";`);
enableStrict(fs, "/src/lib/tsconfig.json");
addTestPrologue(fs, "/src/lib/file0.ts", `"myPrologue"`);
addTestPrologue(fs, "/src/lib/file2.ts", `"myPrologueFile"`);
addTestPrologue(fs, "/src/lib/global.ts", `"myPrologue3"`);
enableStrict(fs, "/src/app/tsconfig.json");
addTestPrologue(fs, "/src/app/file3.ts", `"myPrologue"`);
addTestPrologue(fs, "/src/app/file4.ts", `"myPrologue2";`);
},
modifyAgainFs: fs => addTestPrologue(fs, relName(sources[Project.lib][Source.ts][1]), `"myPrologue5"`)
modifyAgainFs: fs => addTestPrologue(fs, "/src/lib/file1.ts", `"myPrologue5"`)
});
});

Expand Down Expand Up @@ -127,10 +103,10 @@ namespace ts {
describe("stripInternal", () => {
function stripInternalScenario(fs: vfs.FileSystem) {
const internal = "/*@internal*/";
replaceText(fs, sources[Project.app][Source.config], `"composite": true,`, `"composite": true,
replaceText(fs, "/src/app/tsconfig.json", `"composite": true,`, `"composite": true,
"stripInternal": true,`);
replaceText(fs, sources[Project.lib][Source.ts][0], "const", `${internal} const`);
appendText(fs, sources[Project.lib][Source.ts][1], `
replaceText(fs, "/src/lib/file0.ts", "const", `${internal} const`);
appendText(fs, "/src/lib/file1.ts", `
export class normalC {
${internal} constructor() { }
${internal} prop: string;
Expand Down Expand Up @@ -162,16 +138,16 @@ ${internal} export enum internalEnum { a, b, c }`);
verifyOutFileScenario({
subScenario: "stripInternal",
modifyFs: stripInternalScenario,
modifyAgainFs: fs => replaceText(fs, sources[Project.lib][Source.ts][1], `export const`, `/*@internal*/ export const`),
modifyAgainFs: fs => replaceText(fs, "/src/lib/file1.ts", `export const`, `/*@internal*/ export const`),
});
});

describe("when the module resolution finds original source file", () => {
function modifyFs(fs: vfs.FileSystem) {
// Make lib to output to parent dir
replaceText(fs, sources[Project.lib][Source.config], `"outFile": "module.js"`, `"outFile": "../module.js", "rootDir": "../"`);
replaceText(fs, "/src/lib/tsconfig.json", `"outFile": "module.js"`, `"outFile": "../module.js", "rootDir": "../"`);
// Change reference to file1 module to resolve to lib/file1
replaceText(fs, sources[Project.app][Source.ts][0], "file1", "lib/file1");
replaceText(fs, "/src/app/file3.ts", "file1", "lib/file1");
}

verifyTsc({
Expand Down
20 changes: 10 additions & 10 deletions src/testRunner/unittests/tsbuild/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,23 +332,23 @@ interface Symbol {
}

interface VerifyIncrementalCorrectness {
scenario: TscCompile["scenario"];
commandLineArgs: TscCompile["commandLineArgs"];
modifyFs: TscCompile["modifyFs"];
scenario: TestTscCompile["scenario"];
commandLineArgs: TestTscCompile["commandLineArgs"];
modifyFs: TestTscCompile["modifyFs"];
incrementalModifyFs: TscIncremental["modifyFs"];
tick: () => void;
baseFs: vfs.FileSystem;
newSys: TscCompileSystem;
cleanBuildDiscrepancies: TscIncremental["cleanBuildDiscrepancies"];
}
function verifyIncrementalCorrectness(input: () => VerifyIncrementalCorrectness, index: number, subScenario: TscCompile["subScenario"]) {
function verifyIncrementalCorrectness(input: () => VerifyIncrementalCorrectness, index: number, subScenario: TestTscCompile["subScenario"]) {
it(`Verify emit output file text is same when built clean for incremental scenario at:: ${index} ${subScenario}`, () => {
const {
scenario, commandLineArgs, cleanBuildDiscrepancies,
modifyFs, incrementalModifyFs,
tick, baseFs, newSys
} = input();
const sys = tscCompile({
const sys = testTscCompile({
scenario,
subScenario,
fs: () => baseFs.makeReadonly(),
Expand Down Expand Up @@ -521,7 +521,7 @@ interface Symbol {
}
}

export interface VerifyTsBuildInputWorker extends TscCompile {
export interface VerifyTsBuildInputWorker extends TestTscCompile {
incrementalScenarios: TscIncremental[];
}
function verifyTscIncrementalEditsWorker({
Expand All @@ -535,7 +535,7 @@ interface Symbol {
let baseFs: vfs.FileSystem;
before(() => {
({ fs: baseFs, tick } = getFsWithTime(fs()));
sys = tscCompile({
sys = testTscCompile({
scenario,
subScenario,
fs: () => baseFs.makeReadonly(),
Expand Down Expand Up @@ -571,7 +571,7 @@ interface Symbol {
before(() => {
Debug.assert(buildKind !== BuildKind.Initial, "Incremental edit cannot be initial compilation");
tick();
newSys = tscCompile({
newSys = testTscCompile({
scenario,
subScenario: incrementalSubScenario || subScenario,
buildKind,
Expand Down Expand Up @@ -629,7 +629,7 @@ interface Symbol {
let incrementalSys: TscCompileSystem[];
before(() => {
({ fs: baseFs, tick } = getFsWithTime(fs()));
sys = tscCompile({
sys = testTscCompile({
scenario,
subScenario,
fs: () => baseFs.makeReadonly(),
Expand All @@ -648,7 +648,7 @@ interface Symbol {
) => {
Debug.assert(buildKind !== BuildKind.Initial, "Incremental edit cannot be initial compilation");
tick();
(incrementalSys || (incrementalSys = [])).push(tscCompile({
(incrementalSys || (incrementalSys = [])).push(testTscCompile({
scenario,
subScenario: incrementalSubScenario || subScenario,
buildKind,
Expand Down
Loading