From 725f909ff82cbb30754603c0ee9e489fa8c4a336 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 13 Apr 2015 23:56:07 -0700 Subject: [PATCH] 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 --- gulpfile.js | 49 +++++++++++++++++++------------ package.json | 1 + tools/broccoli/trees/node_tree.ts | 9 +++++- tools/traceur-jasmine/index.js | 16 ++++++++++ 4 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 tools/traceur-jasmine/index.js diff --git a/gulpfile.js b/gulpfile.js index 3facf107d80ace..894eec0c49a338 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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", "")))); +function runNodeJasmineTests() { + var doneDeferred = Q.defer(); + var jasmineProcess = fork('./tools/traceur-jasmine', ['dist/js/cjs/angular2/test/**/*_spec.js'], { + stdio: 'inherit' }); - //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() {}); + + 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 ); }); diff --git a/package.json b/package.json index fb633d45481b6c..bc33c3c797b526 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "lodash": "^2.4.1", "madge": "^0.5.0", "merge": "^1.2.0", + "minijasminenode2": "^1.0.0", "minimatch": "^2.0.1", "minimist": "1.1.x", "parse5": "1.3.2", diff --git a/tools/broccoli/trees/node_tree.ts b/tools/broccoli/trees/node_tree.ts index b00bd8120eb28f..5d0c8039dabd47 100644 --- a/tools/broccoli/trees/node_tree.ts +++ b/tools/broccoli/trees/node_tree.ts @@ -19,7 +19,14 @@ module.exports = function makeNodeTree() { var modulesTree = new Funnel('modules', { include: ['angular2/**', 'benchpress/**', 'rtts_assert/**', '**/e2e_test/**'], - exclude: ['angular2/src/core/zone/vm_turn_zone.es6'] + exclude: [ + 'angular2/src/core/zone/vm_turn_zone.es6', + 'angular2/test/core/application_spec.js', + 'angular2/test/core/testability/**', + 'angular2/test/core/zone/**', + 'angular2/test/render/**', + 'angular2/test/forms/integration_spec.js' + ] }); var nodeTree = new TraceurCompiler(modulesTree, '.js', '.map', { diff --git a/tools/traceur-jasmine/index.js b/tools/traceur-jasmine/index.js new file mode 100644 index 00000000000000..385ec853b926d6 --- /dev/null +++ b/tools/traceur-jasmine/index.js @@ -0,0 +1,16 @@ +'use strict'; + +var glob = require('glob'); +var minijasminenode2 = require('minijasminenode2'); +var path = require('path'); +// Require traceur to exposes $traceurRuntime on global context so that CJS files can run +require('traceur/bin/traceur-runtime.js'); + +glob(process.argv[2], function (error, specFiles) { + minijasminenode2.executeSpecs({ + includeStackTrace: true, + defaultTimeoutInterval: 1000, + showColors: process.argv.indexOf('--no-color') === -1, + specs: specFiles + }); +});