Skip to content

Commit 53d54c2

Browse files
committed
Make baselines faster by not writing out unneeded files
1 parent f6a850b commit 53d54c2

File tree

5 files changed

+81
-73
lines changed

5 files changed

+81
-73
lines changed

Gulpfile.ts

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ declare module "gulp-typescript" {
1717
stripInternal?: boolean;
1818
types?: string[];
1919
}
20-
interface CompileStream extends NodeJS.ReadWriteStream {} // Either gulp or gulp-typescript has some odd typings which don't reflect reality, making this required
20+
interface CompileStream extends NodeJS.ReadWriteStream { } // Either gulp or gulp-typescript has some odd typings which don't reflect reality, making this required
2121
}
2222
import * as insert from "gulp-insert";
2323
import * as sourcemaps from "gulp-sourcemaps";
@@ -65,7 +65,7 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
6565
}
6666
});
6767

68-
function exec(cmd: string, args: string[], complete: () => void = (() => {}), error: (e: any, status: number) => void = (() => {})) {
68+
function exec(cmd: string, args: string[], complete: () => void = (() => { }), error: (e: any, status: number) => void = (() => { })) {
6969
console.log(`${cmd} ${args.join(" ")}`);
7070
// TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition
7171
const subshellFlag = isWin ? "/c" : "-c";
@@ -116,12 +116,12 @@ const es2015LibrarySources = [
116116
];
117117

118118
const es2015LibrarySourceMap = es2015LibrarySources.map(function(source) {
119-
return { target: "lib." + source, sources: ["header.d.ts", source] };
119+
return { target: "lib." + source, sources: ["header.d.ts", source] };
120120
});
121121

122-
const es2016LibrarySource = [ "es2016.array.include.d.ts" ];
122+
const es2016LibrarySource = ["es2016.array.include.d.ts"];
123123

124-
const es2016LibrarySourceMap = es2016LibrarySource.map(function (source) {
124+
const es2016LibrarySourceMap = es2016LibrarySource.map(function(source) {
125125
return { target: "lib." + source, sources: ["header.d.ts", source] };
126126
});
127127

@@ -130,38 +130,38 @@ const es2017LibrarySource = [
130130
"es2017.sharedmemory.d.ts"
131131
];
132132

133-
const es2017LibrarySourceMap = es2017LibrarySource.map(function (source) {
133+
const es2017LibrarySourceMap = es2017LibrarySource.map(function(source) {
134134
return { target: "lib." + source, sources: ["header.d.ts", source] };
135135
});
136136

137137
const hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scripthost.d.ts"];
138138

139139
const librarySourceMap = [
140-
// Host library
141-
{ target: "lib.dom.d.ts", sources: ["header.d.ts", "dom.generated.d.ts"] },
142-
{ target: "lib.dom.iterable.d.ts", sources: ["header.d.ts", "dom.iterable.d.ts"] },
143-
{ target: "lib.webworker.d.ts", sources: ["header.d.ts", "webworker.generated.d.ts"] },
144-
{ target: "lib.scripthost.d.ts", sources: ["header.d.ts", "scripthost.d.ts"] },
145-
146-
// JavaScript library
147-
{ target: "lib.es5.d.ts", sources: ["header.d.ts", "es5.d.ts"] },
148-
{ target: "lib.es2015.d.ts", sources: ["header.d.ts", "es2015.d.ts"] },
149-
{ target: "lib.es2016.d.ts", sources: ["header.d.ts", "es2016.d.ts"] },
150-
{ target: "lib.es2017.d.ts", sources: ["header.d.ts", "es2017.d.ts"] },
151-
152-
// JavaScript + all host library
153-
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) },
154-
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") }
140+
// Host library
141+
{ target: "lib.dom.d.ts", sources: ["header.d.ts", "dom.generated.d.ts"] },
142+
{ target: "lib.dom.iterable.d.ts", sources: ["header.d.ts", "dom.iterable.d.ts"] },
143+
{ target: "lib.webworker.d.ts", sources: ["header.d.ts", "webworker.generated.d.ts"] },
144+
{ target: "lib.scripthost.d.ts", sources: ["header.d.ts", "scripthost.d.ts"] },
145+
146+
// JavaScript library
147+
{ target: "lib.es5.d.ts", sources: ["header.d.ts", "es5.d.ts"] },
148+
{ target: "lib.es2015.d.ts", sources: ["header.d.ts", "es2015.d.ts"] },
149+
{ target: "lib.es2016.d.ts", sources: ["header.d.ts", "es2016.d.ts"] },
150+
{ target: "lib.es2017.d.ts", sources: ["header.d.ts", "es2017.d.ts"] },
151+
152+
// JavaScript + all host library
153+
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) },
154+
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") }
155155
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap);
156156

157-
const libraryTargets = librarySourceMap.map(function (f) {
157+
const libraryTargets = librarySourceMap.map(function(f) {
158158
return path.join(builtLocalDirectory, f.target);
159159
});
160160

161161
for (const i in libraryTargets) {
162162
const entry = librarySourceMap[i];
163163
const target = libraryTargets[i];
164-
const sources = [copyright].concat(entry.sources.map(function (s) {
164+
const sources = [copyright].concat(entry.sources.map(function(s) {
165165
return path.join(libraryDirectory, s);
166166
}));
167167
gulp.task(target, false, [], function() {
@@ -391,7 +391,7 @@ gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
391391
.pipe(sourcemaps.init())
392392
.pipe(tsc(servicesProject));
393393
const completedJs = js.pipe(prependCopyright())
394-
.pipe(sourcemaps.write("."));
394+
.pipe(sourcemaps.write("."));
395395
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/true))
396396
.pipe(insert.transform((contents, file) => {
397397
file.path = standaloneDefinitionsFile;
@@ -434,17 +434,17 @@ const tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverli
434434

435435
gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
436436
const serverLibraryProject = tsc.createProject("src/server/tsconfig.library.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
437-
const {js, dts}: {js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream} = serverLibraryProject.src()
437+
const {js, dts}: { js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream } = serverLibraryProject.src()
438438
.pipe(sourcemaps.init())
439439
.pipe(newer(tsserverLibraryFile))
440440
.pipe(tsc(serverLibraryProject));
441441

442442
return merge2([
443443
js.pipe(prependCopyright())
444-
.pipe(sourcemaps.write("."))
445-
.pipe(gulp.dest(builtLocalDirectory)),
444+
.pipe(sourcemaps.write("."))
445+
.pipe(gulp.dest(builtLocalDirectory)),
446446
dts.pipe(prependCopyright())
447-
.pipe(gulp.dest(builtLocalDirectory))
447+
.pipe(gulp.dest(builtLocalDirectory))
448448
]);
449449
});
450450

@@ -476,7 +476,7 @@ gulp.task(specMd, false, [word2mdJs], (done) => {
476476
const specMDFullPath = path.resolve(specMd);
477477
const cmd = "cscript //nologo " + word2mdJs + " \"" + specWordFullPath + "\" " + "\"" + specMDFullPath + "\"";
478478
console.log(cmd);
479-
cp.exec(cmd, function () {
479+
cp.exec(cmd, function() {
480480
done();
481481
});
482482
});
@@ -492,12 +492,12 @@ gulp.task("dontUseDebugMode", false, [], (done) => { useDebugMode = false; done(
492492

493493
gulp.task("VerifyLKG", false, [], () => {
494494
const expectedFiles = [builtLocalCompiler, servicesFile, serverFile, nodePackageFile, nodeDefinitionsFile, standaloneDefinitionsFile, tsserverLibraryFile, tsserverLibraryDefinitionFile].concat(libraryTargets);
495-
const missingFiles = expectedFiles.filter(function (f) {
495+
const missingFiles = expectedFiles.filter(function(f) {
496496
return !fs.existsSync(f);
497497
});
498498
if (missingFiles.length > 0) {
499499
throw new Error("Cannot replace the LKG unless all built targets are present in directory " + builtLocalDirectory +
500-
". The following files are missing:\n" + missingFiles.join("\n"));
500+
". The following files are missing:\n" + missingFiles.join("\n"));
501501
}
502502
// Copy all the targets into the LKG directory
503503
return gulp.src(expectedFiles).pipe(gulp.dest(LKGDirectory));
@@ -627,7 +627,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
627627
}
628628
args.push(run);
629629
setNodeEnvToDevelopment();
630-
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: colors === " --no-colors " }, function (err) {
630+
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: colors === " --no-colors " }, function(err) {
631631
// last worker clean everything and runs linter in case if there were no errors
632632
del(taskConfigsFolder).then(() => {
633633
if (!err) {
@@ -679,7 +679,7 @@ gulp.task("runtests",
679679
["build-rules", "tests"],
680680
(done) => {
681681
runConsoleTests("mocha-fivemat-progress-reporter", /*runInParallel*/ false, done);
682-
});
682+
});
683683

684684
const nodeServerOutFile = "tests/webTestServer.js";
685685
const nodeServerInFile = "tests/webTestServer.ts";
@@ -812,31 +812,38 @@ gulp.task("diff-rwc", "Diffs the RWC baselines using the diff tool specified by
812812
});
813813

814814

815-
gulp.task("baseline-accept", "Makes the most recent test results the new baseline, overwriting the old baseline", (done) => {
816-
const softAccept = cmdLineOptions["soft"];
817-
if (!softAccept) {
818-
del(refBaseline).then(() => {
819-
fs.renameSync(localBaseline, refBaseline);
820-
done();
821-
}, done);
822-
}
823-
else {
824-
gulp.src(localBaseline)
825-
.pipe(gulp.dest(refBaseline))
826-
.on("end", () => {
827-
del(path.join(refBaseline, "local")).then(() => done(), done);
828-
});
829-
}
815+
const deleteEnding = '.delete';
816+
gulp.task("baseline-accept", "Makes the most recent test results the new baseline, overwriting the old baseline", () => {
817+
return baselineAccept("");
830818
});
819+
820+
function baselineAccept(subfolder = "") {
821+
return merge2(baselineCopy(subfolder), baselineDelete(subfolder));
822+
}
823+
824+
function baselineCopy(subfolder = "") {
825+
return gulp.src([`tests/baselines/local/${subfolder}/**`, `!tests/baselines/local/${subfolder}/**/*.delete`])
826+
.pipe(gulp.dest(refBaseline));
827+
}
828+
829+
function baselineDelete(subfolder = "") {
830+
return gulp.src(['tests/baselines/local/**/*.delete'])
831+
.pipe(insert.transform((content, fileObj) => {
832+
const target = path.join(refBaseline, fileObj.relative.substr(0, fileObj.relative.length - '.delete'.length));
833+
console.log(target);
834+
del.sync(target);
835+
del.sync(fileObj.path);
836+
return '';
837+
}));
838+
}
839+
831840
gulp.task("baseline-accept-rwc", "Makes the most recent rwc test results the new baseline, overwriting the old baseline", () => {
832-
return del(refRwcBaseline).then(() => {
833-
fs.renameSync(localRwcBaseline, refRwcBaseline);
834-
});
841+
return baselineAccept("rwc");
835842
});
843+
844+
836845
gulp.task("baseline-accept-test262", "Makes the most recent test262 test results the new baseline, overwriting the old baseline", () => {
837-
return del(refTest262Baseline).then(() => {
838-
fs.renameSync(localTest262Baseline, refTest262Baseline);
839-
});
846+
return baselineAccept("test262");
840847
});
841848

842849

Jakefile.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use strict";
12
// This file contains the build logic for the public repo
23

34
var fs = require("fs");
@@ -898,16 +899,16 @@ task("tests-debug", ["setDebugMode", "tests"]);
898899
// Makes the test results the new baseline
899900
desc("Makes the most recent test results the new baseline, overwriting the old baseline");
900901
task("baseline-accept", function(hardOrSoft) {
901-
if (!hardOrSoft || hardOrSoft === "hard") {
902-
jake.rmRf(refBaseline);
903-
fs.renameSync(localBaseline, refBaseline);
904-
}
905-
else if (hardOrSoft === "soft") {
906-
var files = jake.readdirR(localBaseline);
907-
for (var i in files) {
902+
var files = jake.readdirR(localBaseline);
903+
var deleteEnding = '.delete';
904+
for (var i in files) {
905+
if (files[i].substr(files[i].length - deleteEnding.length) === deleteEnding) {
906+
var filename = path.basename(files[i]);
907+
filename = filename.substr(0, filename.length - deleteEnding.length);
908+
fs.unlink(path.join(refBaseline, filename));
909+
} else {
908910
jake.cpR(files[i], refBaseline);
909911
}
910-
jake.rmRf(path.join(refBaseline, "local"));
911912
}
912913
});
913914

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"mkdirp": "latest",
7070
"mocha": "latest",
7171
"mocha-fivemat-progress-reporter": "latest",
72+
"q": "latest",
7273
"run-sequence": "latest",
7374
"sorcery": "latest",
7475
"through2": "latest",

scripts/types/ambient.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare module "gulp-insert" {
1010
export function append(text: string | Buffer): NodeJS.ReadWriteStream;
1111
export function prepend(text: string | Buffer): NodeJS.ReadWriteStream;
1212
export function wrap(text: string | Buffer, tail: string | Buffer): NodeJS.ReadWriteStream;
13-
export function transform(cb: (contents: string, file: {path: string}) => string): NodeJS.ReadWriteStream; // file is a vinyl file
13+
export function transform(cb: (contents: string, file: {path: string, relative: string}) => string): NodeJS.ReadWriteStream; // file is a vinyl file
1414
}
1515

1616
declare module "into-stream" {

src/harness/harness.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@ namespace Harness {
15691569

15701570
/** Support class for baseline files */
15711571
export namespace Baseline {
1572+
const NoContent = "<no content>";
15721573

15731574
export interface BaselineOptions {
15741575
Subfolder?: string;
@@ -1635,14 +1636,6 @@ namespace Harness {
16351636
throw new Error("The generated content was \"undefined\". Return \"null\" if no baselining is required.\"");
16361637
}
16371638

1638-
// Store the content in the 'local' folder so we
1639-
// can accept it later (manually)
1640-
/* tslint:disable:no-null-keyword */
1641-
if (actual !== null) {
1642-
/* tslint:enable:no-null-keyword */
1643-
IO.writeFile(actualFileName, actual);
1644-
}
1645-
16461639
return actual;
16471640
}
16481641

@@ -1659,7 +1652,7 @@ namespace Harness {
16591652
/* tslint:disable:no-null-keyword */
16601653
if (actual === null) {
16611654
/* tslint:enable:no-null-keyword */
1662-
actual = "<no content>";
1655+
actual = NoContent;
16631656
}
16641657

16651658
let expected = "<no content>";
@@ -1672,7 +1665,13 @@ namespace Harness {
16721665

16731666
function writeComparison(expected: string, actual: string, relativeFileName: string, actualFileName: string, descriptionForDescribe: string) {
16741667
const encoded_actual = Utils.encodeString(actual);
1675-
if (expected != encoded_actual) {
1668+
if (expected !== encoded_actual) {
1669+
if (actual === NoContent) {
1670+
IO.writeFile(relativeFileName + '.delete', '');
1671+
}
1672+
else {
1673+
IO.writeFile(relativeFileName, actual);
1674+
}
16761675
// Overwrite & issue error
16771676
const errMsg = "The baseline file " + relativeFileName + " has changed.";
16781677
throw new Error(errMsg);

0 commit comments

Comments
 (0)