Run mocha excluding paths

2020-05-25 06:18发布

I have this (in gulpfile.js):

var gulp = require("gulp");
var mocha = require("gulp-mocha");
gulp.task("test", function() {
    gulp
        .src(["./**/*_test.js", "!./node_modules/**/*.js"]);
});

and it works.

I want to replicate the same behavior, excluding "node_modules" folder, from mocha command, running npm test (in package.json):

"scripts": {
    "test": "mocha **\\*_test.js !./node_modules/**/*.js*",
}

and it doesn't work.

I'm using Windows.

Any suggestion?

标签: npm mocha
7条回答
别忘想泡老子
2楼-- · 2020-05-25 06:58

I'm not a guru on mocha or ant-style pattern but maybe it isn't possible escluding specific path in the mocha command line.

You can put all your test files under a test folder, and set your package.json like this:

"scripts": {
    "test": "mocha ./test/**/*_test.js"
}

You can also provide more than one starting folder:

"scripts": {
    "test": "mocha ./test/**/*_test.js ./another_test_folder/**/*_test.js"
}
查看更多
登录 后发表回答