diff --git a/bin/install-msedgedriver.js b/bin/install-msedgedriver.js index 872dedf..cbff51b 100644 --- a/bin/install-msedgedriver.js +++ b/bin/install-msedgedriver.js @@ -4,7 +4,7 @@ require('../src/utils/throw-up'); const got = require('got'); const { promisify } = require('util'); -const fs = { ...require('fs'), ...require('fs').promises }; +const fs = { ...require('fs'), ...require('fs').promises, ...require('../src/fs') }; const path = require('path'); const extractZip = require('extract-zip'); const pipeline = promisify(require('stream').pipeline); @@ -85,7 +85,11 @@ async function install() { let driverPath = await getDriverPath(version, driverName); - await downloadAndExtract({ version, driverName, driverPath }); + if (await fs.exists(driverPath)) { + console.log(`Found ${driverPath}, not downloading`); + } else { + await downloadAndExtract({ version, driverName, driverPath }); + } console.log(`Edge WebDriver available at ${driverPath}`); diff --git a/src/fs.js b/src/fs.js new file mode 100644 index 0000000..d66714b --- /dev/null +++ b/src/fs.js @@ -0,0 +1,17 @@ +'use strict'; + +const fs = { ...require('fs'), ...require('fs').promises }; + +async function exists(path) { + try { + await fs.access(path, fs.constants.F_OK); + + return true; + } catch { + return false; + } +} + +module.exports = { + exists, +}; diff --git a/test/acceptance/install-msedgedriver-test.js b/test/acceptance/install-msedgedriver-test.js index ef8386f..9dd3e82 100644 --- a/test/acceptance/install-msedgedriver-test.js +++ b/test/acceptance/install-msedgedriver-test.js @@ -43,4 +43,16 @@ describe(path.basename(installerPath), function() { expect(ps.stdout).to.include(version); }); + + it('doesn\'t redownload same version', async function() { + let string = `Found ${driverPath}, not downloading`; + + let ps = await execa.node(installerPath); + + expect(ps.stdout).to.not.include(string); + + ps = await execa.node(installerPath); + + expect(ps.stdout).to.include(string); + }); });