I am trying to configure package.json to run test cases with similar names. In my case i have two different naming conventions,one for unit test and another for integration test. I need to run only unit test by giving a command which picks only unit test case files and same with the integration test files.
unit test case file naming convention
JavaScript
x
3
1
sample_unit.test.js
2
sample1_unit.test.js
3
integration test case file naming convention
JavaScript
1
3
1
sample_integration.test.js
2
sample1_integration.test.js
3
package.json(Attached only test configuration part)
JavaScript
1
9
1
"scripts": {
2
"test": "jest --config=./config/jest/jest_all.config.json --runInBand",
3
"unit-test": "jest --config=./config/jest/jest_unit.config.json",
4
"integration-test": "jest --config=./config/jest/jest_integration.config.json --runInBand",
5
"start": "node app.js",
6
"doc": "jsdoc -c config/jsdoc_config.json",
7
"sonar-scanner": "node_modules/sonar-scanner/bin/sonar-scanner"
8
}
9
Advertisement
Answer
I think this would work (as jest accepts a regex pattern):
JavaScript
1
9
1
"scripts": {
2
"test": "jest --config=./config/jest/jest_all.config.json --runInBand",
3
"unit-test": "jest --config=./config/jest/jest_unit.config.json '.+_unit.test.js'",
4
"integration-test": "jest --config=./config/jest/jest_integration.config.json --runInBand '.+_integration.test.js'",
5
"start": "node app.js",
6
"doc": "jsdoc -c config/jsdoc_config.json",
7
"sonar-scanner": "node_modules/sonar-scanner/bin/sonar-scanner"
8
}
9