diff --git a/test/screenshots/win32/add-torrent-0-percent.png b/test/screenshots/win32/add-torrent-0-percent.png index 800128a8..e835effb 100644 Binary files a/test/screenshots/win32/add-torrent-0-percent.png and b/test/screenshots/win32/add-torrent-0-percent.png differ diff --git a/test/screenshots/win32/add-torrent-100-percent.png b/test/screenshots/win32/add-torrent-100-percent.png new file mode 100644 index 00000000..4c38cc59 Binary files /dev/null and b/test/screenshots/win32/add-torrent-100-percent.png differ diff --git a/test/screenshots/win32/play-torrent-wired-list.png b/test/screenshots/win32/play-torrent-wired-list.png index 411644ae..930f6233 100644 Binary files a/test/screenshots/win32/play-torrent-wired-list.png and b/test/screenshots/win32/play-torrent-wired-list.png differ diff --git a/test/setup.js b/test/setup.js index 5f9e8be1..2c664d6a 100644 --- a/test/setup.js +++ b/test/setup.js @@ -15,7 +15,8 @@ module.exports = { waitForLoad, wait, resetTestDataDir, - deleteTestDataDir + deleteTestDataDir, + copy } // Runs WebTorrent Desktop. @@ -97,6 +98,7 @@ function compareIgnoringTransparency (bufActual, bufExpected) { if (Buffer.compare(bufActual, bufExpected) === 0) return true // Otherwise, compare pixel by pixel + let sumSquareDiff = 0 const pngA = PNG.sync.read(bufActual) const pngE = PNG.sync.read(bufExpected) if (pngA.width !== pngE.width || pngA.height !== pngE.height) return false @@ -108,10 +110,21 @@ function compareIgnoringTransparency (bufActual, bufExpected) { 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 + const ca = (da[i] << 16) | (da[i + 1] << 8) | da[i + 2] + const ce = (de[i] << 16) | (de[i + 1] << 8) | de[i + 2] + if (ca === ce) continue + + // Add pixel diff to running sum + // This is necessary on Windows, where rendering apparently isn't quite deterministic + // and a few pixels in the screenshot will sometimes be off by 1. (Visually identical.) + sumSquareDiff += (da[i] - de[i]) * (da[i] - de[i]) + sumSquareDiff += (da[i + 1] - de[i + 1]) * (da[i + 1] - de[i + 1]) + sumSquareDiff += (da[i + 2] - de[i + 2]) * (da[i + 2] - de[i + 2]) } } - return true + const l2Distance = Math.round(Math.sqrt(sumSquareDiff)) + console.log('screenshot diff l2 distance: ' + l2Distance) + return l2Distance < 100 } // Resets the test directory, containing config.json, torrents, downloads, etc @@ -133,6 +146,9 @@ function compareDownloadFolder (t, dirname, filenames) { const dirpath = path.join(config.TEST_DIR_DOWNLOAD, dirname) try { const actualFilenames = fs.readdirSync(dirpath) + if (filenames === null) { + return t.fail('expected download folder to be absent, but it\'s here: ' + dirpath) + } const expectedSorted = filenames.slice().sort() const actualSorted = actualFilenames.slice().sort() t.deepEqual(actualSorted, expectedSorted, 'download folder contents: ' + dirname) @@ -168,3 +184,13 @@ function extractImportantFields (parsedTorrent) { const priv = parsedTorrent.private // private is a reserved word in JS return { infoHash, name, announce, urlList, comment, 'private': priv } } + +function copy (pathFrom, pathTo) { + try { + fs.copySync(pathFrom, pathTo) + } catch (e) { + // Windows sometimes gives us an EPERM error even tho the copy happened... + if (process.platform !== 'win32' || e.code !== 'EPERM') throw e + console.log('ignoring windows copy EPERM error', e) + } +} diff --git a/test/test-add-torrent.js b/test/test-add-torrent.js index 7b89e33e..8352ed96 100644 --- a/test/test-add-torrent.js +++ b/test/test-add-torrent.js @@ -1,5 +1,4 @@ const test = require('tape') -const fs = require('fs-extra') const path = require('path') const setup = require('./setup') const config = require('./config') @@ -23,7 +22,7 @@ test('add-torrent', function (t) { .then(() => app.client.waitUntilTextExists('REMOVE')) .then(() => app.client.click('.control.ok')) // Add the same existing torrent, this time with the file present. Should be at 100% - .then(() => fs.copySync( + .then(() => setup.copy( path.join(__dirname, 'resources', 'm3.jpg'), path.join(config.TEST_DIR_DOWNLOAD, 'm3.jpg'))) .then(() => app.electron.ipcRenderer.send('openTorrentFile')) @@ -39,7 +38,7 @@ test('create-torrent', function (t) { setup.resetTestDataDir() // Set up the files to seed - fs.copySync(path.join(__dirname, 'resources', 'm3.jpg'), config.SEED_FILES[0]) + setup.copy(path.join(__dirname, 'resources', 'm3.jpg'), config.SEED_FILES[0]) t.timeoutAfter(30e3) const app = setup.createApp() diff --git a/test/test-torrent-list.js b/test/test-torrent-list.js index da0b89a2..70e1ff05 100644 --- a/test/test-torrent-list.js +++ b/test/test-torrent-list.js @@ -83,6 +83,7 @@ test('torrent-list: expand torrent, unselect file', function (t) { // Start the torrent .then(() => app.client.click('#torrent-cosmos .icon.download')) .then(() => app.client.waitUntilTextExists('.torrent-list', 'peers')) + .then(() => setup.wait()) .then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-cosmos-expand-start')) // Make sure that it creates all files EXCEPT the deslected one .then(() => setup.compareDownloadFolder(t, 'CosmosLaundromatFirstCycle', [