artifactGraph snapshot stability (#3305)
* artifactgraph snapshot stability * clean up * tweak * Look at this (photo)Graph *in the voice of Nickelback* * trigger ci --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@ -458,9 +458,6 @@ async function GraphTheGraph(
|
|||||||
await page.waitForSelector('#plotly-graph')
|
await page.waitForSelector('#plotly-graph')
|
||||||
const element = await page.$('#plotly-graph')
|
const element = await page.$('#plotly-graph')
|
||||||
|
|
||||||
// wait an extra bit for things to settle
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
await element.screenshot({
|
await element.screenshot({
|
||||||
path: `./e2e/playwright/temp3.png`,
|
path: `./e2e/playwright/temp3.png`,
|
||||||
@ -468,30 +465,45 @@ async function GraphTheGraph(
|
|||||||
|
|
||||||
await browser.close()
|
await browser.close()
|
||||||
|
|
||||||
const img1Path = path.resolve(`./src/lang/std/artifactMapGraphs/${imageName}`)
|
const originalImgPath = path.resolve(
|
||||||
const img2Path = path.resolve('./e2e/playwright/temp3.png')
|
`./src/lang/std/artifactMapGraphs/${imageName}`
|
||||||
|
)
|
||||||
|
// chop the top 30 pixels off the image
|
||||||
|
const originalImg = PNG.sync.read(fs.readFileSync(originalImgPath))
|
||||||
|
// const img1Data = new Uint8Array(img1.data)
|
||||||
|
// const img1DataChopped = img1Data.slice(30 * img1.width * 4)
|
||||||
|
// img1.data = Buffer.from(img1DataChopped)
|
||||||
|
|
||||||
const img1 = PNG.sync.read(fs.readFileSync(img1Path))
|
const newImagePath = path.resolve('./e2e/playwright/temp3.png')
|
||||||
const img2 = PNG.sync.read(fs.readFileSync(img2Path))
|
const newImage = PNG.sync.read(fs.readFileSync(newImagePath))
|
||||||
|
const newImageData = new Uint8Array(newImage.data)
|
||||||
|
const newImageDataChopped = newImageData.slice(30 * newImage.width * 4)
|
||||||
|
newImage.data = Buffer.from(newImageDataChopped)
|
||||||
|
|
||||||
const { width, height } = img1
|
const { width, height } = originalImg
|
||||||
const diff = new PNG({ width, height })
|
const diff = new PNG({ width, height })
|
||||||
|
|
||||||
const numDiffPixels = pixelmatch(
|
const imageSizeDifferent = originalImg.data.length !== newImage.data.length
|
||||||
img1.data,
|
let numDiffPixels = 0
|
||||||
img2.data,
|
if (!imageSizeDifferent) {
|
||||||
diff.data,
|
numDiffPixels = pixelmatch(
|
||||||
width,
|
originalImg.data,
|
||||||
height,
|
newImage.data,
|
||||||
{ threshold: 0.1 }
|
diff.data,
|
||||||
)
|
width,
|
||||||
|
height,
|
||||||
|
{
|
||||||
|
threshold: 0.1,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (numDiffPixels > 10) {
|
if (numDiffPixels > 10 || imageSizeDifferent) {
|
||||||
console.warn('numDiffPixels', numDiffPixels)
|
console.warn('numDiffPixels', numDiffPixels)
|
||||||
// write file out to final place
|
// write file out to final place
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
`src/lang/std/artifactMapGraphs/${imageName}`,
|
`src/lang/std/artifactMapGraphs/${imageName}`,
|
||||||
PNG.sync.write(img2)
|
PNG.sync.write(newImage)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 180 KiB |
Binary file not shown.
Before Width: | Height: | Size: 374 KiB After Width: | Height: | Size: 371 KiB |
Reference in New Issue
Block a user