Jestjs 当Jest.config更改时重新运行Jest
我正在使用jests.config.js文件:Jestjs 当Jest.config更改时重新运行Jest,jestjs,Jestjs,我正在使用jests.config.js文件: // jest.config.js module.exports = { verbose: true, setupFiles: ["./helpers/setup/environment.js"], testMatch: ["**/__tests__/v2/tests.cloud.js"], globals: { _: true, }, watchPathIgnorePatterns:
// jest.config.js
module.exports = {
verbose: true,
setupFiles: ["./helpers/setup/environment.js"],
testMatch: ["**/__tests__/v2/tests.cloud.js"],
globals: {
_: true,
},
watchPathIgnorePatterns: ["./src/dataset", "./logs"],
};
我用手表开玩笑:
jest --watch
为了独立开发每个测试,每次我继续编写下一个测试时,我都会在testMatch上更改测试文件。当配置文件更改时,手表是否有办法重新加载Jest配置本身?还有很多其他选项 CLI[TestPathPattern] 如果您运行
jest--help
,您将看到您可以通过TestPathPattern来匹配测试文件
$jest—帮助
用法:jest.js[--config=][TestPathPattern]
--仅更改,-o Jest将尝试仅运行与已更改(在当前存储库中)文件相关的测试
观察模式(p)
在
--watch
模式下,您可以按p
并输入regex来选择要运行的文件最后编写了一个简短的NodeJS脚本:
const fs = require("fs");
const { spawn } = require("child_process");
const filename = "../jest.config.js";
let jest;
const run = () => {
if (jest) {
jest.kill();
}
jest = spawn("jest", ["--watch"], { stdio: "inherit" });
};
run();
fs.watch(filename, run);
process.on("SIGINT", function() {
console.log("Caught interrupt signal");
process.exit();
});
@盖伊:我的答案并没有真正回答你的问题,但是
testMatch
并不是每次测试都要更改的。是的,我意识到这不是预期的用途,但当我一次编写一个测试时,当我转到下一个套件并使用“npm测试”时,我更容易每10分钟左右更改一次而不是浏览cli历史记录