javascript - 覆盖 jest-junit 默认输出位置?

标签 javascript jestjs xunit jest-junit

如何覆盖默认输出目录和文件名 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

最佳答案

解决方案

更改 package.json 脚本

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

只是

"scripts": {
  "test": "jest --ci"
},
<小时/>

说明

问题是记者配置已提供给 jest.config.js 文件以及 package.json 中 test 脚本的 cli 参数。 CLI选项具有更高的优先级,并且不提供outputDirectoryoutputName,测试结果将恢复为默认的junit.xml

关于javascript - 覆盖 jest-junit 默认输出位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59372493/

相关文章:

unit-testing - 如何模拟对 logger.warn 的调用?

jenkins - 如何让 xunit 在失败时停止 Jenkins 管道?

javascript - Object.assign() 用于替换 json 的对象

javascript - dygraph 仅显示上个月的数据

javascript - 匹配多个字母的准确出现次数

javascript - 如何使用 Jest/Enzyme 测试 React 中的 keydown 事件?

javascript - 清除 Javascript 中的 Var 或回调

typescript - jest typescript - 模拟日期构造函数

c# - 如何在单元测试期间跳过 Fluent 验证静态函数?

c# - xUnit 测试异步事件处理程序