Skip to content

Commit

Permalink
feat: don't redownload existing versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed Sep 30, 2022
1 parent 3589e97 commit ec92fd3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bin/install-msedgedriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}`);

Expand Down
17 changes: 17 additions & 0 deletions src/fs.js
Original file line number Diff line number Diff line change
@@ -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,
};
12 changes: 12 additions & 0 deletions test/acceptance/install-msedgedriver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit ec92fd3

Please sign in to comment.