简体   繁体   中英

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

In Babel7 we have babel.config.js file. The path to this file we can pass via configFile or config-file argument, as I see in internet. However, I couldn't make mocha and gulp-mocha read babel.config.js .

This the way I run mocha:

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

This is the way I run gulpMocha

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

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

If it is not possible for both of them, then, at least for one.

The solution was suggested here . For example, if project structure is like this:

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

And we want to test module1 . We create register.js file in Project/module1 with the following content:

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

After that in Project/module1 we run mocha this way: mocha --require register.js and babel.config.js will be found by babel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM