Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove node-canvas and use SVG snapshot instead #5733

Merged
merged 27 commits into from
Nov 9, 2023
Merged

Conversation

xiaoiver
Copy link
Contributor

@xiaoiver xiaoiver commented Nov 3, 2023

虽然比 node-canvas 容易安装,Playwright 仍存在 CI 和本地截图的差异:
#5663

因此使用 @antv/g-svg 获取各环境一致的 SVG 字符串用作截图测试,其他渲染器的一致性应该由底层保证。
为了彻底移除 node-canvas:

  • 暂时注释掉 __tests__/unit/ssr。G2 服务端渲染的例子可以写在 stackblitz 上,官网链接也得改一下。
  • 提供一个 mock 的 Canvas2D context,用于度量文本。具体度量方法参考 plot 的字符宽度查找表
  • 对于 heatmap wordcloud 这种需要 canvas 的图表,可以在 CI 时安装 node-canvas,本地不安装并跳过测试

其他小改进:

  • 去除 jest 的 -i 参数让测试用例并行执行,目前 ci 时间约 15min 相较之前能缩短一半。如果使用 sharding 会更快
  • 上传不一致的 SVG 截图到 artifacts,便于下载到本地比对,无需 OSS

TODO:

  • G2 生成的部分 path 路径定义可以保留部分精度,否则 SVG 文件较大。在 G 里目前保留 6 位:
<g transform="matrix(1,0,0,1,83.040001,321.600006)"> // G 生成的矩阵,保留6位
  <path
    id="g-svg-83"
    fill="none"
    class="grid-line"
    stroke="rgba(29,33,41,1)"
    stroke-width="0.5"
    stroke-dasharray="3,4"
    d="M 0,0 L 540.9599997056346,0" // G2 / component 生成的路径,也可以只保留6位
    stroke-opacity="0.1"
  />
</g>

@xiaoiver xiaoiver force-pushed the test-jsdom branch 2 times, most recently from 948e49b to d8d0c42 Compare November 8, 2023 07:19
@xiaoiver xiaoiver self-assigned this Nov 8, 2023
@pearmini
Copy link
Member

pearmini commented Nov 9, 2023

这个 PR #5776 可能会解决某些图表坐标轴的问题

@pearmini
Copy link
Member

pearmini commented Nov 9, 2023

终于解决测试稳定性问题了!

@pearmini pearmini merged commit 6d6d1d5 into v5 Nov 9, 2023
3 checks passed
@pearmini pearmini deleted the test-jsdom branch November 9, 2023 07:13
@hustcc
Copy link
Member

hustcc commented Nov 9, 2023

ci 15min 完成,快多了~ 👍🏻👍🏻👍🏻

Exlau pushed a commit to Exlau/G2 that referenced this pull request Nov 10, 2023
* chore: remove node-canvas

* chore: update snapshots

* chore: wordcloud & heatmap test case should run on CI

* chore: upload snapshots

* chore: reset entity counter making snapshots stable

* chore: remove canvas dep on ci

* chore: add max error ratio

* chore: run static-tooltip test cases

* chore: skip upload cov on ci

* chore: run static test cases

* chore: hide axis first

* chore: run chart-auto-fit test case on ci

* chore: run api- test cases

* chore: run interaction test cases

* chore: run animation test cases

* chore: run all test cases

* chore: run all test cases on ci

* chore: skip 2 cases

* chore: run all test cases

* chore: use svg renderer in unit tests

* chore: upload diff html

* chore: update snapshots

* chore: remove oss upload script

* chore: enable axis

* chore: update snapshots

* chore: remove test.only

* chore: run skipped cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants