Skip to content

Commit

Permalink
fix: test snapshots diff on arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Aug 5, 2022
1 parent 6d0df59 commit 21983c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
6 changes: 3 additions & 3 deletions __test__/draw.spec.ts
Expand Up @@ -949,7 +949,7 @@ test('JPEG toDataURL with quality', async (t) => {
const output = canvas.toDataURL('image/jpeg', 20)
const prefix = 'data:image/jpeg;base64,'
t.true(output.startsWith(prefix))
const imageBase64 = output.substr(prefix.length)
const imageBase64 = output.substring(prefix.length)
const pngBuffer = Buffer.from(imageBase64, 'base64')
t.deepEqual(pngBuffer, await canvas.encode('jpeg', 20))
})
Expand All @@ -961,7 +961,7 @@ test('WebP toDataURL with quality', async (t) => {
const output = canvas.toDataURL('image/webp', 100)
const prefix = 'data:image/webp;base64,'
t.true(output.startsWith(prefix))
const imageBase64 = output.substr(prefix.length)
const imageBase64 = output.substring(prefix.length)
const pngBuffer = Buffer.from(imageBase64, 'base64')
t.deepEqual(pngBuffer, await canvas.encode('webp', 100))
})
Expand All @@ -972,7 +972,7 @@ test('toDataURLAsync', async (t) => {
const output = await canvas.toDataURLAsync()
const prefix = 'data:image/png;base64,'
t.true(output.startsWith(prefix))
const imageBase64 = output.substr(prefix.length)
const imageBase64 = output.substring(prefix.length)
const pngBuffer = Buffer.from(imageBase64, 'base64')
t.deepEqual(pngBuffer, await canvas.encode('png'))
})
Expand Down
4 changes: 2 additions & 2 deletions __test__/filter.spec.ts
Expand Up @@ -97,10 +97,10 @@ test('filter-saturate', async (t) => {
})

test('filter-sepia', async (t) => {
const { ctx } = t.context
const { ctx, canvas } = t.context
ctx.filter = 'sepia(100%)'
ctx.drawImage(await createImage('filter-sepia.jpeg'), 0, 0)
await snapshotImage(t)
await snapshotImage(t, { ctx, canvas }, 'png', 0.05)
})

test('filter-combine-contrast-brightness', async (t) => {
Expand Down
19 changes: 16 additions & 3 deletions __test__/pathkit.spec.ts
Expand Up @@ -2,6 +2,13 @@ import test from 'ava'

import { FillType, Path2D, PathOp, StrokeCap, StrokeJoin } from '../index'

const AARCH64_NOT_MUSL = (function () {
// @ts-expect-error
const { header } = process.report?.getReport?.() ?? {}
const isGnuLinux = Boolean(header?.glibcVersionRuntime)
return process.arch === 'arm64' && ((process.platform === 'linux' && isGnuLinux) || process.platform === 'darwin')
})()

test('should be able to call toSVGString', (t) => {
const path = new Path2D()
path.rect(0, 0, 100, 100)
Expand Down Expand Up @@ -170,16 +177,22 @@ test('Convert stroke to path', (t) => {
)
path.stroke({ width: 10, miterLimit: 1 }).simplify().asWinding()

t.snapshot(path.toSVGString())
const expected = AARCH64_NOT_MUSL
? `M57.6458 39.75L37.2942 4.5Q34.6962 -2.38419e-06 29.5 -2.38419e-06Q24.3038 -2.89876e-06 21.7058 4.5L1.35417 39.75Q-1.2439 44.25 1.35418 48.75Q3.95226 53.25 9.14841 53.25L49.8516 53.25Q55.0478 53.25 57.6458 48.75Q60.2439 44.25 57.6458 39.75ZM29.5 11L48.1195 43.25L10.8805 43.25L29.5 11Z`
: `M57.6458 39.75L37.2942 4.5Q34.6962 -2.38419e-06 29.5 -2.38419e-06Q24.3038 -2.90573e-06 21.7058 4.5L1.35417 39.75Q-1.2439 44.25 1.35418 48.75Q3.95226 53.25 9.14841 53.25L49.8516 53.25Q55.0478 53.25 57.6458 48.75Q60.2439 44.25 57.6458 39.75ZM29.5 11L48.1195 43.25L10.8805 43.25L29.5 11Z`

t.is(path.toSVGString(), expected)
})

test('Convert stroke to path 2', (t) => {
const path = new Path2D('M4 23.5L22.5 5L41 23.5')
path.stroke({ width: 10, join: StrokeJoin.Round, miterLimit: 1 }).simplify()

const svg = `<svg width="45" height="28" viewBox="0 0 45 28"><path fill="pink" d="${path.toSVGString()}"></path></svg>`

t.snapshot(svg)
const expected = AARCH64_NOT_MUSL
? `<svg width="45" height="28" viewBox="0 0 45 28"><path fill="pink" d="M18.9645 1.46447L0.464466 19.9645L7.53553 27.0355L22.5 12.0711L37.4645 27.0355L44.5355 19.9645L26.0355 1.46447Q25.8618 1.29078 25.672 1.13495Q25.4821 0.979119 25.2778 0.842652Q25.0736 0.706185 24.857 0.590394Q24.6404 0.474603 24.4134 0.380602Q24.1865 0.286602 23.9514 0.215298Q23.7164 0.143994 23.4754 0.0960736Q23.2345 0.0481527 22.9901 0.0240764Q22.7456 0 22.5 0Q22.2544 0 22.0099 0.0240764Q21.7655 0.0481527 21.5245 0.0960736Q21.2836 0.143994 21.0486 0.215298Q20.8135 0.286602 20.5866 0.380602Q20.3596 0.474603 20.143 0.590394Q19.9264 0.706185 19.7221 0.842652Q19.5179 0.979119 19.328 1.13495Q19.1382 1.29078 18.9645 1.46447Z"></path></svg>`
: `<svg width="45" height="28" viewBox="0 0 45 28"><path fill="pink" d="M18.9645 1.46447L0.464466 19.9645L7.53553 27.0355L22.5 12.0711L37.4645 27.0355L44.5355 19.9645L26.0355 1.46447Q25.9487 1.37767 25.8578 1.29524Q25.7668 1.21282 25.672 1.13495Q25.5771 1.05708 25.4785 0.983962Q25.3799 0.910844 25.2778 0.842652Q25.1758 0.774459 25.0705 0.711357Q24.9652 0.648254 24.857 0.590394Q24.7487 0.532533 24.6378 0.480054Q24.5268 0.427574 24.4134 0.380602Q24.3 0.333631 24.1844 0.29228Q24.0689 0.250929 23.9514 0.215298Q23.834 0.179668 23.7149 0.149844Q23.5958 0.12002 23.4755 0.0960736Q23.3551 0.0721276 23.2337 0.0541174Q23.1122 0.0361073 22.9901 0.0240764Q22.8679 0.0120454 22.7453 0.00602272Q22.6227 0 22.5 0Q22.3773 0 22.2547 0.00602272Q22.1321 0.0120454 22.0099 0.0240764Q21.8878 0.0361073 21.7663 0.0541174Q21.6449 0.0721276 21.5245 0.0960736Q21.4042 0.12002 21.2851 0.149844Q21.166 0.179668 21.0486 0.215298Q20.9311 0.250929 20.8155 0.29228Q20.7 0.333631 20.5866 0.380602Q20.4732 0.427574 20.3622 0.480054Q20.2513 0.532533 20.143 0.590394Q20.0348 0.648254 19.9295 0.711357Q19.8242 0.774459 19.7221 0.842652Q19.6201 0.910844 19.5215 0.983962Q19.4229 1.05708 19.328 1.13495Q19.2332 1.21282 19.1422 1.29524Q19.0513 1.37767 18.9645 1.46447Z"></path></svg>`
t.is(svg, expected)
})

// 直角
Expand Down

1 comment on commit 21983c2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 21983c2 Previous: 6d0df59 Ratio
Draw house#skia-canvas 22.9 ops/sec (±0.87%) 25 ops/sec (±0.96%) 1.09
Draw house#node-canvas 21.3 ops/sec (±0.22%) 21 ops/sec (±1.56%) 0.99
Draw house#@napi-rs/skia 20.6 ops/sec (±0.87%) 22 ops/sec (±0.5%) 1.07
Draw gradient#skia-canvas 21.6 ops/sec (±0.8%) 24 ops/sec (±0.29%) 1.11
Draw gradient#node-canvas 20.4 ops/sec (±0.21%) 20 ops/sec (±0.24%) 0.98
Draw gradient#@napi-rs/skia 19.8 ops/sec (±0.66%) 21 ops/sec (±0.39%) 1.06

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.