Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): improve test.unit.cjs task #998

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEVELOPER.md
Expand Up @@ -137,7 +137,7 @@ $(npm bin)/gulp clean

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

If you prefer running tests in "single-run" mode rather than watch mode use
Expand Down
31 changes: 29 additions & 2 deletions gulpfile.js
Expand Up @@ -3,6 +3,8 @@ var gulpPlugins = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var madge = require('madge');
var merge = require('merge');
var path = require('path');

var gulpTraceur = require('./tools/transpiler/gulp-traceur');

var clean = require('./tools/build/clean');
Expand All @@ -16,6 +18,7 @@ var jsserve = require('./tools/build/jsserve');
var pubserve = require('./tools/build/pubserve');
var rundartpackage = require('./tools/build/rundartpackage');
var copy = require('./tools/build/copy');
var file2moduleName = require('./tools/build/file2modulename');
var karma = require('karma').server;
var minimist = require('minimist');
var es5build = require('./tools/build/es5build');
Expand Down Expand Up @@ -606,8 +609,32 @@ gulp.task('test.unit.dart/ci', function (done) {
karma.start({configFile: __dirname + '/karma-dart.conf.js',
singleRun: true, reporters: ['dots'], browsers: getBrowsersFromCLI()}, done);
});
gulp.task('test.unit.cjs', function (done) {
return gulp.src(CONFIG.test.js.cjs).pipe(jasmine(/*{verbose: true, includeStackTrace: true}*/));
gulp.task('test.unit.cjs/ci', function () {
return gulp.src(CONFIG.test.js.cjs).pipe(jasmine({includeStackTrace: true, timeout: 1000}));
});
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(util.insertSrcFolder(gulpPlugins, CONFIG.srcFolderInsertion.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];
}
}
runSequence('test.unit.cjs/ci', function() {});
});

});

// ------------------
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/test_unit_js.sh
Expand Up @@ -10,4 +10,4 @@ cd $SCRIPT_DIR/../..
./node_modules/.bin/gulp test.transpiler.unittest
./node_modules/.bin/gulp docs/test
./node_modules/.bin/gulp test.unit.js/ci --browsers=$KARMA_BROWSERS
./node_modules/.bin/gulp test.unit.cjs
./node_modules/.bin/gulp test.unit.cjs/ci
10 changes: 6 additions & 4 deletions tools/transpiler/index.js
Expand Up @@ -23,9 +23,9 @@ exports.reloadSources = function() {
needsReload = true;
};

exports.compile = function compile(options, paths, source) {
exports.compile = function compile(options, paths, source, reloadTraceur) {
if (needsReload) {
reloadCompiler();
reloadCompiler(reloadTraceur);
needsReload = false;
}
var inputPath, outputPath, moduleName;
Expand Down Expand Up @@ -73,8 +73,10 @@ exports.init = function() {

// Transpile and evaluate the code in `src`.
// Use existing traceur to compile our sources.
function reloadCompiler() {
loadModule(TRACEUR_PATH, false);
function reloadCompiler(reloadTraceur) {
if (reloadTraceur) {
loadModule(TRACEUR_PATH, false);
}
glob.sync(__dirname + '/src/**/*.js').forEach(function(fileName) {
loadModule(fileName, true);
});
Expand Down
2 changes: 1 addition & 1 deletion tools/transpiler/karma-traceur-preprocessor.js
Expand Up @@ -25,7 +25,7 @@ function createJs2DartPreprocessor(logger, basePath, config, emitter) {
inputPath: file.originalPath,
outputPath: file.path,
moduleName: moduleName
}, content);
}, content, true);

var transpiledContent = result.js;
var sourceMap = result.sourceMap;
Expand Down