使用通配符运行多个脚本进行NPM运行测试



i我的软件包。

"scripts": {
    "test": "node tests/*-test.js"
}

我在tests文件夹中有a-test.jsb-test.js,我可以通过运行ls tests/*-test.js进行验证。

但是,npm run test仅执行a-test.js。如何执行所有*-test.js脚本?明确列出它们不是一个选项,因为我将来将有2个以上的运行。

您可以使用诸如gruntgulp之类的任务管理器,或执行这些脚本的简单脚本:

test.js:

require('./test/a-test.js')
require('./test/b-test.js')

package.json

"scripts": {
   "test": "node test.js"
}

您也可以使用Incluble-All模块为您自动化这些模块https://www.npmjs.com/package/package/include-all-all-all-all

使用IncludeAll:

的示例
    const path = require('path');
    const includeAll = require('include-all');
    const controller = includeAll({
        dirname: path.join(__dirname, 'test'),
        filter: /(.+test).js$/,
    });

最新更新