Skip to content

Commit daa7111

Browse files
committed
2 parents 03b83bf + 779acac commit daa7111

File tree

7 files changed

+446
-358
lines changed

7 files changed

+446
-358
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",

src/locales/gl.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "gl",
3+
"options": {
4+
"months": [
5+
"Xaneiro",
6+
"Febreiro",
7+
"Marzo",
8+
"Abril",
9+
"Maio",
10+
"Xuño",
11+
"Xullo",
12+
"Agosto",
13+
"Setembro",
14+
"Outubro",
15+
"Novembro",
16+
"Decembro"
17+
],
18+
"shortMonths": [
19+
"Xan",
20+
"Feb",
21+
"Mar",
22+
"Abr",
23+
"Mai",
24+
"Xuñ",
25+
"Xul",
26+
"Ago",
27+
"Set",
28+
"Out",
29+
"Nov",
30+
"Dec"
31+
],
32+
"days": [
33+
"Domingo",
34+
"Luns",
35+
"Martes",
36+
"Mércores",
37+
"Xoves",
38+
"Venres",
39+
"Sábado"
40+
],
41+
"shortDays": [
42+
"Dom",
43+
"Lun",
44+
"Mar",
45+
"Mér",
46+
"Xov",
47+
"Ven",
48+
"Sáb"
49+
],
50+
"toolbar": {
51+
"exportToSVG": "Descargar SVG",
52+
"exportToPNG": "Descargar PNG",
53+
"exportToCSV": "Descargar CSV",
54+
"menu": "Menu",
55+
"selection": "Seleccionar",
56+
"selectionZoom": "Seleccionar Zoom",
57+
"zoomIn": "Aumentar",
58+
"zoomOut": "Disminuír",
59+
"pan": "Navegación",
60+
"reset": "Reiniciar Zoom"
61+
}
62+
}
63+
}

src/utils/Utils.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,20 @@ class Utils {
448448
// Find the Greatest Common Divisor of two numbers
449449
//
450450
static getGCD(a, b, p = 7) {
451-
let big = Math.pow(10, p - Math.floor(Math.log10(Math.max(a, b))))
452-
a = Math.round(Math.abs(a) * big)
453-
b = Math.round(Math.abs(b) * big)
451+
let factor = Math.pow(10, p - Math.floor(Math.log10(Math.max(a, b))))
452+
if (factor > 1) {
453+
a = Math.round(Math.abs(a) * factor)
454+
b = Math.round(Math.abs(b) * factor)
455+
} else {
456+
factor = 1
457+
}
454458

455459
while (b) {
456460
let t = b
457461
b = a % b
458462
a = t
459463
}
460-
return a / big
464+
return a / factor
461465
}
462466

463467
static getPrimeFactors(n) {

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)