chore(build): refactor test.unit.cjs to use the broccoli pipeline

This change solves several problems:
- the broccoli pipeline is used to compile the node/cjs tree upon any change to the modules/ directory
- jasmine tests run in a new process removing the need to clean up environment after each test
- since we transpile only those test files that are actually needed for node/cjs build, we transpile less and don't need to filter out tests
This commit is contained in:
Igor Minar
2015-04-13 23:56:07 -07:00
parent 427f0d021c
commit 725f909ff8
4 changed files with 57 additions and 20 deletions

View File

@ -1,5 +1,6 @@
var autoprefixer = require('gulp-autoprefixer');
var format = require('gulp-clang-format');
var fork = require('child_process').fork;
var gulp = require('gulp');
var gulpPlugins = require('gulp-load-plugins')();
var sass = require('gulp-sass');
@ -8,6 +9,7 @@ var runSequence = require('run-sequence');
var madge = require('madge');
var merge = require('merge');
var path = require('path');
var Q = require('q');
var gulpTraceur = require('./tools/transpiler/gulp-traceur');
var clean = require('./tools/build/clean');
@ -465,27 +467,38 @@ gulp.task('test.unit.cjs/ci', function () {
gulp.task('test.unit.cjs', ['build.js.cjs'], function () {
//Run tests once
runSequence('test.unit.cjs/ci', function() {});
});
//Watcher to transpile file changed
gulp.watch(CONFIG.transpile.src.js.concat(['modules/**/*.cjs']), function(event) {
var relPath = path.relative(__dirname, event.path).replace(/\\/g, "/");
gulp.src(relPath)
.pipe(gulpPlugins.rename({extname: '.'+ 'js'}))
.pipe(gulpTraceur(CONFIG.transpile.options.js.cjs, file2moduleName))
.pipe(transformCJSTests())
.pipe(gulp.dest(CONFIG.dest.js.cjs + path.dirname(relPath.replace("modules", ""))));
});
//Watcher to run tests when dist/js/cjs/angular2 is updated by the first watcher (after clearing the node cache)
gulp.watch(CONFIG.dest.js.cjs + '/angular2/**/*.js', function(event) {
for (var id in require.cache) {
if (id.replace(/\\/g, "/").indexOf(CONFIG.dest.js.cjs) > -1) {
delete require.cache[id];
}
}
global.assert = undefined; // https://github.com/angular/angular/issues/1340
runSequence('test.unit.cjs/ci', function() {});
function runNodeJasmineTests() {
var doneDeferred = Q.defer();
var jasmineProcess = fork('./tools/traceur-jasmine', ['dist/js/cjs/angular2/test/**/*_spec.js'], {
stdio: 'inherit'
});
jasmineProcess.on('close', function (code) {
doneDeferred.resolve();
});
return doneDeferred.promise;
}
gulp.task('test.unit.cjs/ci', runNodeJasmineTests);
gulp.task('test.unit.cjs', ['build.broccoli.tools'], function (done) {
//Run tests once
var nodeBroccoliBuilder = getBroccoli().forNodeTree();
nodeBroccoliBuilder.doBuild().then(function() {
gulp.start('build/linknodemodules.js.cjs');
return runNodeJasmineTests();
}).then(function() {
//Watcher to transpile file changed
gulp.watch('modules/**', function(event) {
console.log("fs changes detected", event);
nodeBroccoliBuilder.doBuild().then(runNodeJasmineTests);
});
});
});
// ------------------
@ -621,7 +634,7 @@ gulp.task('broccoli.js.cjs', ['build.broccoli.tools'], function() {
gulp.task('build.js.cjs', function(done) {
runSequence(
'broccoli.js.cjs',
['build/linknodemodules.js.cjs'],
'build/linknodemodules.js.cjs',
done
);
});