Skip to content
Advertisement

How to configure package.json to run test case file which ends with similar names?

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

sample_unit.test.js
sample1_unit.test.js

integration test case file naming convention

sample_integration.test.js
sample1_integration.test.js

package.json(Attached only test configuration part)

"scripts": {
    "test": "jest --config=./config/jest/jest_all.config.json --runInBand",
    "unit-test": "jest --config=./config/jest/jest_unit.config.json",
    "integration-test": "jest --config=./config/jest/jest_integration.config.json --runInBand",
    "start": "node app.js",
    "doc": "jsdoc -c config/jsdoc_config.json",
    "sonar-scanner": "node_modules/sonar-scanner/bin/sonar-scanner"
  }

Advertisement

Answer

I think this would work (as jest accepts a regex pattern):

"scripts": {
    "test": "jest --config=./config/jest/jest_all.config.json --runInBand",
    "unit-test": "jest --config=./config/jest/jest_unit.config.json '.+_unit.test.js'",
    "integration-test": "jest --config=./config/jest/jest_integration.config.json --runInBand '.+_integration.test.js'",
    "start": "node app.js",
    "doc": "jsdoc -c config/jsdoc_config.json",
    "sonar-scanner": "node_modules/sonar-scanner/bin/sonar-scanner"
  }
Advertisement