我正在尝试用gulp-jasmine和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())
};
我得到了
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)
我对失踪的想法有所了解吗?由于仍然使用ES6关键字,代码似乎会中断。我不知道如何解决这个问题。
答案 0 :(得分:3)
根据sindresorhus,lib只能在文件路径上工作,所以我不能使用流:https://github.com/sindresorhus/gulp-jasmine/issues/60#event-452847672
他建议采用这种方法:
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
}))
};