@@ -5,6 +5,7 @@ var os = require("os");
55var path = require ( "path" ) ;
66var child_process = require ( "child_process" ) ;
77var Linter = require ( "tslint" ) ;
8+ var runTestsInParallel = require ( "./scripts/mocha-parallel" ) . runTestsInParallel ;
89
910// Variables
1011var compilerDirectory = "src/compiler/" ;
@@ -155,6 +156,7 @@ var harnessSources = harnessCoreSources.concat([
155156 "commandLineParsing.ts" ,
156157 "convertCompilerOptionsFromJson.ts" ,
157158 "convertTypingOptionsFromJson.ts" ,
159+ "tsserverProjectSystem.ts" ,
158160 "matchFiles.ts"
159161] . map ( function ( f ) {
160162 return path . join ( unittestsDirectory , f ) ;
@@ -189,7 +191,10 @@ var es2016LibrarySourceMap = es2016LibrarySource.map(function (source) {
189191 return { target : "lib." + source , sources : [ "header.d.ts" , source ] } ;
190192} ) ;
191193
192- var es2017LibrarySource = [ "es2017.object.d.ts" ] ;
194+ var es2017LibrarySource = [
195+ "es2017.object.d.ts" ,
196+ "es2017.sharedmemory.d.ts"
197+ ] ;
193198
194199var es2017LibrarySourceMap = es2017LibrarySource . map ( function ( source ) {
195200 return { target : "lib." + source , sources : [ "header.d.ts" , source ] } ;
@@ -209,7 +214,7 @@ var librarySourceMap = [
209214 { target : "lib.es2015.d.ts" , sources : [ "header.d.ts" , "es2015.d.ts" ] } ,
210215 { target : "lib.es2016.d.ts" , sources : [ "header.d.ts" , "es2016.d.ts" ] } ,
211216 { target : "lib.es2017.d.ts" , sources : [ "header.d.ts" , "es2017.d.ts" ] } ,
212-
217+
213218 // JavaScript + all host library
214219 { target : "lib.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] . concat ( hostsLibrarySources ) } ,
215220 { target : "lib.es6.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] . concat ( es2015LibrarySources , hostsLibrarySources , "dom.iterable.d.ts" ) }
@@ -273,6 +278,7 @@ var builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename);
273278 * @param {boolean } opts.noResolve: true if compiler should not include non-rooted files in compilation
274279 * @param {boolean } opts.stripInternal: true if compiler should remove declarations marked as @internal
275280 * @param {boolean } opts.noMapRoot: true if compiler omit mapRoot option
281+ * @param {boolean } opts.inlineSourceMap: true if compiler should inline sourceMap
276282 * @param callback: a function to execute after the compilation process ends
277283 */
278284function compileFile ( outFile , sources , prereqs , prefixes , useBuiltCompiler , opts , callback ) {
@@ -310,10 +316,16 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
310316 }
311317
312318 if ( useDebugMode ) {
313- options += " -sourcemap" ;
314- if ( ! opts . noMapRoot ) {
315- options += " -mapRoot file:///" + path . resolve ( path . dirname ( outFile ) ) ;
319+ if ( opts . inlineSourceMap ) {
320+ options += " --inlineSourceMap --inlineSources" ;
321+ } else {
322+ options += " -sourcemap" ;
323+ if ( ! opts . noMapRoot ) {
324+ options += " -mapRoot file:///" + path . resolve ( path . dirname ( outFile ) ) ;
325+ }
316326 }
327+ } else {
328+ options += " --newLine LF" ;
317329 }
318330
319331 if ( opts . stripInternal ) {
@@ -490,7 +502,13 @@ var nodeStandaloneDefinitionsFile = path.join(builtLocalDirectory, "typescript_s
490502compileFile ( servicesFile , servicesSources , [ builtLocalDirectory , copyright ] . concat ( servicesSources ) ,
491503 /*prefixes*/ [ copyright ] ,
492504 /*useBuiltCompiler*/ true ,
493- { noOutFile : false , generateDeclarations : true , preserveConstEnums : true , keepComments : true , noResolve : false , stripInternal : true } ,
505+ /*opts*/ { noOutFile : false ,
506+ generateDeclarations : true ,
507+ preserveConstEnums : true ,
508+ keepComments : true ,
509+ noResolve : false ,
510+ stripInternal : true
511+ } ,
494512 /*callback*/ function ( ) {
495513 jake . cpR ( servicesFile , nodePackageFile , { silent : true } ) ;
496514
@@ -513,16 +531,21 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca
513531 fs . writeFileSync ( nodeStandaloneDefinitionsFile , nodeStandaloneDefinitionsFileContents ) ;
514532 } ) ;
515533
516- compileFile ( servicesFileInBrowserTest , servicesSources , [ builtLocalDirectory , copyright ] . concat ( servicesSources ) ,
517- /*prefixes*/ [ copyright ] ,
518- /*useBuiltCompiler*/ true ,
519- { noOutFile : false , generateDeclarations : true , preserveConstEnums : true , keepComments : true , noResolve : false , stripInternal : true , noMapRoot : true } ,
520- /*callback*/ function ( ) {
521- var content = fs . readFileSync ( servicesFileInBrowserTest ) . toString ( ) ;
522- var i = content . lastIndexOf ( "\n" ) ;
523- fs . writeFileSync ( servicesFileInBrowserTest , content . substring ( 0 , i ) + "\r\n//# sourceURL=../built/local/typeScriptServices.js" + content . substring ( i ) ) ;
524- } ) ;
525-
534+ compileFile (
535+ servicesFileInBrowserTest ,
536+ servicesSources ,
537+ [ builtLocalDirectory , copyright ] . concat ( servicesSources ) ,
538+ /*prefixes*/ [ copyright ] ,
539+ /*useBuiltCompiler*/ true ,
540+ { noOutFile : false ,
541+ generateDeclarations : true ,
542+ preserveConstEnums : true ,
543+ keepComments : true ,
544+ noResolve : false ,
545+ stripInternal : true ,
546+ noMapRoot : true ,
547+ inlineSourceMap : true
548+ } ) ;
526549
527550var serverFile = path . join ( builtLocalDirectory , "tsserver.js" ) ;
528551compileFile ( serverFile , serverSources , [ builtLocalDirectory , copyright ] . concat ( serverSources ) , /*prefixes*/ [ copyright ] , /*useBuiltCompiler*/ true ) ;
@@ -623,7 +646,13 @@ directory(builtLocalDirectory);
623646
624647// Task to build the tests infrastructure using the built compiler
625648var run = path . join ( builtLocalDirectory , "run.js" ) ;
626- compileFile ( run , harnessSources , [ builtLocalDirectory , tscFile ] . concat ( libraryTargets ) . concat ( harnessSources ) , [ ] , /*useBuiltCompiler:*/ true ) ;
649+ compileFile (
650+ /*outFile*/ run ,
651+ /*source*/ harnessSources ,
652+ /*prereqs*/ [ builtLocalDirectory , tscFile ] . concat ( libraryTargets ) . concat ( harnessSources ) ,
653+ /*prefixes*/ [ ] ,
654+ /*useBuiltCompiler:*/ true ,
655+ /*opts*/ { inlineSourceMap : true } ) ;
627656
628657var internalTests = "internal/" ;
629658
@@ -682,9 +711,8 @@ function cleanTestDirs() {
682711}
683712
684713// used to pass data from jake command line directly to run.js
685- function writeTestConfigFile ( tests , light , testConfigFile ) {
686- console . log ( 'Running test(s): ' + tests ) ;
687- var testConfigContents = JSON . stringify ( { test : [ tests ] , light : light } ) ;
714+ function writeTestConfigFile ( tests , light , taskConfigsFolder , workerCount ) {
715+ var testConfigContents = JSON . stringify ( { test : tests ? [ tests ] : undefined , light : light , workerCount : workerCount , taskConfigsFolder : taskConfigsFolder } ) ;
688716 fs . writeFileSync ( 'test.config' , testConfigContents ) ;
689717}
690718
@@ -694,7 +722,7 @@ function deleteTemporaryProjectOutput() {
694722 }
695723}
696724
697- function runConsoleTests ( defaultReporter , defaultSubsets ) {
725+ function runConsoleTests ( defaultReporter , runInParallel ) {
698726 cleanTestDirs ( ) ;
699727 var debug = process . env . debug || process . env . d ;
700728 tests = process . env . test || process . env . tests || process . env . t ;
@@ -703,9 +731,22 @@ function runConsoleTests(defaultReporter, defaultSubsets) {
703731 if ( fs . existsSync ( testConfigFile ) ) {
704732 fs . unlinkSync ( testConfigFile ) ;
705733 }
734+ var workerCount , taskConfigsFolder ;
735+ if ( runInParallel ) {
736+ // generate name to store task configuration files
737+ var prefix = os . tmpdir ( ) + "/ts-tests" ;
738+ var i = 1 ;
739+ do {
740+ taskConfigsFolder = prefix + i ;
741+ i ++ ;
742+ } while ( fs . existsSync ( taskConfigsFolder ) ) ;
743+ fs . mkdirSync ( taskConfigsFolder ) ;
744+
745+ workerCount = process . env . workerCount || os . cpus ( ) . length ;
746+ }
706747
707- if ( tests || light ) {
708- writeTestConfigFile ( tests , light , testConfigFile ) ;
748+ if ( tests || light || taskConfigsFolder ) {
749+ writeTestConfigFile ( tests , light , taskConfigsFolder , workerCount ) ;
709750 }
710751
711752 if ( tests && tests . toLocaleLowerCase ( ) === "rwc" ) {
@@ -719,61 +760,76 @@ function runConsoleTests(defaultReporter, defaultSubsets) {
719760
720761 // timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally
721762 // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
722- var subsetRegexes ;
723- if ( defaultSubsets . length === 0 ) {
724- subsetRegexes = [ tests ] ;
725- }
726- else {
727- var subsets = tests ? tests . split ( "|" ) : defaultSubsets ;
728- subsetRegexes = subsets . map ( function ( sub ) { return "^" + sub + ".*$" ; } ) ;
729- subsetRegexes . push ( "^(?!" + subsets . join ( "|" ) + ").*$" ) ;
730- }
731- var counter = subsetRegexes . length ;
732- var errorStatus ;
733- subsetRegexes . forEach ( function ( subsetRegex , i ) {
734- tests = subsetRegex ? ' -g "' + subsetRegex + '"' : '' ;
763+ if ( ! runInParallel ) {
764+ tests = tests ? ' -g "' + tests + '"' : '' ;
735765 var cmd = "mocha" + ( debug ? " --debug-brk" : "" ) + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run ;
736766 console . log ( cmd ) ;
737- function finish ( status ) {
738- counter -- ;
739- // save first error status
740- if ( status !== undefined && errorStatus === undefined ) {
741- errorStatus = status ;
742- }
743767
768+ var savedNodeEnv = process . env . NODE_ENV ;
769+ process . env . NODE_ENV = "development" ;
770+ exec ( cmd , function ( ) {
771+ process . env . NODE_ENV = savedNodeEnv ;
772+ runLinter ( ) ;
773+ finish ( ) ;
774+ } , function ( e , status ) {
775+ process . env . NODE_ENV = savedNodeEnv ;
776+ finish ( status ) ;
777+ } ) ;
778+
779+ }
780+ else {
781+ var savedNodeEnv = process . env . NODE_ENV ;
782+ process . env . NODE_ENV = "development" ;
783+ runTestsInParallel ( taskConfigsFolder , run , { testTimeout : testTimeout , noColors : colors === " --no-colors " } , function ( err ) {
784+ process . env . NODE_ENV = savedNodeEnv ;
785+
786+ // last worker clean everything and runs linter in case if there were no errors
744787 deleteTemporaryProjectOutput ( ) ;
745- if ( counter !== 0 || errorStatus === undefined ) {
746- // run linter when last worker is finished
747- if ( lintFlag && counter === 0 ) {
748- var lint = jake . Task [ 'lint' ] ;
749- lint . addListener ( 'complete' , function ( ) {
750- complete ( ) ;
751- } ) ;
752- lint . invoke ( ) ;
753- }
754- complete ( ) ;
788+ jake . rmRf ( taskConfigsFolder ) ;
789+ if ( err ) {
790+ fail ( err ) ;
755791 }
756792 else {
757- fail ( "Process exited with code " + status ) ;
793+ runLinter ( ) ;
794+ complete ( ) ;
758795 }
796+ } ) ;
797+ }
798+
799+ function failWithStatus ( status ) {
800+ fail ( "Process exited with code " + status ) ;
801+ }
802+
803+ function finish ( errorStatus ) {
804+ deleteTemporaryProjectOutput ( ) ;
805+ if ( errorStatus !== undefined ) {
806+ failWithStatus ( errorStatus ) ;
759807 }
760- exec ( cmd , function ( ) {
761- finish ( ) ;
762- } , function ( e , status ) {
763- finish ( status ) ;
808+ else {
809+ complete ( ) ;
810+ }
811+ }
812+ function runLinter ( ) {
813+ if ( ! lintFlag ) {
814+ return ;
815+ }
816+ var lint = jake . Task [ 'lint' ] ;
817+ lint . addListener ( 'complete' , function ( ) {
818+ complete ( ) ;
764819 } ) ;
765- } ) ;
820+ lint . invoke ( ) ;
821+ }
766822}
767823
768824var testTimeout = 20000 ;
769825desc ( "Runs all the tests in parallel using the built run.js file. Optional arguments are: t[ests]=category1|category2|... d[ebug]=true." ) ;
770826task ( "runtests-parallel" , [ "build-rules" , "tests" , builtLocalDirectory ] , function ( ) {
771- runConsoleTests ( 'min' , [ 'compiler' , 'conformance' , 'Projects' , 'fourslash' ] ) ;
827+ runConsoleTests ( 'min' , /*runInParallel*/ true ) ;
772828} , { async : true } ) ;
773829
774830desc ( "Runs the tests using the built run.js file. Optional arguments are: t[ests]=regex r[eporter]=[list|spec|json|<more>] d[ebug]=true color[s]=false lint=true." ) ;
775831task ( "runtests" , [ "build-rules" , "tests" , builtLocalDirectory ] , function ( ) {
776- runConsoleTests ( 'mocha-fivemat-progress-reporter' , [ ] ) ;
832+ runConsoleTests ( 'mocha-fivemat-progress-reporter' , /*runInParallel*/ false ) ;
777833} , { async : true } ) ;
778834
779835desc ( "Generates code coverage data via instanbul" ) ;
@@ -790,7 +846,7 @@ compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile
790846
791847desc ( "Runs browserify on run.js to produce a file suitable for running tests in the browser" ) ;
792848task ( "browserify" , [ "tests" , builtLocalDirectory , nodeServerOutFile ] , function ( ) {
793- var cmd = 'browserify built/local/run.js -o built/local/bundle.js' ;
849+ var cmd = 'browserify built/local/run.js -d - o built/local/bundle.js' ;
794850 exec ( cmd ) ;
795851} , { async : true } ) ;
796852
@@ -807,11 +863,11 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory, servicesFi
807863 fs . unlinkSync ( testConfigFile ) ;
808864 }
809865 if ( tests || light ) {
810- writeTestConfigFile ( tests , light , testConfigFile ) ;
866+ writeTestConfigFile ( tests , light ) ;
811867 }
812868
813869 tests = tests ? tests : '' ;
814- var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + tests ;
870+ var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + JSON . stringify ( tests ) ;
815871 console . log ( cmd ) ;
816872 exec ( cmd ) ;
817873} , { async : true } ) ;
0 commit comments