From 7794a601919cef4b529318027fa98474a6e11ddb Mon Sep 17 00:00:00 2001 From: Matt Gaunt Date: Sat, 27 Jan 2018 11:08:58 -0800 Subject: [PATCH] Fixes Firefox Nightly and adds improve safari support (#109) * Fixes Firefox Nightly and adds improve safari support * Adding logging for trqvis debugging * Force download on travis --- package.json | 3 +-- src/browser-models/local-browser.js | 5 ++++- src/download-manager.js | 12 ++++++------ src/index.js | 2 +- src/local-browsers/firefox.js | 4 ++-- src/local-browsers/safari.js | 1 + test/browser-usage.js | 27 ++++++++++++++++----------- test/downloading-browsers.js | 4 ++-- test/expiration-behavior.js | 6 +++--- 9 files changed, 36 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 6b6ef8b..38e21a0 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "src/index.js", "scripts": { "lint": "eslint '.'", - "test": "npm run lint && mocha", + "test": "mocha && npm run lint", "istanbul": "npm run lint && istanbul cover _mocha", "coveralls": "cat ./coverage/lcov.info | coveralls", "postpublish-release": "track-pkg-size", @@ -47,7 +47,6 @@ }, "dependencies": { "chalk": "^2.1.0", - "del": "^3.0.0", "dmg": "^0.1.0", "fs-extra": "^4.0.2", "mkdirp": "^0.5.1", diff --git a/src/browser-models/local-browser.js b/src/browser-models/local-browser.js index db4d6e6..1a04a50 100644 --- a/src/browser-models/local-browser.js +++ b/src/browser-models/local-browser.js @@ -80,7 +80,10 @@ class LocalBrowser extends Browser { const minVersion = this._getMinSupportedVersion(); if (minVersion) { - return this.getVersionNumber() >= minVersion; + const browserVersion = this.getVersionNumber(); + if (browserVersion !== -1 && browserVersion < minVersion) { + return false; + } } if (this.isBlackListed()) { diff --git a/src/download-manager.js b/src/download-manager.js index c59e0ab..4ec03bd 100644 --- a/src/download-manager.js +++ b/src/download-manager.js @@ -21,7 +21,6 @@ const path = require('path'); const fs = require('fs'); const request = require('request'); const mkdirp = require('mkdirp'); -const del = require('del'); const dmg = require('dmg'); const fse = require('fs-extra'); const yauzl = require('yauzl'); @@ -70,6 +69,7 @@ class DownloadManager { let localStorage = null; return new Promise((resolve, reject) => { + // TODO: Switch to fs-extra mkdirp(localstoragePath, (err) => { if (err) { return reject(err); @@ -268,7 +268,7 @@ class DownloadManager { }) .then((filePath) => { if (filePath) { - return del(filePath, {force: true}); + return fse.remove(filePath); } }); } @@ -295,7 +295,7 @@ class DownloadManager { ffProduct = 'firefox-beta-latest'; break; case 'unstable': - firefoxMacApp = 'FirefoxNightly.app'; + firefoxMacApp = 'Firefox Nightly.app'; ffProduct = 'firefox-nightly-latest'; break; default: @@ -396,7 +396,7 @@ class DownloadManager { }) .then((filePath) => { if (filePath) { - return del(filePath, {force: true}); + return fse.remove(filePath); } }); } @@ -604,7 +604,7 @@ class DownloadManager { }); }) .then((filePath) => { - return del(currentAppPath, {force: true}) + return fse.remove(currentAppPath) .then(() => filePath); }); }); @@ -614,7 +614,7 @@ class DownloadManager { }) .then((filePath) => { if (filePath) { - return del(filePath, {force: true}); + return fse.remove(filePath); } }); } diff --git a/src/index.js b/src/index.js index 1cdd364..126bcb1 100644 --- a/src/index.js +++ b/src/index.js @@ -343,7 +343,7 @@ class SeleniumAssistant { quitTimeout = setTimeout(resolve, 2000); driver.close() - .then(() => driver.quit()) + .then(() => driver.quit(), () => driver.quit()) .then(resolve, resolve); }) .then(() => { diff --git a/src/local-browsers/firefox.js b/src/local-browsers/firefox.js index f34a5dd..94d123e 100644 --- a/src/local-browsers/firefox.js +++ b/src/local-browsers/firefox.js @@ -87,7 +87,7 @@ class LocalChromeBrowser extends LocalBrowser { // Find OS X expected path let firefoxAppName; if (this._release === 'unstable') { - firefoxAppName = 'FirefoxNightly.app'; + firefoxAppName = 'Firefox Nightly.app'; } else { firefoxAppName = 'Firefox.app'; } @@ -129,7 +129,7 @@ class LocalChromeBrowser extends LocalBrowser { if (this._release === 'stable') { return '/Applications/Firefox.app/Contents/MacOS/firefox'; } else if (this._release === 'unstable') { - return '/Applications/FirefoxNightly.app/Contents/MacOS/firefox'; + return '/Applications/Firefox Nightly.app/Contents/MacOS/firefox'; } break; case 'linux': diff --git a/src/local-browsers/safari.js b/src/local-browsers/safari.js index cfabcd3..ce143f4 100644 --- a/src/local-browsers/safari.js +++ b/src/local-browsers/safari.js @@ -52,6 +52,7 @@ class LocalSafariBrowser extends LocalBrowser { */ getSeleniumDriverBuilder() { const seleniumOptions = this.getSeleniumOptions(); + seleniumOptions.setTechnologyPreview((this._release === 'beta')); const builder = new webdriver .Builder() diff --git a/test/browser-usage.js b/test/browser-usage.js index d9f23a0..6efe6f6 100644 --- a/test/browser-usage.js +++ b/test/browser-usage.js @@ -80,11 +80,14 @@ describe('Test Usage of Browsers', function() { const versionString = specificBrowser.getRawVersionString(); (typeof versionString).should.equal('string'); (versionString === null).should.equal(false); - versionString.length.should.gt(0); + // Chrome unstable has made it possible that this could happen + // versionString.length.should.gt(0); const versionNumber = specificBrowser.getVersionNumber(); (typeof versionNumber).should.equal('number'); - versionNumber.should.not.equal(-1); + if (versionString) { + versionNumber.should.not.equal(-1); + } const prettyName = specificBrowser.getPrettyName(); prettyName.length.should.gt(1); @@ -109,9 +112,9 @@ describe('Test Usage of Browsers', function() { return; } + testBrowserInfo(localBrowser); return testNormalSeleniumUsage(localBrowser) - .then(() => testBuilderSeleniumUsage(localBrowser)) - .then(() => testBrowserInfo(localBrowser)); + .then(() => testBuilderSeleniumUsage(localBrowser)); }); it('should get null for raw version output if no executable found', function() { @@ -161,14 +164,15 @@ describe('Test Usage of Browsers', function() { before(function() { seleniumAssistant.setBrowserInstallDir(null); + const expiration = process.env.TRAVIS ? 0 : 24; console.log('Downloading browsers....'); return Promise.all([ - seleniumAssistant.downloadLocalBrowser('chrome', 'stable'), - seleniumAssistant.downloadLocalBrowser('chrome', 'beta'), - seleniumAssistant.downloadLocalBrowser('chrome', 'unstable'), - seleniumAssistant.downloadLocalBrowser('firefox', 'stable'), - seleniumAssistant.downloadLocalBrowser('firefox', 'beta'), - seleniumAssistant.downloadLocalBrowser('firefox', 'unstable'), + seleniumAssistant.downloadLocalBrowser('chrome', 'stable', expiration), + seleniumAssistant.downloadLocalBrowser('chrome', 'beta', expiration), + seleniumAssistant.downloadLocalBrowser('chrome', 'unstable', expiration), + seleniumAssistant.downloadLocalBrowser('firefox', 'stable', expiration), + seleniumAssistant.downloadLocalBrowser('firefox', 'beta', expiration), + seleniumAssistant.downloadLocalBrowser('firefox', 'unstable', expiration), ]) .catch((err) => { console.warn('There was an issue downloading the browsers: ', err); @@ -200,7 +204,8 @@ describe('Test Usage of Browsers', function() { return globalServer.killServer(); }); - const localBrowserFiles = fs.readdirSync('./src/local-browsers'); + const localBrowserFiles = fs.readdirSync( + path.join(__dirname, '..', 'src', 'local-browsers')); localBrowserFiles.forEach((localBrowserFile) => { const LocalBrowserClass = require(`./../src/local-browsers/${localBrowserFile}`); const browserReleases = LocalBrowserClass.getPrettyReleaseNames(); diff --git a/test/downloading-browsers.js b/test/downloading-browsers.js index b1bbeff..c11be1a 100644 --- a/test/downloading-browsers.js +++ b/test/downloading-browsers.js @@ -1,6 +1,6 @@ 'use strict'; -const del = require('del'); +const fs = require('fs-extra'); const seleniumAssistant = require('../src/index.js'); const TIMEOUT = 5 * 60 * 1000; @@ -14,7 +14,7 @@ describe('Test Download Manager - Browser Download', function() { // Reset Install Directory seleniumAssistant.setBrowserInstallDir(null); - return del(seleniumAssistant.getBrowserInstallDir(), {force: true}); + return fs.remove(seleniumAssistant.getBrowserInstallDir()); }); const setupDownloadTest = (browserId, release) => { diff --git a/test/expiration-behavior.js b/test/expiration-behavior.js index 56a71f2..724bb5a 100644 --- a/test/expiration-behavior.js +++ b/test/expiration-behavior.js @@ -1,6 +1,6 @@ 'use strict'; -const del = require('del'); +const fse = require('fs-extra'); const sinon = require('sinon'); const LocalStorage = require('node-localstorage').LocalStorage; const path = require('path'); @@ -149,14 +149,14 @@ describe('Test Download Manager - Browser Expiration', function() { stub.restore(); }); - return del(seleniumAssistant.getBrowserInstallDir(), {force: true}); + return fse.remove(seleniumAssistant.getBrowserInstallDir()); }); beforeEach(function() { this.timeout(6000); // Ensure the test output is clear at the start - return del(seleniumAssistant.getBrowserInstallDir(), {force: true}); + return fse.remove(seleniumAssistant.getBrowserInstallDir()); }); const browsers = [