Integration test: screenshots
This commit is contained in:
@@ -14,7 +14,7 @@ module.exports = class TorrentList extends React.Component {
|
|||||||
if (state.downloadPathStatus === 'missing') {
|
if (state.downloadPathStatus === 'missing') {
|
||||||
contents.push(
|
contents.push(
|
||||||
<div key='torrent-missing-path'>
|
<div key='torrent-missing-path'>
|
||||||
<p id='torrent-error'>Download path missing: {state.saved.prefs.downloadPath}</p>
|
<p>Download path missing: {state.saved.prefs.downloadPath}</p>
|
||||||
<p>Check that all drives are connected?</p>
|
<p>Check that all drives are connected?</p>
|
||||||
<p>Alternatively, choose a new download path
|
<p>Alternatively, choose a new download path
|
||||||
in <a href='#' onClick={dispatcher('preferences')}>Preferences</a>
|
in <a href='#' onClick={dispatcher('preferences')}>Preferences</a>
|
||||||
|
|||||||
@@ -32,10 +32,12 @@ test('show download path missing', function (t) {
|
|||||||
.then((text) => console.log('Title ' + text))
|
.then((text) => console.log('Title ' + text))
|
||||||
.then(() => app.client.waitUntilTextExists('.torrent-list', 'Download path missing'))
|
.then(() => app.client.waitUntilTextExists('.torrent-list', 'Download path missing'))
|
||||||
.then((err) => t.notOk(err))
|
.then((err) => t.notOk(err))
|
||||||
|
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-download-path-missing'))
|
||||||
.then(() => app.client.click('a'))
|
.then(() => app.client.click('a'))
|
||||||
.then(() => setup.wait())
|
.then(() => setup.wait())
|
||||||
.then(() => app.browserWindow.getTitle())
|
.then(() => app.browserWindow.getTitle())
|
||||||
.then((windowTitle) => t.equal(windowTitle, 'Preferences'))
|
.then((windowTitle) => t.equal(windowTitle, 'Preferences', 'window title'))
|
||||||
|
.then(() => setup.screenshotCreateOrCompare(app, t, 'prefs-basic'))
|
||||||
.then(() => setup.endTest(app, t),
|
.then(() => setup.endTest(app, t),
|
||||||
(err) => setup.endTest(app, t, err || 'error'))
|
(err) => setup.endTest(app, t, err || 'error'))
|
||||||
})
|
})
|
||||||
|
|||||||
BIN
test/screenshots/darwin/prefs-basic.png
Normal file
BIN
test/screenshots/darwin/prefs-basic.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
BIN
test/screenshots/darwin/torrent-list-download-path-missing.png
Normal file
BIN
test/screenshots/darwin/torrent-list-download-path-missing.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
@@ -28,16 +28,19 @@ function createApp (t) {
|
|||||||
// Starts the app, waits for it to load, returns a promise
|
// Starts the app, waits for it to load, returns a promise
|
||||||
function waitForLoad (app, t) {
|
function waitForLoad (app, t) {
|
||||||
return app.start().then(function () {
|
return app.start().then(function () {
|
||||||
|
// Switch to the main window. Index 0 is apparently the hidden webtorrent window...
|
||||||
return app.client.windowByIndex(1)
|
return app.client.windowByIndex(1)
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
return app.client.waitUntilWindowLoaded()
|
return app.client.waitUntilWindowLoaded()
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
return app.webContents.getTitle()
|
return app.webContents.getTitle()
|
||||||
}).then(function (title) {
|
}).then(function (title) {
|
||||||
t.equal(title, 'WebTorrent Desktop', 'app title')
|
// Note the window title is WebTorrent (BETA), this is the HTML <title>
|
||||||
|
t.equal(title, 'WebTorrent Desktop', 'html title')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a promise that resolves after 'ms' milliseconds. Default: 500
|
||||||
function wait (ms) {
|
function wait (ms) {
|
||||||
if (ms === undefined) ms = 500 // Default: wait long enough for the UI to update
|
if (ms === undefined) ms = 500 // Default: wait long enough for the UI to update
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
@@ -45,24 +48,26 @@ function wait (ms) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Quit the app, end the test, either in success (!err) or failure (err)
|
||||||
function endTest (app, t, err) {
|
function endTest (app, t, err) {
|
||||||
return app.stop().then(function () {
|
return app.stop().then(function () {
|
||||||
t.end(err)
|
t.end(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes a screenshot of the app
|
||||||
|
// 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) {
|
function screenshotCreateOrCompare (app, t, name) {
|
||||||
const ssPath = path.join(__dirname, 'screenshots', process.platform, name + '.png')
|
const ssPath = path.join(__dirname, 'screenshots', process.platform, name + '.png')
|
||||||
console.log('Capturing ' + ssPath)
|
|
||||||
fs.ensureFileSync(ssPath)
|
fs.ensureFileSync(ssPath)
|
||||||
const ssBuf = fs.readFileSync(ssPath)
|
const ssBuf = fs.readFileSync(ssPath)
|
||||||
return app.browserWindow.capturePage().then(function (buffer) {
|
return app.browserWindow.capturePage().then(function (buffer) {
|
||||||
if (ssBuf.length === 0) {
|
if (ssBuf.length === 0) {
|
||||||
console.log('Saving screenshot ' + ssPath)
|
console.log('Saving screenshot ' + ssPath)
|
||||||
fs.writeFileSync(ssPath, buffer)
|
fs.writeFileSync(ssPath, buffer)
|
||||||
} else if (Buffer.compare(buffer, ssBuf) !== 0) {
|
|
||||||
return Promise.reject('Screenshot didn\'t match: ' + ssPath)
|
|
||||||
} else {
|
} else {
|
||||||
|
t.ok(Buffer.compare(buffer, ssBuf) === 0, 'screenshot ' + name)
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user