剧作家:如何从电子渲染过程中获得覆盖

发布于 2025-01-20 14:43:46 字数 761 浏览 5 评论 0原文

我正在重写电子应用程序的测试,使用“@playwright/test”测试运行器,用基于剧作家的测试替换基于 Spectron/mocha 的测试。

剧作家测试正在工作,但我在从电子渲染过程中获取任何覆盖数据时遇到问题。

在 Spectron 情况下,我必须在“卸载”事件上保存渲染过程中的覆盖数据(并且我得到了所有内容),但在剧作家环境中完成类似的操作时遇到问题。

似乎剧作家 startJSCoverage()/stopJSCoverage() API 可能相关,但虽然收集了一些数据,但它似乎来自主进程。

已尝试设置 NODE_V8_COVERAGE=.nyc_output,并且似乎不会影响渲染过程。

从电子渲染过程中收集覆盖率数据的推荐方法是什么?

下面是挽救报道失败的尝试的片段。还使用了一个匹配的await window.coverage.startJSCoverage()。

  const coverage = await window.coverage.stopJSCoverage();
  for (const entry of coverage) {
    let name = `.nyc_output/cl-${v4()}.json`
    console.log('electron.spec', name)
    console.dir(entry.functions)
    fs.writeFileSync(name, JSON.stringify(entry.functions));
  }

I am rewriting tests for an electron application, replacing spectron/mocha based tests with playwright based tests, using the '@playwright/test' test runner.

The playwright tests are working, but I have problems with getting any coverage data from the electron render process.

In the spectron case I had to save coverage data from render process on the 'unload' event (and I got everything), but I have problems getting something similar done in the playwright environment.

It seems that playwright startJSCoverage()/stopJSCoverage() API might be relevant, but while some data is collected, it appears to be from main process.

Setting NODE_V8_COVERAGE=.nyc_output has been tried, and doesn't appear to affect render process.

What is the recommended way to collect coverage data from electron render process?

Below is a snip of a failing attempt to save coverage. There is a matching await window.coverage.startJSCoverage() in use as well.

  const coverage = await window.coverage.stopJSCoverage();
  for (const entry of coverage) {
    let name = `.nyc_output/cl-${v4()}.json`
    console.log('electron.spec', name)
    console.dir(entry.functions)
    fs.writeFileSync(name, JSON.stringify(entry.functions));
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文