Skip to content

Commit 52bf0de

Browse files
marclavalmhevery
authored andcommitted
chore(test): improve test.unit.cjs task
Closes angular#998
1 parent 376bdf4 commit 52bf0de

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

DEVELOPER.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ $(npm bin)/gulp clean
137137

138138
1. `$(npm bin)/gulp test.unit.js`: JS tests in a browser; runs in **watch mode** (i.e. karma
139139
watches the test files for changes and re-runs tests when files are updated).
140-
2. `$(npm bin)/gulp test.unit.cjs`: JS tests in NodeJS (requires a build before)
140+
2. `$(npm bin)/gulp test.unit.cjs`: JS tests in NodeJS; runs in **watch mode**
141141
3. `$(npm bin)/gulp test.unit.dart`: Dart tests in Dartium; runs in **watch mode**.
142142

143143
If you prefer running tests in "single-run" mode rather than watch mode use

gulpfile.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var gulpPlugins = require('gulp-load-plugins')();
33
var runSequence = require('run-sequence');
44
var madge = require('madge');
55
var merge = require('merge');
6+
var path = require('path');
7+
68
var gulpTraceur = require('./tools/transpiler/gulp-traceur');
79

810
var clean = require('./tools/build/clean');
@@ -16,6 +18,7 @@ var jsserve = require('./tools/build/jsserve');
1618
var pubserve = require('./tools/build/pubserve');
1719
var rundartpackage = require('./tools/build/rundartpackage');
1820
var copy = require('./tools/build/copy');
21+
var file2moduleName = require('./tools/build/file2modulename');
1922
var karma = require('karma').server;
2023
var minimist = require('minimist');
2124
var es5build = require('./tools/build/es5build');
@@ -606,8 +609,32 @@ gulp.task('test.unit.dart/ci', function (done) {
606609
karma.start({configFile: __dirname + '/karma-dart.conf.js',
607610
singleRun: true, reporters: ['dots'], browsers: getBrowsersFromCLI()}, done);
608611
});
609-
gulp.task('test.unit.cjs', function (done) {
610-
return gulp.src(CONFIG.test.js.cjs).pipe(jasmine(/*{verbose: true, includeStackTrace: true}*/));
612+
gulp.task('test.unit.cjs/ci', function () {
613+
return gulp.src(CONFIG.test.js.cjs).pipe(jasmine({includeStackTrace: true, timeout: 1000}));
614+
});
615+
gulp.task('test.unit.cjs', ['build.js.cjs'], function () {
616+
//Run tests once
617+
runSequence('test.unit.cjs/ci', function() {});
618+
//Watcher to transpile file changed
619+
gulp.watch(CONFIG.transpile.src.js.concat(['modules/**/*.cjs']), function(event) {
620+
var relPath = path.relative(__dirname, event.path).replace(/\\/g, "/");
621+
gulp.src(relPath)
622+
.pipe(gulpPlugins.rename({extname: '.'+ 'js'}))
623+
.pipe(util.insertSrcFolder(gulpPlugins, CONFIG.srcFolderInsertion.js))
624+
.pipe(gulpTraceur(CONFIG.transpile.options.js.cjs, file2moduleName))
625+
.pipe(transformCJSTests())
626+
.pipe(gulp.dest(CONFIG.dest.js.cjs + path.dirname(relPath.replace("modules", ""))));
627+
});
628+
//Watcher to run tests when dist/js/cjs/angular2 is updated by the first watcher (after clearing the node cache)
629+
gulp.watch(CONFIG.dest.js.cjs + '/angular2/**/*.js', function(event) {
630+
for (var id in require.cache) {
631+
if (id.replace(/\\/g, "/").indexOf(CONFIG.dest.js.cjs) > -1) {
632+
delete require.cache[id];
633+
}
634+
}
635+
runSequence('test.unit.cjs/ci', function() {});
636+
});
637+
611638
});
612639

613640
// ------------------

scripts/ci/test_unit_js.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ cd $SCRIPT_DIR/../..
1010
./node_modules/.bin/gulp test.transpiler.unittest
1111
./node_modules/.bin/gulp docs/test
1212
./node_modules/.bin/gulp test.unit.js/ci --browsers=$KARMA_BROWSERS
13-
./node_modules/.bin/gulp test.unit.cjs
13+
./node_modules/.bin/gulp test.unit.cjs/ci

tools/transpiler/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ exports.reloadSources = function() {
2323
needsReload = true;
2424
};
2525

26-
exports.compile = function compile(options, paths, source) {
26+
exports.compile = function compile(options, paths, source, reloadTraceur) {
2727
if (needsReload) {
28-
reloadCompiler();
28+
reloadCompiler(reloadTraceur);
2929
needsReload = false;
3030
}
3131
var inputPath, outputPath, moduleName;
@@ -73,8 +73,10 @@ exports.init = function() {
7373

7474
// Transpile and evaluate the code in `src`.
7575
// Use existing traceur to compile our sources.
76-
function reloadCompiler() {
77-
loadModule(TRACEUR_PATH, false);
76+
function reloadCompiler(reloadTraceur) {
77+
if (reloadTraceur) {
78+
loadModule(TRACEUR_PATH, false);
79+
}
7880
glob.sync(__dirname + '/src/**/*.js').forEach(function(fileName) {
7981
loadModule(fileName, true);
8082
});

tools/transpiler/karma-traceur-preprocessor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function createJs2DartPreprocessor(logger, basePath, config, emitter) {
2525
inputPath: file.originalPath,
2626
outputPath: file.path,
2727
moduleName: moduleName
28-
}, content);
28+
}, content, true);
2929

3030
var transpiledContent = result.js;
3131
var sourceMap = result.sourceMap;

0 commit comments

Comments
 (0)