Skip to content

Commit 705d3aa

Browse files
committed
build(gulp): fix concurrency and caching issues in test.unit.js and test.unit.dart tasks
previously there was a chance of race conditions that could sporadically fail the build. additionally runing a task via gulp.start or runSequence always reruns its dependencies, which meant that we were blowing away the build.tools build and rebuilding everything from scratch even during the interactive/watch mode. This meant that the build pipeline cache was destroyed on every change and we never got the benefit of incremental compilation
1 parent 1d00784 commit 705d3aa

File tree

1 file changed

+58
-21
lines changed

1 file changed

+58
-21
lines changed

gulpfile.js

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,16 @@ gulp.task('build/clean.docs', clean(gulp, gulpPlugins, {
102102
// ------------
103103
// transpile
104104

105-
gulp.task('build/tree.dart', ['build.tools'], function() {
105+
gulp.task('build/tree.dart', ['build/clean.dart', 'build.tools'], function(done) {
106+
runSequence('!build/tree.dart', done);
107+
});
108+
109+
110+
gulp.task('!build/tree.dart', function() {
106111
return angularBuilder.rebuildDartTree();
107112
});
108113

114+
109115
// ------------
110116
// pubspec
111117

@@ -322,41 +328,68 @@ function getBrowsersFromCLI() {
322328
return [args.browsers?args.browsers:'DartiumWithWebPlatform']
323329
}
324330

325-
gulp.task('test.unit.js', ['build/clean.js', 'broccoli.js.dev'], function (neverDone) {
326331

327-
function buildAndTest() {
332+
gulp.task('test.unit.js', ['build.js.dev'], function (neverDone) {
333+
334+
runSequence(
335+
'!test.unit.js/karma-server',
336+
'!test.unit.js/karma-run',
337+
'check-format'
338+
);
339+
340+
gulp.watch('modules/**', function() {
328341
runSequence(
329-
'broccoli.js.dev',
330-
'test.unit.js/karma-run'
342+
'!broccoli.js.dev',
343+
'!test.unit.js/karma-run',
344+
'check-format'
331345
);
332-
}
346+
});
347+
});
333348

334-
karma.server.start({configFile: __dirname + '/karma-js.conf.js'});
335349

336-
gulp.watch('modules/**', buildAndTest);
350+
gulp.task('!test.unit.js/karma-server', function() {
351+
karma.server.start({configFile: __dirname + '/karma-js.conf.js'});
337352
});
338353

339-
gulp.task('test.unit.js/karma-run', function (done) {
340-
karma.runner.run({configFile: __dirname + '/karma-js.conf.js'}, done);
354+
355+
gulp.task('!test.unit.js/karma-run', function(done) {
356+
karma.runner.run({configFile: __dirname + '/karma-js.conf.js'}, function(exitCode) {
357+
// ignore exitCode, we don't want to fail the build in the interactive (non-ci) mode
358+
// karma will print all test failures
359+
done();
360+
});
341361
});
342362

363+
343364
gulp.task('test.unit.dart', ['build/tree.dart'], function (done) {
344-
function buildAndTest() {
365+
366+
runSequence(
367+
'!test.unit.dart/karma-server',
368+
'!test.unit.dart/karma-run'
369+
);
370+
371+
gulp.watch('modules/angular2/**', function() {
345372
runSequence(
346-
'build/tree.dart',
347-
'test.unit.dart/karma-run'
373+
'!build/tree.dart',
374+
'!test.unit.dart/karma-run'
348375
);
349-
}
350-
351-
karma.server.start({configFile: __dirname + '/karma-dart.conf.js'});
376+
});
377+
});
352378

353-
gulp.watch('modules/angular2/**', buildAndTest);
379+
gulp.task('!test.unit.dart/karma-run', function (done) {
380+
karma.runner.run({configFile: __dirname + '/karma-dart.conf.js'}, function(exitCode) {
381+
// ignore exitCode, we don't want to fail the build in the interactive (non-ci) mode
382+
// karma will print all test failures
383+
done();
384+
});
354385
});
355386

356-
gulp.task('test.unit.dart/karma-run', function (done) {
357-
karma.runner.run({configFile: __dirname + '/karma-dart.conf.js'}, done);
387+
388+
gulp.task('!test.unit.dart/karma-server', function() {
389+
karma.server.start({configFile: __dirname + '/karma-dart.conf.js'});
358390
});
359391

392+
360393
gulp.task('test.unit.js/ci', function (done) {
361394
karma.server.start({configFile: __dirname + '/karma-js.conf.js',
362395
singleRun: true, reporters: ['dots'], browsers: getBrowsersFromCLI()}, done);
@@ -538,12 +571,16 @@ gulp.task('!build.tools', function() {
538571
return mergedStream;
539572
});
540573

541-
gulp.task('broccoli.js.dev', ['build.tools'], function() {
574+
gulp.task('broccoli.js.dev', ['build.tools'], function(done) {
575+
runSequence('!broccoli.js.dev', done);
576+
});
577+
578+
gulp.task('!broccoli.js.dev', function() {
542579
return angularBuilder.rebuildBrowserDevTree();
543580
});
544581

545582

546-
gulp.task('build.js.dev', function(done) {
583+
gulp.task('build.js.dev', ['build/clean.js'], function(done) {
547584
runSequence(
548585
'broccoli.js.dev',
549586
'build/checkCircularDependencies',

0 commit comments

Comments
 (0)