【问题标题】:Testing with gulp + babel + jasmine on nodejs在 nodejs 上使用 gulp + babel + jasmine 进行测试
【发布时间】:2015-11-02 22:23:54
【问题描述】:

我正在尝试使用 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 关键字,因此代码似乎中断了。我不确定如何解决这个问题。

【问题讨论】:

  • 你可以在 babel 配置中添加global: true 吗?
  • @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)
  • @LimH。您需要完整的消息吗?我可以添加编辑...
  • 对不起,我猜错了!我想问题不在于插件,而是你的代码/node_modules。但这只是我的猜测
  • @LimH。我的源代码还可以,它们正在使用 karma。也许安装出错了,我收到了一些错误消息,但是 npm 很难知道它什么时候有真正的错误,因为通过安装可选的依赖项,你得到几乎相同的红线,所以你倾向于忽略错误消息。你认为重新安装 gulp-babel 会起作用吗?

标签: jasmine gulp babeljs gulp-jasmine


【解决方案1】:

根据 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
        }))
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 1970-01-01
    • 2020-07-06
    相关资源
    最近更新 更多