【问题标题】:How to pass Babel7 config file path to mocha and gulp-mocha?如何将 Babel7 配置文件路径传递给 mocha 和 gulp-mocha?
【发布时间】:2019-02-13 11:35:04
【问题描述】:

在 Babel7 中,我们有 babel.config.js 文件。正如我在互联网上看到的那样,我们可以通过 configFileconfig-file 参数传递此文件的路径。但是,我无法让 mocha 和 gulp-mocha 读取 babel.config.js

这就是我运行摩卡咖啡的方式:

./node_modules/.bin/mocha ./foo.spec.js --compilers js:@babel/register

这就是我运行 gulpMocha 的方式

pipe(gulpMocha({
        reporter: 'spec',
        require: [
            '@babel/preset-env',
        ]
}))

如何将 Babel7 配置文件路径传递给 mocha 和 gulp-mocha?

如果两者都不可能,那么,至少一个。

【问题讨论】:

  • 该命令有哪些错误?

标签: javascript node.js gulp mocha.js babeljs


【解决方案1】:

建议解决方案here。 例如,如果项目结构是这样的:

Project
|-module1
|-module2
|-babel.config.js

我们想测试module1。我们在Project/module1 中创建register.js 文件,内容如下:

require("@babel/register")({
  rootMode: "upward"
});

Project/module1 之后,我们以这种方式运行 mocha:mocha --require register.jsbabel.config.js 将被 babel 找到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-25
    • 2016-04-25
    • 1970-01-01
    • 2013-12-01
    • 2013-09-08
    • 2019-09-02
    • 1970-01-01
    相关资源
    最近更新 更多