gulp-mocha how to pass the compilers flag?

后端 未结 6 1103
[愿得一人]
[愿得一人] 2021-02-14 09:28

I\'m trying to use the gulp-mocha module but can\'t figure out a good way to pass over the compilers flag. Is there a way to include this in my gulp task? Maybe in a separate

6条回答
  •  执念已碎
    2021-02-14 10:29

    The top answer relies on using the require hook. This will only work in the current process, and not if you run Mocha tests in a separate process, as with gulp-spawn-mocha.

    This is how you pass compilers into the mocha module:

        return mocha({
            compilers: [
                'js:babel-core/register',
            ]
        });
    

    Mocha will loop through the elements of the compilers property and split on :. It will treat the string before it as the extensions to follow, and will inject everything after it into a require() statement.

提交回复
热议问题