Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override jest-junit default output location?

How can I override the default output directory and file name jest-junit?

I would like to customise the output configuration of output when using Jest, but it still ends up in the default location, i.e. ./junit.xml in the project root folder.


My configuration

In package.json:

  "scripts": {
    "test": "jest --ci --reporters=default --reporters=jest-junit"
  },
  "devDependencies": {
    "jest": "^24.9.0",
    "jest-junit": "^10.0.0",
  }

In jest.config.js

module.exports = {
  testMatch: [
    '**/*.spec.js',
  ],
  reporters: [
    'default',
    [ 'jest-junit', {
      outputDirectory: 'test_reports',
      outputName: 'jest-junit.xml',
    } ]
  ]
};

Expected result:

  • A file with the test result at ./test_reports/jest-junit.xml

Actual result:

  • A file with the test result at the default ./junit.xml
like image 520
matsev Avatar asked Dec 17 '19 10:12

matsev


People also ask

Where are jest test results stored?

A report file test-report. xml is generated in the project root directory.

What is preset in jest?

preset [string] Default: undefined. A preset that is used as a base for Jest's configuration. A preset should point to an npm module that exports a jest-preset. json module on its top level.


1 Answers

Solution

change package.json script from

"scripts": {
  "test": "jest --ci --reporters=default --reporters=jest-junit"
},

to just

"scripts": {
  "test": "jest --ci"
},

Explanation

The problem is that reporters configuration have been provided to both the jest.config.js file as well as cli arguments to the test script in package.json. The CLI options has higher precedence and does not provide the outputDirectory and outputName, the test result will revert to the default junit.xml.

like image 163
matsev Avatar answered Sep 28 '22 12:09

matsev