Skip to content

Commit 46a842e

Browse files
Merge pull request microsoft#3049 from Microsoft/testPerf
Create "light" test-running mode and a '--noLibCheck' flag
2 parents 60e855e + c2fa08b commit 46a842e

20 files changed

+137
-241
lines changed

Jakefile.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,9 @@ function cleanTestDirs() {
505505
}
506506

507507
// used to pass data from jake command line directly to run.js
508-
function writeTestConfigFile(tests, testConfigFile) {
508+
function writeTestConfigFile(tests, light, testConfigFile) {
509509
console.log('Running test(s): ' + tests);
510-
var testConfigContents = JSON.stringify({ test: [tests]});
510+
var testConfigContents = JSON.stringify({ test: [tests], light: light });
511511
fs.writeFileSync('test.config', testConfigContents);
512512
}
513513

@@ -523,13 +523,14 @@ task("runtests", ["tests", builtLocalDirectory], function() {
523523
cleanTestDirs();
524524
host = "mocha"
525525
tests = process.env.test || process.env.tests || process.env.t;
526+
var light = process.env.light || false;
526527
var testConfigFile = 'test.config';
527528
if(fs.existsSync(testConfigFile)) {
528529
fs.unlinkSync(testConfigFile);
529530
}
530531

531-
if(tests) {
532-
writeTestConfigFile(tests, testConfigFile);
532+
if(tests || light) {
533+
writeTestConfigFile(tests, light, testConfigFile);
533534
}
534535

535536
if (tests && tests.toLocaleLowerCase() === "rwc") {
@@ -572,12 +573,13 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function(
572573
port = process.env.port || process.env.p || '8888';
573574
browser = process.env.browser || process.env.b || "IE";
574575
tests = process.env.test || process.env.tests || process.env.t;
576+
var light = process.env.light || false;
575577
var testConfigFile = 'test.config';
576578
if(fs.existsSync(testConfigFile)) {
577579
fs.unlinkSync(testConfigFile);
578580
}
579-
if(tests) {
580-
writeTestConfigFile(tests, testConfigFile);
581+
if(tests || light) {
582+
writeTestConfigFile(tests, light, testConfigFile);
581583
}
582584

583585
tests = tests ? tests : '';

src/compiler/checker.ts

+4
Original file line numberDiff line numberDiff line change
@@ -11609,14 +11609,18 @@ namespace ts {
1160911609

1161011610
function checkSourceFile(node: SourceFile) {
1161111611
let start = new Date().getTime();
11612+
1161211613
checkSourceFileWorker(node);
11614+
1161311615
checkTime += new Date().getTime() - start;
1161411616
}
1161511617

1161611618
// Fully type check a source file and collect the relevant diagnostics.
1161711619
function checkSourceFileWorker(node: SourceFile) {
1161811620
let links = getNodeLinks(node);
1161911621
if (!(links.flags & NodeCheckFlags.TypeChecked)) {
11622+
// Check whether the file has declared it is the default lib,
11623+
// and whether the user has specifically chosen to avoid checking it.
1162011624
if (node.isDefaultLib && compilerOptions.skipDefaultLibCheck) {
1162111625
return;
1162211626
}

src/compiler/program.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,30 @@ namespace ts {
144144
let program: Program;
145145
let files: SourceFile[] = [];
146146
let diagnostics = createDiagnosticCollection();
147-
let skipDefaultLib = options.noLib;
147+
148148
let commonSourceDirectory: string;
149149
let diagnosticsProducingTypeChecker: TypeChecker;
150150
let noDiagnosticsTypeChecker: TypeChecker;
151151
let classifiableNames: Map<string>;
152152

153+
let skipDefaultLib = options.noLib;
154+
153155
let start = new Date().getTime();
154156

155157
host = host || createCompilerHost(options);
158+
156159
let filesByName = createFileMap<SourceFile>(fileName => host.getCanonicalFileName(fileName));
157160

158161
forEach(rootNames, name => processRootFile(name, /*isDefaultLib:*/ false));
162+
163+
// Do not process the default library if:
164+
// - The '--noLib' flag is used.
165+
// - A 'no-default-lib' reference comment is encountered in
166+
// processing the root files.
159167
if (!skipDefaultLib) {
160168
processRootFile(host.getDefaultLibFileName(options), /*isDefaultLib:*/ true);
161169
}
170+
162171
verifyCompilerOptions();
163172

164173
programTime += new Date().getTime() - start;

src/compiler/types.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,14 @@ namespace ts {
11491149
moduleName: string;
11501150
referencedFiles: FileReference[];
11511151

1152+
/**
1153+
* lib.d.ts should have a reference comment like
1154+
*
1155+
* /// <reference no-default-lib="true"/>
1156+
*
1157+
* If any other file has this comment, it signals not to include lib.d.ts
1158+
* because this containing file is intended to act as a default library.
1159+
*/
11521160
hasNoDefaultLib: boolean;
11531161

11541162
languageVersion: ScriptTarget;
@@ -1860,7 +1868,10 @@ namespace ts {
18601868
experimentalDecorators?: boolean;
18611869
emitDecoratorMetadata?: boolean;
18621870
/* @internal */ stripInternal?: boolean;
1871+
1872+
// Skip checking lib.d.ts to help speed up tests.
18631873
/* @internal */ skipDefaultLibCheck?: boolean;
1874+
18641875
[option: string]: string | number | boolean;
18651876
}
18661877

src/harness/compilerRunner.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/// <reference path='harness.ts' />
22
/// <reference path='runnerbase.ts' />
33
/// <reference path='typeWriter.ts' />
4-
/// <reference path='syntacticCleaner.ts' />
54

65
const enum CompilerTestType {
76
Conformance,
@@ -18,7 +17,7 @@ class CompilerBaselineRunner extends RunnerBase {
1817

1918
public options: string;
2019

21-
constructor(public testType?: CompilerTestType) {
20+
constructor(public testType: CompilerTestType) {
2221
super();
2322
this.errors = true;
2423
this.emit = true;
@@ -171,7 +170,6 @@ class CompilerBaselineRunner extends RunnerBase {
171170
}
172171
});
173172

174-
175173
it('Correct JS output for ' + fileName, () => {
176174
if (!ts.fileExtensionIs(lastUnit.name, '.d.ts') && this.emit) {
177175
if (result.files.length === 0 && result.errors.length === 0) {
@@ -195,8 +193,6 @@ class CompilerBaselineRunner extends RunnerBase {
195193
jsCode += '//// [' + Harness.Path.getFileName(result.files[i].fileName) + ']\r\n';
196194
jsCode += getByteOrderMarkText(result.files[i]);
197195
jsCode += result.files[i].code;
198-
// Re-enable this if we want to do another comparison of old vs new compiler baselines
199-
// jsCode += SyntacticCleaner.clean(result.files[i].code);
200196
}
201197

202198
if (result.declFilesCode.length > 0) {

src/harness/exec.ts

-74
This file was deleted.

src/harness/fourslash.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ module FourSlash {
343343
if (!resolvedResult.isLibFile) {
344344
this.languageServiceAdapterHost.addScript(Harness.Compiler.defaultLibFileName, Harness.Compiler.defaultLibSourceFile.text);
345345
}
346-
} else {
346+
}
347+
else {
347348
// resolveReference file-option is not specified then do not resolve any files and include all inputFiles
348349
ts.forEachKey(this.inputFiles, fileName => {
349350
if (!Harness.isLibraryFile(fileName)) {

0 commit comments

Comments
 (0)