const path = require('path') const Application = require('spectron').Application const fs = require('fs-extra') const TEST_DATA_DIR = path.join(__dirname, 'tempTestData') module.exports = { TEST_DATA_DIR, createApp, endTest, screenshotCreateOrCompare, waitForLoad, wait } // Runs WebTorrent Desktop. // Returns a promise that resolves to a Spectron Application once the app has loaded. // Takes a Tape test. Makes some basic assertions to verify that the app loaded correctly. function createApp (t) { return new Application({ path: path.join(__dirname, '..', 'node_modules', '.bin', 'electron' + (process.platform === 'win32' ? '.cmd' : '')), args: [path.join(__dirname, '..')], env: {NODE_ENV: 'test'} }) } // Starts the app, waits for it to load, returns a promise function waitForLoad (app, t) { return app.start().then(function () { // Switch to the main window. Index 0 is apparently the hidden webtorrent window... return app.client.windowByIndex(1) }).then(function () { return app.client.waitUntilWindowLoaded() }).then(function () { return app.webContents.getTitle() }).then(function (title) { // Note the window title is WebTorrent (BETA), this is the HTML