Integration test: save failed screenshot comparisons

This commit is contained in:
DC
2016-09-08 17:30:48 -07:00
parent 967e161288
commit 1ad8a5313b
2 changed files with 18 additions and 3 deletions

View File

@@ -41,3 +41,12 @@ test('show download path missing', function (t) {
.then(() => setup.endTest(app, t),
(err) => setup.endTest(app, t, err || 'error'))
})
// TODO:
// require('./test-torrent-list')
// require('./test-add-torrent')
// require('./test-create-torrent')
// require('./test-prefs')
// require('./test-video')
// require('./test-audio')
// require('./test-cast')

View File

@@ -59,7 +59,8 @@ function endTest (app, t, err) {
// If we already have a reference under test/screenshots, assert that they're the same
// Otherwise, create the reference screenshot: test/screenshots/<platform>/<name>.png
function screenshotCreateOrCompare (app, t, name) {
const ssPath = path.join(__dirname, 'screenshots', process.platform, name + '.png')
const ssDir = path.join(__dirname, 'screenshots', process.platform)
const ssPath = path.join(ssDir, name + '.png')
fs.ensureFileSync(ssPath)
const ssBuf = fs.readFileSync(ssPath)
return app.browserWindow.capturePage().then(function (buffer) {
@@ -67,8 +68,13 @@ function screenshotCreateOrCompare (app, t, name) {
console.log('Saving screenshot ' + ssPath)
fs.writeFileSync(ssPath, buffer)
} else {
t.ok(Buffer.compare(buffer, ssBuf) === 0, 'screenshot ' + name)
return Promise.resolve()
const match = Buffer.compare(buffer, ssBuf) === 0
t.ok(match, 'screenshot comparison ' + name)
if (!match) {
const ssFailedPath = path.join(ssDir, name + '-failed.png')
console.log('Saving screenshot, failed comparison: ' + ssFailedPath)
fs.writeFileSync(ssFailedPath, buffer)
}
}
})
}