@@ -26,7 +26,7 @@ const exec = require("./scripts/build/exec");
26
26
const browserify = require ( "./scripts/build/browserify" ) ;
27
27
const prepend = require ( "./scripts/build/prepend" ) ;
28
28
const { removeSourceMaps } = require ( "./scripts/build/sourcemaps" ) ;
29
- const { CancellationTokenSource, CancelError, delay, Semaphore } = require ( "prex" ) ;
29
+ const { CancellationTokenSource, CancelError, delay, Semaphore } = require ( "prex" ) ;
30
30
const { libraryTargets, generateLibs } = require ( "./scripts/build/lib" ) ;
31
31
const { runConsoleTests, cleanTestDirs, writeTestConfigFile, refBaseline, localBaseline, refRwcBaseline, localRwcBaseline } = require ( "./scripts/build/tests" ) ;
32
32
@@ -533,34 +533,39 @@ gulp.task(
533
533
[ "watch-diagnostics" , "watch-lib" ] . concat ( useCompilerDeps ) ,
534
534
( ) => project . watch ( tsserverProject , { typescript : useCompiler } ) ) ;
535
535
536
- gulp . task (
537
- "watch-local" ,
538
- /*help*/ false ,
539
- [ "watch-lib" , "watch-tsc" , "watch-services" , "watch-server" ] ) ;
540
-
541
536
gulp . task (
542
537
"watch-runner" ,
543
538
/*help*/ false ,
544
539
useCompilerDeps ,
545
540
( ) => project . watch ( testRunnerProject , { typescript : useCompiler } ) ) ;
546
541
547
- const watchPatterns = [
548
- runJs ,
549
- typescriptDts ,
550
- tsserverlibraryDts
551
- ] ;
542
+ gulp . task (
543
+ "watch-local" ,
544
+ "Watches for changes to projects in src/ (but does not execute tests)." ,
545
+ [ "watch-lib" , "watch-tsc" , "watch-services" , "watch-server" , "watch-runner" , "watch-lssl" ] ) ;
552
546
553
547
gulp . task (
554
548
"watch" ,
555
- "Watches for changes to the build inputs for built/local/run.js, then executes runtests-parallel ." ,
549
+ "Watches for changes to the build inputs for built/local/run.js, then runs tests ." ,
556
550
[ "build-rules" , "watch-runner" , "watch-services" , "watch-lssl" ] ,
557
551
( ) => {
558
- const runTestsSemaphore = new Semaphore ( 1 ) ;
559
- const fn = async ( ) => {
552
+ const sem = new Semaphore ( 1 ) ;
553
+
554
+ gulp . watch ( [ runJs , typescriptDts , tsserverlibraryDts ] , ( ) => {
555
+ runTests ( ) ;
556
+ } ) ;
557
+
558
+ // NOTE: gulp.watch is far too slow when watching tests/cases/**/* as it first enumerates *every* file
559
+ const testFilePattern = / ( \. t s | [ \\ / ] t s c o n f i g \. j s o n ) $ / ;
560
+ fs . watch ( "tests/cases" , { recursive : true } , ( _ , file ) => {
561
+ if ( testFilePattern . test ( file ) ) runTests ( ) ;
562
+ } ) ;
563
+
564
+ async function runTests ( ) {
560
565
try {
561
566
// Ensure only one instance of the test runner is running at any given time.
562
- if ( runTestsSemaphore . count > 0 ) {
563
- await runTestsSemaphore . wait ( ) ;
567
+ if ( sem . count > 0 ) {
568
+ await sem . wait ( ) ;
564
569
try {
565
570
// Wait for any concurrent recompilations to complete...
566
571
try {
@@ -576,20 +581,20 @@ gulp.task(
576
581
}
577
582
578
583
// cancel any pending or active test run if a new recompilation is triggered
579
- const runTestsSource = new CancellationTokenSource ( ) ;
584
+ const source = new CancellationTokenSource ( ) ;
580
585
project . waitForWorkToStart ( ) . then ( ( ) => {
581
- runTestsSource . cancel ( ) ;
586
+ source . cancel ( ) ;
582
587
} ) ;
583
588
584
589
if ( cmdLineOptions . tests || cmdLineOptions . failed ) {
585
- await runConsoleTests ( runJs , "mocha-fivemat-progress-reporter" , /*runInParallel*/ false , /*watchMode*/ true , runTestsSource . token ) ;
590
+ await runConsoleTests ( runJs , "mocha-fivemat-progress-reporter" , /*runInParallel*/ false , /*watchMode*/ true , source . token ) ;
586
591
}
587
592
else {
588
- await runConsoleTests ( runJs , "min" , /*runInParallel*/ true , /*watchMode*/ true , runTestsSource . token ) ;
593
+ await runConsoleTests ( runJs , "min" , /*runInParallel*/ true , /*watchMode*/ true , source . token ) ;
589
594
}
590
595
}
591
596
finally {
592
- runTestsSemaphore . release ( ) ;
597
+ sem . release ( ) ;
593
598
}
594
599
}
595
600
}
@@ -602,14 +607,6 @@ gulp.task(
602
607
}
603
608
}
604
609
} ;
605
-
606
- gulp . watch ( watchPatterns , ( e ) => fn ( ) ) ;
607
-
608
- // NOTE: gulp.watch is far too slow when watching tests/cases/**/* as it first enumerates *every* file
609
- const testFilePattern = / ( \. t s | [ \\ / ] t s c o n f i g \. j s o n ) $ / ;
610
- fs . watch ( "tests/cases" , { recursive : true } , ( _ , file ) => {
611
- if ( testFilePattern . test ( file ) ) fn ( ) ;
612
- } ) ;
613
610
} ) ;
614
611
615
612
gulp . task ( "clean-built" , /*help*/ false , [ `clean:${ diagnosticInformationMapTs } ` ] , ( ) => del ( [ "built" ] ) ) ;
0 commit comments