9

如何覆盖默认输出目录和文件名jest-junit

我想在使用 Jest 时自定义输出的输出配置,但它仍然在默认位置结束,即./junit.xml在项目根文件夹中。


我的配置

package.json中:

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

jest.config.js 中

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

预期结果:

  • 包含测试结果的文件./test_reports/jest-junit.xml

实际结果:

  • 默认为测试结果的文件./junit.xml
4

1 回答 1

7

解决方案

更改package.json脚本

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

只是

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

解释

问题是已经为文件和package.json 中脚本的jest.config.jscli 参数提供了记者配置。testCLI 选项具有更高的优先级且不提供outputDirectoryand outputName,测试结果将恢复为默认值junit.xml

于 2019-12-18T13:49:23.137 回答