Skip to content

Commit

Permalink
More baselines for the tsbuildinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Apr 19, 2022
1 parent 386786c commit f45e9ca
Show file tree
Hide file tree
Showing 22 changed files with 2,522 additions and 112 deletions.
4 changes: 2 additions & 2 deletions src/testRunner/unittests/tsbuild/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ interface Symbol {

export function baselineBuildInfo(
options: CompilerOptions,
sys: System & { writtenFiles: ReadonlyCollection<Path>; },
sys: TscCompileSystem | tscWatch.WatchedSystem,
originalReadCall?: System["readFile"],
) {
const buildInfoPath = getTsBuildInfoEmitOutputFilePath(options);
if (!buildInfoPath || !sys.writtenFiles.has(toPathWithSystem(sys, buildInfoPath))) return;
if (!buildInfoPath || !sys.writtenFiles!.has(toPathWithSystem(sys, buildInfoPath))) return;
if (!sys.fileExists(buildInfoPath)) return;

const buildInfo = getBuildInfo((originalReadCall || sys.readFile).call(sys, buildInfoPath, "utf8")!);
Expand Down
4 changes: 2 additions & 2 deletions src/testRunner/unittests/tsbuild/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace ts {
)
);

const host = createSolutionBuilderHost(system);
const host = createSolutionBuilderHostForBaseline(system);
const builder = createSolutionBuilder(host, [testsConfig.path], {});
baseline.push("Input::");
baselineState();
Expand Down Expand Up @@ -317,7 +317,7 @@ namespace ts {
)
);

const host = createSolutionBuilderHost(system);
const host = createSolutionBuilderHostForBaseline(system);
const builder = createSolutionBuilder(host, [testsConfig.path], { dry: false, force: false, verbose: false });
builder.build();
baselineState("Build of project");
Expand Down
12 changes: 8 additions & 4 deletions src/testRunner/unittests/tsc/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ts {
return !!(program as Program | BuilderProgram).getCompilerOptions;
}
export function commandLineCallbacks(
sys: System & { writtenFiles: ReadonlyCollection<Path>; },
sys: TscCompileSystem | tscWatch.WatchedSystem,
originalReadCall?: System["readFile"],
): CommandLineCallbacks {
let programs: CommandLineProgram[] | undefined;
Expand Down Expand Up @@ -136,9 +136,13 @@ ${patch ? vfs.formatPatch(patch) : ""}`
};
}

export function createSolutionBuilderHostForBaseline(sys: TscCompileSystem, versionToWrite?: string) {
makeSystemReadyForBaseline(sys, versionToWrite);
const { cb } = commandLineCallbacks(sys);
export function createSolutionBuilderHostForBaseline(
sys: TscCompileSystem | tscWatch.WatchedSystem,
versionToWrite?: string,
originalRead?: (TscCompileSystem | tscWatch.WatchedSystem)["readFile"]
) {
if (sys instanceof fakes.System) makeSystemReadyForBaseline(sys, versionToWrite);
const { cb } = commandLineCallbacks(sys, originalRead);
const host = createSolutionBuilderHost(sys,
/*createProgram*/ undefined,
createDiagnosticReporter(sys, /*pretty*/ true),
Expand Down
23 changes: 13 additions & 10 deletions src/testRunner/unittests/tscWatch/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ namespace ts.tscWatch {
export interface Baseline extends BaselineBase, CommandLineCallbacks {
}

export function createBaseline(system: WatchedSystem, modifySystem?: (sys: WatchedSystem) => void): Baseline {
export function createBaseline(system: WatchedSystem, modifySystem?: (sys: WatchedSystem, originalRead: WatchedSystem["readFile"]) => void): Baseline {
const originalRead = system.readFile;
const initialSys = fakes.patchHostForBuildInfoReadWrite(system);
modifySystem?.(initialSys);
modifySystem?.(initialSys, originalRead);
const sys = TestFSWithWatch.changeToHostTrackingWrittenFiles(initialSys);
const baseline: string[] = [];
baseline.push("Input::");
Expand Down Expand Up @@ -407,30 +408,32 @@ namespace ts.tscWatch {
sys.writeFile(file, content.replace(searchValue, replaceValue));
}

export function createSolutionBuilder(system: WatchedSystem, rootNames: readonly string[], defaultOptions?: BuildOptions) {
const host = createSolutionBuilderHost(system);
return ts.createSolutionBuilder(host, rootNames, defaultOptions || {});
export function createSolutionBuilder(system: WatchedSystem, rootNames: readonly string[], originalRead?: WatchedSystem["readFile"]) {
const host = createSolutionBuilderHostForBaseline(system, /*versionToWrite*/ undefined, originalRead);
return ts.createSolutionBuilder(host, rootNames, {});
}

export function ensureErrorFreeBuild(host: WatchedSystem, rootNames: readonly string[]) {
// ts build should succeed
const solutionBuilder = createSolutionBuilder(host, rootNames, {});
solutionBuilder.build();
solutionBuildWithBaseline(host, rootNames);
assert.equal(host.getOutput().length, 0, JSON.stringify(host.getOutput(), /*replacer*/ undefined, " "));
}

export function createSystemWithSolutionBuild(solutionRoots: readonly string[], files: readonly TestFSWithWatch.FileOrFolderOrSymLink[], params?: TestFSWithWatch.TestServerHostCreationParameters) {
const sys = createWatchedSystem(files, params);
export function solutionBuildWithBaseline(sys: WatchedSystem, solutionRoots: readonly string[], originalRead?: WatchedSystem["readFile"]) {
const originalReadFile = sys.readFile;
const originalWrite = sys.write;
const originalWriteFile = sys.writeFile;
const solutionBuilder = createSolutionBuilder(TestFSWithWatch.changeToHostTrackingWrittenFiles(
fakes.patchHostForBuildInfoReadWrite(sys)
), solutionRoots, {});
), solutionRoots, originalRead);
solutionBuilder.build();
sys.readFile = originalReadFile;
sys.write = originalWrite;
sys.writeFile = originalWriteFile;
return sys;
}

export function createSystemWithSolutionBuild(solutionRoots: readonly string[], files: readonly TestFSWithWatch.FileOrFolderOrSymLink[], params?: TestFSWithWatch.TestServerHostCreationParameters) {
return solutionBuildWithBaseline(createWatchedSystem(files, params), solutionRoots);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ namespace ts.tscWatch {
function verifyWatch({ files, config, subScenario }: VerifyWatchInput, alreadyBuilt: boolean) {
const { sys, baseline, oldSnap, cb, getPrograms } = createBaseline(
createWatchedSystem(files),
alreadyBuilt ? sys => {
const solutionBuilder = createSolutionBuilder(sys, [config], {});
solutionBuilder.build();
solutionBuilder.close();
alreadyBuilt ? (sys, originalRead) => {
solutionBuildWithBaseline(sys, [config], originalRead);
sys.clearOutput();
} : undefined
);
Expand Down
3 changes: 1 addition & 2 deletions src/testRunner/unittests/tsserver/projectReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1278,8 +1278,7 @@ bar;`
const files = [solnConfig, sharedConfig, sharedIndex, sharedPackage, appConfig, appBar, appIndex, sharedSymlink, libFile];
const host = createServerHost(files);
if (built) {
const solutionBuilder = tscWatch.createSolutionBuilder(host, [solnConfig.path], {});
solutionBuilder.build();
tscWatch.solutionBuildWithBaseline(host, [solnConfig.path]);
host.clearOutput();
}
const session = createSession(host, { logger: createLoggerWithInMemoryLogs() });
Expand Down
Loading

0 comments on commit f45e9ca

Please sign in to comment.