最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Override jest-junit default output location? - Stack Overflow

programmeradmin3浏览0评论

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

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
Share Improve this question edited Dec 18, 2019 at 13:49 matsev asked Dec 17, 2019 at 10:43 matsevmatsev 33.8k17 gold badges125 silver badges168 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 15

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.

发布评论

评论列表(0)

  1. 暂无评论