admin管理员组文章数量:1429550
I am working on integration tests with jest where i have a 20 test files under a folder. I need to make sure three files in that folder need not to be executed while running the tests. i tried with testPathIgnorePatterns but it only works for folders and not for files. how to do that?
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,
},
],
],
};
I am working on integration tests with jest where i have a 20 test files under a folder. I need to make sure three files in that folder need not to be executed while running the tests. i tried with testPathIgnorePatterns but it only works for folders and not for files. how to do that?
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,
},
],
],
};
Share
Improve this question
edited Jan 13, 2021 at 9:09
Sabito
5,1459 gold badges38 silver badges65 bronze badges
asked Nov 27, 2020 at 8:38
muthumuthu
8032 gold badges12 silver badges28 bronze badges
6
- 1 Why not change the name of the file, or move it into a lm e.g. samples directory and ignore that? – jonrsharpe Commented Nov 27, 2020 at 8:39
- Nope, that is not possible. following some standards over the project. so moving to a folder is not remended @jonrsharpe – muthu Commented Nov 27, 2020 at 8:42
- What standards? And not remended !== not possible, is it really sensible to have a file that seems to be a test file but isn't (what is it)? It's clearly confusing the test discovery, but more importantly will probably confuse people. – jonrsharpe Commented Nov 27, 2020 at 8:46
-
1
@muthu how about renaming the files to
_integration.test.skip.js
– Teneff Commented Nov 27, 2020 at 11:54 - 2 That's an answer? You told me you couldn't rename the file. – jonrsharpe Commented Nov 27, 2020 at 15:07
2 Answers
Reset to default 5How about using --testPathIgnorePatterns
cli option?
yarn test --testPathIgnorePatterns=user.test.ts
If for multi files, can use below.
yarn test --testPathIgnorePatterns=filename1 filename2
You can use the collectCoverageFrom
parameter of Zest json like this,
collectCoverageFrom: ['path-to-file1','path-to-file2'],
Note: This option requires collectCoverage to be set to true or Jest to be invoked with --coverage.
Refer documentation
In documentation, they specified a pattern but it works file static file paths too.
本文标签: javascriptHow to skip a file from executing in jestStack Overflow
版权声明:本文标题:javascript - How to skip a file from executing in jest? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745501921a2661071.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论