Cha*_*kal 7 javascript testing jest
我在许多测试套件中,在许多测试文件中进行了许多测试
我需要隔离和调试单个测试
我正在调试通过node --inspect-brk ./node_modules/jest/bin/jest,所以其他涉及监视模式的解决方案太复杂了
我怎么能跳过所有测试,除了我需要调试的那个?
jest 分两步处理
通过使用testPathPattern (jest docs)命令行参数运行 jest来隔离您的测试文件
node --inspect-brk ./node_modules/jest/bin/jest --testPathPattern="integration.test"
Run Code Online (Sandbox Code Playgroud)
这里integration.test作为正则表达式提供以过滤正确的测试文件
隔离您的测试功能
有两种方法可以做到这一点
一种方法是使用testNamePattern (jest docs)命令行参数
node --inspect-brk ./node_modules/jest/bin/jest --testNamePattern="host events"
Run Code Online (Sandbox Code Playgroud)
这里host events作为正则表达式提供以过滤正确的测试套件名称
或者,您可以添加.only到您的测试功能:
以便 test("object works", async() => {/*...*/})
变成 test.only("object works", async() => {/*...*/})
我使用VSCode用于调试和launch.json添加到runTimeArgs一个testPathPattern为您的文件夹名称:
{
"version": "0.2.0",
"configurations": [{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/jest/bin/jest.js",
"--runInBand",
"--testPathPattern=<NameOfTheFolder-you-want-to-test-without-this-angle-brackets>"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
}]
}
Run Code Online (Sandbox Code Playgroud)