运行摩卡(不包含路径) [英] Run mocha excluding paths

查看:105
本文介绍了运行摩卡(不包含路径)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个(在gulpfile.js中):

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"]);
});

它有效.

我想通过运行 npm test (在package.json中)从mocha命令复制相同的行为,不包括"node_modules"文件夹:

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*",
}

它不起作用.

我正在使用Windows.

I'm using Windows.

有什么建议吗?

推荐答案

正如@thebearingedge的评论中所建议的,最后我将所有源文件(以及相关的测试文件)放入了一个新的"src"中. "dir .
这样,我可以为测试定义根目录,其路径默认情况下不包括"node_modules"文件夹.

As suggested in a comment by @thebearingedge, in the end I put ALL the source files (with the relative test files) in a new "src" dir.
In this way I can define the root for tests with a path that exclude by default the "node_modules" folder.

.
├── src  
    ├── fileA.js  
    ├── fileA_test.js  
    ├── fileB.js  
    ├── fileB_test.js  
├── node_modules
    ├── ...

我必须更新package.json,gulpfile.js和一些用作实用程序的批处理文件中的路径.

I had to update the path in the package.json, gulpfile.js and in some batch files that I use as utilities.

gulpfile.js 中的更改:

.src(["./src/**/*_test.js"]);

package.json 中的

"test": "mocha src\\**\\*_test.js",

简单的更改就可以了.

  • 我可以自由选择自己喜欢的命名约定.
  • 每个测试文件都保持相对JS文件的位置.

这篇关于运行摩卡(不包含路径)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆