[英]How to skip a file from executing in jest?
我正在使用 jest 进行集成测试,其中一个文件夹下有 20 个测试文件。 我需要确保在运行测试时不需要执行该文件夹中的三个文件。 我尝试使用testPathIgnorePatterns但它仅适用于文件夹而不适用于文件。 怎么做?
jest.config.js
/**
* @file Jest Integration Test Configuration File
*/
module.exports = {
roots: ['../../tests'],
testRegex: '_*_integration.test.(js|ts|tsx)?$',
globals: {
'ts-jest': {
tsconfig: 'tsconfig.json',
},
},
moduleFileExtensions: ['ts', 'js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
testPathIgnorePatterns: ['tests/api/modules/m3/sample.test.ts'],
testEnvironment: 'node',
reporters: [
'default',
[
'../../node_modules/jest-html-reporter',
{
pageTitle: 'Integration Test Report',
outputPath: 'tests/reports/integration-test-report.html',
includeFailureMsg: true,
},
],
],
};
使用--testPathIgnorePatterns
cli 选项怎么样?
yarn test --testPathIgnorePatterns=user.test.ts
如果用于多个文件,可以在下面使用。
yarn test --testPathIgnorePatterns=filename1 filename2
您可以像这样使用 Zest json 的collectCoverageFrom
参数,
collectCoverageFrom: ['path-to-file1','path-to-file2'],
注意:此选项需要将 collectCoverage 设置为 true 或使用--coverage.
参考文档
在文档中,他们指定了一种模式,但它也适用于文件 static 文件路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.