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

How to pass Babel7 config file path to mocha and gulp-mocha?

在 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?

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

建议了解决方案 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 找到。