Slide 33
Slide 33 text
const main = async (id: string, url: string, threshold = 0) => {
// url
をヘッドレスブラウザで開いて、新しくスクリーンショットを取る
await getNewScreenShot(id, url)
if (fs.existsSync(`${id}.old.png`) && fs.existsSync(`${id}.new.png`)) {
//
新旧ファイルが揃っているときは、比較する
const file1 = fs.readFileSync(`${id}.old.png`)
const file2 = fs.readFileSync(`${id}.new.png`)
const img1 = PNG.sync.read(file1)
const img2 = PNG.sync.read(file2)
const { width, height } = img2
const diff2 = new PNG({ width, height })
console.log('pixelmatch2', img1.width, img1.height, img2.width, img2.height)
const result2 = pixelmatch(
img1.data,
img2.data,
diff2.data,
width,
height,
{
// threshold: 0.1,
// includeAA: true,
// alpha: 0.5,
// aaColor: [255, 255, 0],
// diffColor: [255, 0, 0],
// diffColorAlt: [0, 0, 255],
// diffMask: false,
},
)
console.log('pixelmatch2', result2)
fs.writeFileSync(`${id}.diff2.png`, PNG.sync.write(diff2))
Appendix:ソースコード全録
Copyright (C) 2022 Toranoana Inc. All Rights Reserved.