[英]Using wildcard to run multiple scripts for npm run test
I my package.json I have 我我的package.json有
"scripts": {
"test": "node tests/*-test.js"
}
And I have a-test.js
and b-test.js
in the tests
folder, which I can verify by running ls tests/*-test.js
. 我在
tests
文件夹中有a-test.js
和b-test.js
,可以通过运行ls tests/*-test.js
。
However, npm run test
is only executing a-test.js
. 但是,
npm run test
仅执行a-test.js
。 How can I execute all *-test.js
scripts? 如何执行所有
*-test.js
脚本? Explicitly listing them is not an option, since I will have more than 2 to run in the future. 明确列出它们不是一个选择,因为将来我将运行两个以上的函数。
You could use a task manager such as grunt
or gulp
, or a simple script that execute those scripts: 您可以使用任务管理器(例如
grunt
或gulp
)或执行这些脚本的简单脚本:
test.js: test.js:
require('./test/a-test.js')
require('./test/b-test.js')
package.json package.json
"scripts": {
"test": "node test.js"
}
You could also use the include-all module for automating these for you https://www.npmjs.com/package/include-all 您还可以使用包含所有模块为您自动执行这些操作https://www.npmjs.com/package/include-all
Example using includeAll: 使用includeAll的示例:
const path = require('path');
const includeAll = require('include-all');
const controller = includeAll({
dirname: path.join(__dirname, 'test'),
filter: /(.+test)\.js$/,
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.