Skip to content

Commit 0f9ec80

Browse files
js-kylegiggio
authored andcommittedSep 18, 2019
Automated Chromedriver updates (#230)
Add an npm script `update-chromedriver` to automate Chromedriver updates
1 parent 955d73c commit 0f9ec80

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed
 

‎.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tmp
55
Dockerfile
66
test-driver.sh
77
testInstall.js
8+
update.js
89
*.tgz
910
.vscode
1011
.editorconfig

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ executed as a callback at the end of your tests
210210
The NPM package version tracks the version of chromedriver that will be installed,
211211
with an additional build number that is used for revisions to the installer.
212212
You can use the package version number to install a specific version, or use the
213-
setting to a specific version. To always install the latest version of Chromedriver,
213+
setting to a specific version. If there is a new Chromedriver version available which is not yet available as a version of `node-chromedriver`, the npm command `npm run update-chromedriver` in this repository can be used to make the required updates to this module, please submit the change as a PR. To always install the latest version of Chromedriver,
214214
use `LATEST` as the version number:
215215

216216
```shell

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"chromedriver": "./bin/chromedriver"
2323
},
2424
"scripts": {
25-
"install": "node install.js"
25+
"install": "node install.js",
26+
"update-chromedriver": "node update.js"
2627
},
2728
"dependencies": {
2829
"del": "^4.1.1",

‎update.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const request = require('request');
2+
const fs = require('fs');
3+
const execSync = require('child_process').execSync;
4+
const CURRENT_VERSION = require('./lib/chromedriver').version;
5+
6+
// fetch the latest chromedriver version
7+
const getLatest = (cb) => {
8+
request('https://chromedriver.storage.googleapis.com/LATEST_RELEASE', (err, response, body) => {
9+
if (err) {
10+
process.exit(1);
11+
}
12+
return cb(body);
13+
});
14+
};
15+
16+
/* Provided a new Chromedriver version such as 77.0.3865.40:
17+
- update the version inside the ./lib/chromedriver helper file e.g. exports.version = '77.0.3865.40';
18+
- bumps package.json version number
19+
- add a git tag using the new node-chromedriver version
20+
- add a git commit, e.g. Bump version to 77.0.0
21+
*/
22+
const writeUpdate = (version) => {
23+
const helper = fs.readFileSync('./lib/chromedriver.js', 'utf8');
24+
const versionExport = 'exports.version';
25+
const regex = new RegExp(`^.*${versionExport}.*$`, 'gm');
26+
const updated = helper.replace(regex, `${versionExport} = '${version}';`);
27+
fs.writeFileSync('./lib/chromedriver.js', updated, 'utf8');
28+
const packageVersion = `${version.slice(0, 2)}.0.0`;
29+
execSync(`npm version ${packageVersion} --git-tag-version=false && git add . && git commit -m "Bump version to ${packageVersion}" && git tag ${packageVersion}`);
30+
};
31+
32+
getLatest((version) => {
33+
if (CURRENT_VERSION === version) {
34+
console.log('Chromedriver version is up to date.');
35+
} else {
36+
writeUpdate(version);
37+
console.log(`Chromedriver version updated to ${version}`);
38+
}
39+
});

0 commit comments

Comments
 (0)
Please sign in to comment.