From 8d99ecfa6caddb9f5a37e1829b11d4811bdb7ce1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 29 Apr 2015 12:13:35 -0700 Subject: [PATCH] Add a light=true mode for running tests faster. --- Jakefile.js | 14 ++++--- src/compiler/checker.ts | 5 ++- src/compiler/types.ts | 4 ++ src/harness/compilerRunner.ts | 3 +- src/harness/harness.ts | 5 ++- src/harness/runner.ts | 79 ++++++++++++++++++++--------------- 6 files changed, 66 insertions(+), 44 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index cb53b479502..78622f67287 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -503,9 +503,9 @@ function cleanTestDirs() { } // used to pass data from jake command line directly to run.js -function writeTestConfigFile(tests, testConfigFile) { +function writeTestConfigFile(tests, light, testConfigFile) { console.log('Running test(s): ' + tests); - var testConfigContents = '{\n' + '\ttest: [\'' + tests + '\']\n}'; + var testConfigContents = JSON.stringify({ test: [tests], light: light }); fs.writeFileSync('test.config', testConfigContents); } @@ -521,13 +521,14 @@ task("runtests", ["tests", builtLocalDirectory], function() { cleanTestDirs(); host = "mocha" tests = process.env.test || process.env.tests || process.env.t; + var light = process.env.light || false; var testConfigFile = 'test.config'; if(fs.existsSync(testConfigFile)) { fs.unlinkSync(testConfigFile); } - if(tests) { - writeTestConfigFile(tests, testConfigFile); + if(tests || light) { + writeTestConfigFile(tests, light, testConfigFile); } if (tests && tests.toLocaleLowerCase() === "rwc") { @@ -570,12 +571,13 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function( port = process.env.port || process.env.p || '8888'; browser = process.env.browser || process.env.b || "IE"; tests = process.env.test || process.env.tests || process.env.t; + var light = process.env.light || false; var testConfigFile = 'test.config'; if(fs.existsSync(testConfigFile)) { fs.unlinkSync(testConfigFile); } - if(tests) { - writeTestConfigFile(tests, testConfigFile); + if(tests || light) { + writeTestConfigFile(tests, light, testConfigFile); } tests = tests ? tests : ''; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bbfa681d72e..03c2fbd9630 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10934,7 +10934,10 @@ module ts { function checkSourceFile(node: SourceFile) { let start = new Date().getTime(); - checkSourceFileWorker(node); + let skipCheck = node.fileName.indexOf("lib.d.ts") >= 0 && compilerOptions.noLibCheck; + if (!skipCheck) { + checkSourceFileWorker(node); + } checkTime += new Date().getTime() - start; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 94053a6484d..2f4e33a6e8b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1677,6 +1677,10 @@ module ts { separateCompilation?: boolean; emitDecoratorMetadata?: boolean; /* @internal */ stripInternal?: boolean; + + // Skip checking lib.d.ts to help speed up tests. + /* @internal */ noLibCheck?: boolean; + [option: string]: string | number | boolean; } diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index b6997e705b9..11822e2fec5 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -171,7 +171,6 @@ class CompilerBaselineRunner extends RunnerBase { } }); - it('Correct JS output for ' + fileName, () => { if (!ts.fileExtensionIs(lastUnit.name, '.d.ts') && this.emit) { if (result.files.length === 0 && result.errors.length === 0) { @@ -259,7 +258,7 @@ class CompilerBaselineRunner extends RunnerBase { }); it('Correct type/symbol baselines for ' + fileName, () => { - if (fileName.indexOf("APISample") >= 0) { + if (fileName.indexOf("APISample") >= 0 || lightMode) { return; } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 6af77e3d746..70c5cae8c49 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -800,7 +800,7 @@ module Harness { // Only set the parent nodes if we're asserting invariants. We don't need them otherwise. var result = ts.createSourceFile(fileName, sourceText, languageVersion, /*setParentNodes:*/ assertInvariants); if (assertInvariants) { - Utils.assertInvariants(result, /*parent:*/ undefined); + // Utils.assertInvariants(result, /*parent:*/ undefined); } return result; } @@ -937,6 +937,9 @@ module Harness { options.target = options.target || ts.ScriptTarget.ES3; options.module = options.module || ts.ModuleKind.None; options.noErrorTruncation = true; + if (lightMode) { + options.noLibCheck = true; + } if (settingsCallback) { settingsCallback(null); diff --git a/src/harness/runner.ts b/src/harness/runner.ts index 37451639d75..4bcd5643efa 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -36,43 +36,54 @@ var testconfig = 'test.config'; var testConfigFile = Harness.IO.fileExists(mytestconfig) ? Harness.IO.readFile(mytestconfig) : (Harness.IO.fileExists(testconfig) ? Harness.IO.readFile(testconfig) : ''); +var lightMode: boolean; if (testConfigFile !== '') { // TODO: not sure why this is crashing mocha - //var testConfig = JSON.parse(testConfigRaw); - var testConfig = testConfigFile.match(/test:\s\['(.*)'\]/); - var options = testConfig ? [testConfig[1]] : []; - for (var i = 0; i < options.length; i++) { - switch (options[i]) { - case 'compiler': - runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance)); - runners.push(new CompilerBaselineRunner(CompilerTestType.Regressions)); - runners.push(new ProjectRunner()); - break; - case 'conformance': - runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance)); - break; - case 'project': - runners.push(new ProjectRunner()); - break; - case 'fourslash': - runners.push(new FourSlashRunner(FourSlashTestType.Native)); - break; - case 'fourslash-shims': - runners.push(new FourSlashRunner(FourSlashTestType.Shims)); - break; - case 'fourslash-server': - runners.push(new FourSlashRunner(FourSlashTestType.Server)); - break; - case 'fourslash-generated': - runners.push(new GeneratedFourslashRunner(FourSlashTestType.Native)); - break; - case 'rwc': - runners.push(new RWCRunner()); - break; - case 'test262': - runners.push(new Test262BaselineRunner()); - break; + var testConfig = JSON.parse(testConfigFile); + //var testConfig = testConfigFile.match(/test:\s\['(.*)'\]/); + //var options = testConfig ? [testConfig[1]] : []; + if (testConfig.light) { + lightMode = true; + } + + if (testConfig.test && testConfig.test.length > 0) { + for (let option of testConfig.test) { + if (!option) { + continue; + } + ts.sys.write("Option: " + option + "\r\n"); + switch (option) { + case 'compiler': + runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance)); + runners.push(new CompilerBaselineRunner(CompilerTestType.Regressions)); + runners.push(new ProjectRunner()); + break; + case 'conformance': + runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance)); + break; + case 'project': + runners.push(new ProjectRunner()); + break; + case 'fourslash': + runners.push(new FourSlashRunner(FourSlashTestType.Native)); + break; + case 'fourslash-shims': + runners.push(new FourSlashRunner(FourSlashTestType.Shims)); + break; + case 'fourslash-server': + runners.push(new FourSlashRunner(FourSlashTestType.Server)); + break; + case 'fourslash-generated': + runners.push(new GeneratedFourslashRunner(FourSlashTestType.Native)); + break; + case 'rwc': + runners.push(new RWCRunner()); + break; + case 'test262': + runners.push(new Test262BaselineRunner()); + break; + } } } }