Integration test: screenshot compare ignoring transparency
This commit is contained in:
@@ -66,6 +66,7 @@
|
|||||||
"nodemon": "^1.10.2",
|
"nodemon": "^1.10.2",
|
||||||
"open": "0.0.5",
|
"open": "0.0.5",
|
||||||
"plist": "^2.0.1",
|
"plist": "^2.0.1",
|
||||||
|
"pngjs": "^3.0.0",
|
||||||
"rimraf": "^2.5.2",
|
"rimraf": "^2.5.2",
|
||||||
"run-series": "^1.1.4",
|
"run-series": "^1.1.4",
|
||||||
"spectron": "^3.3.0",
|
"spectron": "^3.3.0",
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ test('app runs', function (t) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
require('./test-torrent-list')
|
require('./test-torrent-list')
|
||||||
// require('./test-add-torrent')
|
require('./test-add-torrent')
|
||||||
// require('./test-video')
|
require('./test-video')
|
||||||
|
|
||||||
|
// TODO:
|
||||||
// require('./test-audio')
|
// require('./test-audio')
|
||||||
// require('./test-cast')
|
// require('./test-cast')
|
||||||
// require('./test-prefs')
|
// 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 Application = require('spectron').Application
|
||||||
const fs = require('fs-extra')
|
const fs = require('fs-extra')
|
||||||
const parseTorrent = require('parse-torrent')
|
const parseTorrent = require('parse-torrent')
|
||||||
|
const PNG = require('pngjs').PNG
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -78,7 +79,7 @@ function screenshotCreateOrCompare (app, t, name) {
|
|||||||
console.log('Saving screenshot ' + ssPath)
|
console.log('Saving screenshot ' + ssPath)
|
||||||
fs.writeFileSync(ssPath, buffer)
|
fs.writeFileSync(ssPath, buffer)
|
||||||
} else {
|
} else {
|
||||||
const match = Buffer.compare(buffer, ssBuf) === 0
|
const match = compareIgnoringTransparency(buffer, ssBuf)
|
||||||
t.ok(match, 'screenshot comparison ' + name)
|
t.ok(match, 'screenshot comparison ' + name)
|
||||||
if (!match) {
|
if (!match) {
|
||||||
const ssFailedPath = path.join(ssDir, name + '-failed.png')
|
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
|
// Resets the test directory, containing config.json, torrents, downloads, etc
|
||||||
function resetTestDataDir () {
|
function resetTestDataDir () {
|
||||||
fs.removeSync(config.TEST_DIR)
|
fs.removeSync(config.TEST_DIR)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ test('basic-streaming', function (t) {
|
|||||||
setup.waitForLoad(app, t, {online: true})
|
setup.waitForLoad(app, t, {online: true})
|
||||||
.then(() => app.client.waitUntilTextExists('.torrent-list', 'Big Buck Bunny'))
|
.then(() => app.client.waitUntilTextExists('.torrent-list', 'Big Buck Bunny'))
|
||||||
// Play Big Buck Bunny. Wait for it to start streaming.
|
// 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(() => setup.wait())
|
||||||
.then(() => app.client.click('.icon.play'))
|
.then(() => app.client.click('.icon.play'))
|
||||||
.then(() => setup.wait(10e3))
|
.then(() => setup.wait(10e3))
|
||||||
@@ -23,6 +23,8 @@ test('basic-streaming', function (t) {
|
|||||||
.then(() => app.webContents.executeJavaScript('dispatch("escapeBack")'))
|
.then(() => app.webContents.executeJavaScript('dispatch("escapeBack")'))
|
||||||
.then(() => setup.wait())
|
.then(() => setup.wait())
|
||||||
// Delete Big Buck Bunny
|
// Delete Big Buck Bunny
|
||||||
|
.then(() => app.client.moveToObject('.torrent'))
|
||||||
|
.then(() => setup.wait())
|
||||||
.then(() => app.client.click('.icon.delete'))
|
.then(() => app.client.click('.icon.delete'))
|
||||||
.then(() => setup.wait())
|
.then(() => setup.wait())
|
||||||
.then(() => app.client.click('.control.ok'))
|
.then(() => app.client.click('.control.ok'))
|
||||||
|
|||||||
Reference in New Issue
Block a user