Search code examples
jasminegulpbabeljsgulp-jasmine

Testing with gulp + babel + jasmine on nodejs


I am trying to test my code with gulp-jasmine and gulp-babel:

var gulp = require("gulp"),
    jasmine = require("gulp-jasmine"),
    babel = require("gulp-babel");

module.exports = function () {
    gulp.src(["index.js", "src/**/*.js", "spec/**/*[sS]pec.js"])
        .pipe(babel({
            "presets": ["es2015"],
            "plugins": ["transform-runtime"]
        }))
        .pipe(jasmine())
};

I got

events.js:141
      throw er; // Unhandled 'error' event
      ^
SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at D:\creation\software developer\projects\javascript-project-template\node_modules\jasmine\lib\jasmine.js:63:5
    at Array.forEach (native)
    at Jasmine.loadSpecs (D:\creation\software developer\projects\javascript-project-template\node_modules\jasmine\lib\jasmine.js:62:18)

Any idea about what I am missing? The code appears to break because there are still ES6 keywords used. I am not sure how to fix this.


Solution

  • According to sindresorhus the lib works only on file paths, so I cannot use streams: https://github.com/sindresorhus/gulp-jasmine/issues/60#event-452847672

    He suggested this approach instead:

    require('babel-core/register');
    
    var gulp = require("gulp"),
        jasmine = require("gulp-jasmine");
    
    module.exports = function () {
        gulp.src(["index.js", "src/**/*.js", "spec/**/*[sS]pec.js"])
            .pipe(jasmine({
                includeStackTrace: true
            }))
    };