最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 4浏览 0评论

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

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

这就是我运行mocha的方式:

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

这是我运行Mocha的方式

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

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

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

回答如下:

解决方案被建议here。例如,如果项目结构如下:

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

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

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

之后在Project/module1,我们以这种方式运行摩卡:mocha --require register.jsbabel.config.js将由babel发现。

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

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

这就是我运行mocha的方式:

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

这是我运行Mocha的方式

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

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

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

回答如下:

解决方案被建议here。例如,如果项目结构如下:

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

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

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

之后在Project/module1,我们以这种方式运行摩卡:mocha --require register.jsbabel.config.js将由babel发现。

发布评论

评论列表 (0)

  1. 暂无评论