我有这个(在gulpfile.js中):
var gulp = require("gulp");
var mocha = require("gulp-mocha");
gulp.task("test", function() {
gulp
.src(["./**/*_test.js", "!./node_modules/**/*.js"]);
});而且起作用了。
我希望从mocha命令中复制相同的行为,不包括"node_modules“文件夹,运行npm测试(在package.json中):
"scripts": {
"test": "mocha **\\*_test.js !./node_modules/**/*.js*",
}但不起作用。
我在用Windows。
有什么建议吗?
发布于 2016-01-11 23:33:21
正如@thebearingedge的评论中所建议的那样,最后,将所有源文件(以及相关的测试文件)放入一个新的"src“dir中。
通过这种方式,我可以使用默认排除"node_modules“文件夹的路径定义测试的根。
.
├── src
├── fileA.js
├── fileA_test.js
├── fileB.js
├── fileB_test.js
├── node_modules
├── ...我必须更新package.json、gulpfile.js和一些作为实用工具使用的批处理文件中的路径。
gulpfile.js的变化
.src(["./src/**/*_test.js"]);在package.json中
"test": "mocha src\\**\\*_test.js",简单的改变就行了。
发布于 2017-09-05 15:44:42
我能够在mocha的参数中使用全局模式来解决这个问题。和你一样,我不想把所有的测试都放在一个tests文件夹下。我希望它们与它们测试的类位于同一个目录中。我的文件结构如下:
project
|- lib
|- class1.js
|- class1.test.js
|- node_modules
|- lots of stuff...在project文件夹中运行此操作对我有效:
mocha './{,!(node_modules)/**}/*.test.js'与树中的任何*.test.js文件相匹配,那么它的路径就不会根植于./node_modules/。
这是一个用于测试glob模式的在线工具,我发现它很有用。
发布于 2018-12-19 01:58:39
您可以通过传递opts来排除mocha中的文件。
mocha -h|grep -i exclude
--exclude <file> a file or glob pattern to ignore (default: )
mocha --exclude **/*-.jest.js此外,您还可以创建一个test/mocha.opts文件并在那里添加它。
# test/mocha.opts
--exclude **/*-test.jest.js
--require ./test/setup.js如果您想要排除特定的文件类型,您可以这样做
// test/setup.js
require.extensions['.graphql'] = function() {
return null
}当使用模块加载程序(如webpack )处理扩展时,这是非常有用的,因为mocha不理解这些扩展。
https://stackoverflow.com/questions/34301448
复制相似问题