Integration test: screenshot compare ignoring transparency
This commit is contained in:
@@ -15,9 +15,10 @@ test('app runs', function (t) {
|
||||
})
|
||||
|
||||
require('./test-torrent-list')
|
||||
// require('./test-add-torrent')
|
||||
// require('./test-video')
|
||||
require('./test-add-torrent')
|
||||
require('./test-video')
|
||||
|
||||
// TODO:
|
||||
// require('./test-audio')
|
||||
// require('./test-cast')
|
||||
// require('./test-prefs')
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 301 KiB After Width: | Height: | Size: 423 KiB |
BIN
test/screenshots/darwin/play-torrent-return.png
Normal file
BIN
test/screenshots/darwin/play-torrent-return.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 777 KiB |
@@ -2,6 +2,7 @@ const path = require('path')
|
||||
const Application = require('spectron').Application
|
||||
const fs = require('fs-extra')
|
||||
const parseTorrent = require('parse-torrent')
|
||||
const PNG = require('pngjs').PNG
|
||||
const config = require('./config')
|
||||
|
||||
module.exports = {
|
||||
@@ -78,7 +79,7 @@ function screenshotCreateOrCompare (app, t, name) {
|
||||
console.log('Saving screenshot ' + ssPath)
|
||||
fs.writeFileSync(ssPath, buffer)
|
||||
} else {
|
||||
const match = Buffer.compare(buffer, ssBuf) === 0
|
||||
const match = compareIgnoringTransparency(buffer, ssBuf)
|
||||
t.ok(match, 'screenshot comparison ' + name)
|
||||
if (!match) {
|
||||
const ssFailedPath = path.join(ssDir, name + '-failed.png')
|
||||
@@ -89,6 +90,30 @@ function screenshotCreateOrCompare (app, t, name) {
|
||||
})
|
||||
}
|
||||
|
||||
// Compares two PNGs, ignoring any transparent regions in bufExpected.
|
||||
// Returns true if they match.
|
||||
function compareIgnoringTransparency (bufActual, bufExpected) {
|
||||
// Common case: exact byte-for-byte match
|
||||
if (Buffer.compare(bufActual, bufExpected) === 0) return true
|
||||
|
||||
// Otherwise, compare pixel by pixel
|
||||
const pngA = PNG.sync.read(bufActual)
|
||||
const pngE = PNG.sync.read(bufExpected)
|
||||
if (pngA.width !== pngE.width || pngA.height !== pngE.height) return false
|
||||
const w = pngA.width
|
||||
const h = pngE.height
|
||||
const da = pngA.data
|
||||
const de = pngE.data
|
||||
for (let y = 0; y < h; y++) {
|
||||
for (let x = 0; x < w; x++) {
|
||||
const i = (y * w + x) * 4
|
||||
if (de[i + 3] === 0) continue // Skip transparent pixels
|
||||
if (da[i] !== de[i] || da[i + 1] !== de[i + 1] || da[i + 2] !== de[i + 2]) return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Resets the test directory, containing config.json, torrents, downloads, etc
|
||||
function resetTestDataDir () {
|
||||
fs.removeSync(config.TEST_DIR)
|
||||
|
||||
@@ -9,7 +9,7 @@ test('basic-streaming', function (t) {
|
||||
setup.waitForLoad(app, t, {online: true})
|
||||
.then(() => app.client.waitUntilTextExists('.torrent-list', 'Big Buck Bunny'))
|
||||
// Play Big Buck Bunny. Wait for it to start streaming.
|
||||
.then(() => app.client.moveToObject('.torrent.bbb'))
|
||||
.then(() => app.client.moveToObject('.torrent'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => app.client.click('.icon.play'))
|
||||
.then(() => setup.wait(10e3))
|
||||
@@ -23,6 +23,8 @@ test('basic-streaming', function (t) {
|
||||
.then(() => app.webContents.executeJavaScript('dispatch("escapeBack")'))
|
||||
.then(() => setup.wait())
|
||||
// Delete Big Buck Bunny
|
||||
.then(() => app.client.moveToObject('.torrent'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => app.client.click('.icon.delete'))
|
||||
.then(() => setup.wait())
|
||||
.then(() => app.client.click('.control.ok'))
|
||||
|
||||
Reference in New Issue
Block a user