Cypress Mochawesome 报告显示文件两次

huangapple go评论68阅读模式
英文:

Cypress Mochawesome report showing file twice

问题

我正在运行 Cypress 12.13.0,搭配 mochawesome-report-generator 6.2.0、mochawesome-merge 4.3.0 和 mochawesome 7.1.3,尽管我在几个 Cypress 版本上都遇到了这个问题。

我正在使用 Bamboo 运行一个 PowerShell 脚本来运行所有文件并生成报告。脚本如下:

npx cypress run --spec 'cypress/e2e/features/**/*'

npx mochawesome-merge cypress/results/json/**/*.json -o combined-mochawesome.json

npx marge combined-mochawesome.json

根据报告,似乎 Cypress 会重新运行整个文件,该文件包含多个测试。有人知道为什么会这样吗?Cypress 配置文件中没有设置重试。

Cypress Mochawesome 报告显示文件两次

Bamboo 的日志中并未显示额外的运行,只显示了一次文件的运行。

Cypress Mochawesome 报告显示文件两次

英文:

I'm running Cypress 12.13.0 with mochawesome-report-generator 6.2.0, mochawesome-merge 4.3.0 and mochawesome 7.1.3, although I've had this problem for a few versions of Cypress.

I'm using bamboo to run a powershell script to run all of the files and generate the reports. It looks like:

npx cypress run --spec 'cypress/e2e/features/**/*'

npx mochawesome-merge cypress/results/json/**.json -o combined-mochawesome.json

npx marge combined-mochawesome.json

It appears cypress is re running an entire file, which contains multiple tests, according to the report at the end. Anybody know why that is? The cypress config file doesn't have retries set.

Cypress Mochawesome 报告显示文件两次

The log from bamboo doesn't show an additional run, it only shows 1 run of the file.
Cypress Mochawesome 报告显示文件两次

答案1

得分: 3

以下是您要翻译的内容:

"It looks like a report from a prior run is being picked up (only the last spec is repeated).

To be sure, add a 'trash-assets' hook before the run

const { defineConfig } = require('cypress')
const fs = require("fs");
const path = require("path");

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on('before:run', (details) => {
        const resultsPath = path.resolve(__dirname, 'cypress/results')
        const files = fs.readdirSync(resultsPath)
        for (const file of files) {
          fs.unlinkSync(path.resolve(resultsPath, file))
        }
      })
    },
  },
  experimentalInteractiveRunEvents: true,   // for open mode
})
```"

<details>
<summary>英文:</summary>

It looks like a report from a prior run is being picked up (only the last spec is repeated).

To be sure, add a &quot;trash-assets&quot; hook before the run

```js
const { defineConfig } = require(&#39;cypress&#39;)
const fs = require(&quot;fs&quot;);
const path = require(&quot;path&quot;);

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on(&#39;before:run&#39;, (details) =&gt; {
        const resultsPath = path.resolve(__dirname, &#39;cypress/results&#39;)
        const files = fs.readdirSync(resultsPath)
        for (const file of files) {
          fs.unlinkSync(path.reaolve(resultsPath, file)
        }
      })
    },
  },
  experimentalInteractiveRunEvents: true,   // for open mode
})

答案2

得分: 0

原来我们的代码库中有一个包含 JSON 文件的结果文件夹。这是意外造成的。删除了该文件和文件夹后,问题解决了,现在一切都正常工作。

英文:

Turns out that a results folder with a json file checked into our repository. This was done by accident. Removing the file and folder this problem has gone away and everything works as expected now.

huangapple
  • 本文由 发表于 2023年5月30日 03:21:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76359888.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定