2

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.

inf3rno
  • 24,976
  • 11
  • 115
  • 197
  • Can you add `global: true` inside the babel config? – Lim H. Nov 02 '15 at 22:25
  • @LimH. `events.js:141 throw er; // Unhandled 'error' event ^ ReferenceError: [BABEL] D:\creation\software developer\projects\javascript-project-template\index.js: Unknown option: base.global at Logger.error (D:\creation\software developer\projects\javascript-project-template\node_modules\gulp-babel\node_modules\babel-core\lib\transformation\file\logger.js:43:11) ... at doWrite (D:\creation\software developer\projects\javascript-project-template\node_modules\gulp-babel\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:333:12) ` – inf3rno Nov 02 '15 at 22:28
  • @LimH. Do you need the full message? I can add an edit... – inf3rno Nov 02 '15 at 22:32
  • Sorry I'm out of guess! I suppose the problem doesn't lie with the plugins but your code/node_modules. But that's as far as my guess goes – Lim H. Nov 02 '15 at 22:33
  • @LimH. My source codes are okay, they are working with karma. Maybe the install went wrong, I got some error messages, but it is hard to know by npm when it has real errors, because by installing optional dependencies you got almost the same red lines, so you tend to ignore error messages. Do you think a gulp-babel reinstall would work? – inf3rno Nov 02 '15 at 22:36
  • @LimH. I have the same after reinstall. I'll check an older version, maybe the new 6.x is buggy. – inf3rno Nov 02 '15 at 22:45
  • you may find this interesting https://babeljs.io/blog/2015/10/29/6.0.0/ – Lim H. Nov 02 '15 at 22:47
  • @LimH. I tried with babel 5.x without presets and plugins. (There are no 5.x version of them). I got the same error message. I guess it does not do the transformation runtime, so the jasmine got the es6 files instead of the es5 files. – inf3rno Nov 02 '15 at 22:56
  • @LimH. Here is the working version with karma and babel 5x: https://github.com/inf3rno/javascript-project-template/blob/babel/karma.conf.js (I am trying to pipe it to jasmine currently, otherwise I cannot test nodejs with source maps as far as I can tell, because the jasmine reporters do not always handle source maps very well.) – inf3rno Nov 02 '15 at 22:59

1 Answers1

3

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
        }))
};
jordiburgos
  • 5,964
  • 4
  • 46
  • 80
inf3rno
  • 24,976
  • 11
  • 115
  • 197