Skip to content

Commit 0e7addc

Browse files
authored
Merge pull request #5104 from teimurjan/feat/use-blazediff-instead-of-pixelmatch
feat: use blazediff instead of pixelmatch
2 parents c2144e3 + e8f5960 commit 0e7addc

File tree

5 files changed

+375
-354
lines changed

5 files changed

+375
-354
lines changed

package-lock.json

Lines changed: 32 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@babel/core": "^7.8.7",
4949
"@babel/plugin-proposal-class-properties": "^7.8.3",
5050
"@babel/preset-env": "^7.8.7",
51+
"@blazediff/core": "1.0.0",
5152
"@rollup/plugin-babel": "^5.2.1",
5253
"@rollup/plugin-json": "4.0.1",
5354
"@rollup/plugin-node-resolve": "6.0.0",
@@ -73,7 +74,6 @@
7374
"jest-puppeteer": "^10.0.1",
7475
"nunjucks": "3.2.4",
7576
"nyc": "15.0.0",
76-
"pixelmatch": "5.1.0",
7777
"pngjs": "3.4.0",
7878
"postcss": "^8.4.21",
7979
"prettier": "2.8.5",

tests/e2e/samples.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const chalk = require('chalk')
22
const { spawnSync } = require('child_process')
33
const fs = require('fs-extra')
44
const path = require('path')
5-
const pixelmatch = require('pixelmatch')
5+
const blazediff = require('@blazediff/core')
66
const { PNG } = require('pngjs')
77
const { Cluster } = require('puppeteer-cluster')
88
const os = require('os')
@@ -100,7 +100,7 @@ async function processSample(page, sample, command) {
100100

101101
await page.goto(`file://${htmlPath}`)
102102

103-
let wait;
103+
let wait
104104
do {
105105
//Wait for all intervals in the page to have been cleared
106106
await page.waitForFunction(() => window.activeIntervalCount === 0)
@@ -117,7 +117,11 @@ async function processSample(page, sample, command) {
117117
//After the network requests, timers, and intervals finish, if another request, timer, or interval is created then we need
118118
//to wait for that to finish before continuing on.
119119
wait = await page.evaluate(() => {
120-
return !(window.activeIntervalCount === 0 && window.activeTimerCount === 0 && chart.w.globals.animationEnded)
120+
return !(
121+
window.activeIntervalCount === 0 &&
122+
window.activeTimerCount === 0 &&
123+
chart.w.globals.animationEnded
124+
)
121125
})
122126
} while (wait)
123127

@@ -151,7 +155,7 @@ async function processSample(page, sample, command) {
151155
// Compare screenshot to the original and throw error on differences
152156
const testImg = PNG.sync.read(testImgBuffer)
153157
// BUG: copy if original image doesn't exist and report in test results?
154-
let originalImg;
158+
let originalImg
155159
try {
156160
originalImg = PNG.sync.read(fs.readFileSync(originalImgPath))
157161
} catch (e) {
@@ -168,7 +172,7 @@ async function processSample(page, sample, command) {
168172
let err
169173

170174
try {
171-
numDiffs = pixelmatch(
175+
numDiffs = blazediff(
172176
originalImg.data,
173177
testImg.data,
174178
diffImg.data,
@@ -180,7 +184,7 @@ async function processSample(page, sample, command) {
180184
err = e
181185
}
182186

183-
// Save screenshot even if pixelmatch failed (due to image size mismatch)
187+
// Save screenshot even if blazediff failed (due to image size mismatch)
184188
if (numDiffs !== 0) {
185189
await fs.ensureDir(`${e2eDir}/diffs/${sample.dirName}`)
186190
fs.writeFileSync(`${e2eDir}/diffs/${relPath}.png`, testImgBuffer)
@@ -331,7 +335,11 @@ async function processSamples(command, paths, isCI) {
331335
)
332336

333337
if (testsMissingSnapshots.length > 0) {
334-
console.log(chalk.yellow.bold(`${testsMissingSnapshots.length} tests were missing snapshots to compare against. Those tests are:`))
338+
console.log(
339+
chalk.yellow.bold(
340+
`${testsMissingSnapshots.length} tests were missing snapshots to compare against. Those tests are:`
341+
)
342+
)
335343
for (const testMissingSnapshot of testsMissingSnapshots) {
336344
console.log(chalk.yellow.bold(`${testMissingSnapshot}\n`))
337345
}

tests/e2e/spec/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs'
22
import path from 'path'
3-
import pixelmatch from 'pixelmatch'
3+
import blazediff from '@blazediff/core'
44
import { PNG } from 'pngjs'
55
import puppeteer from 'puppeteer'
66
import { setTimeout as promisifiedTimeout } from 'timers/promises'
@@ -36,7 +36,7 @@ export function chartVisualTest(type, filename, imageFilename, validate) {
3636
const diffImg = new PNG({ width, height })
3737

3838
// BUG: fix threshold
39-
const numDiffs = pixelmatch(
39+
const numDiffs = blazediff(
4040
originalImg.data,
4141
testImg.data,
4242
diffImg.data,

0 commit comments

Comments
 (0)