[selenium] propertly share download info

This commit is contained in:
spalger 2016-03-21 14:36:57 -07:00
parent 7061021822
commit f383827890
3 changed files with 19 additions and 14 deletions

View file

@ -1,14 +1,18 @@
var path = require('path');
import { resolve as resolveUrl } from 'url';
const URL = 'https://selenium-release.storage.googleapis.com/2.48/selenium-server-standalone-2.48.2.jar';
const DIR = resolveUrl(URL, './');
const FILE = URL.replace(DIR, '');
module.exports = function (grunt) {
return {
options: {
selenium: {
filename: 'selenium-server-standalone-2.48.2.jar',
server: 'https://selenium-release.storage.googleapis.com/2.48/',
filename: FILE,
server: DIR,
md5: 'b2784fc67c149d3c13c83d2108104689',
directory: path.join(grunt.config.get('root'), 'selenium')
path: path.join(grunt.config.get('root'), 'selenium', FILE)
}
}
};

View file

@ -122,7 +122,7 @@ module.exports = function (grunt) {
cmd: 'java',
args: [
'-jar',
'selenium/selenium-server-standalone-2.48.2.jar',
'<%= downloadSelenium.options.selenium.path %>',
'-port',
uiConfig.servers.webdriver.port,
]
@ -138,7 +138,7 @@ module.exports = function (grunt) {
cmd: 'java',
args: [
'-jar',
'selenium/selenium-server-standalone-2.48.2.jar',
'<%= downloadSelenium.options.selenium.path %>',
'-port',
uiConfig.servers.webdriver.port,
]

View file

@ -11,8 +11,9 @@ module.exports = function (grunt) {
const done = this.async();
const config = this.options();
const SELENIUM_FILE_PATH = path.join(config.selenium.directory, config.selenium.filename);
const SELENIUM_DOWNLOAD_URL = config.selenium.server + config.selenium.filename;
const FILE = config.selenium.path;
const DIR = path.dirname(config.selenium.path);
const URL = config.selenium.server + config.selenium.filename;
function validateDownload(path, expectedHash, success) {
grunt.log.write('Validating hash...');
@ -28,27 +29,27 @@ module.exports = function (grunt) {
}
function downloadSelenium(success) {
grunt.log.write(`Downloading ${SELENIUM_DOWNLOAD_URL}...`);
request.get(SELENIUM_DOWNLOAD_URL)
.pipe(fs.createWriteStream(SELENIUM_FILE_PATH))
grunt.log.write(`Downloading ${URL}...`);
request.get(URL)
.pipe(fs.createWriteStream(FILE))
.on('error', function downloadError(err) {
grunt.fail.warn(err);
})
.on('finish', function downloadFinish() {
grunt.log.writeln('done');
validateDownload(SELENIUM_FILE_PATH, config.selenium.md5, success);
validateDownload(FILE, config.selenium.md5, success);
});
}
function start() {
try {
fs.mkdirSync(config.selenium.directory);
fs.mkdirSync(DIR);
} catch (err) {
if (err && err.code !== 'EEXIST') grunt.fail.warn(err);
}
if (fs.existsSync(SELENIUM_FILE_PATH)) {
validateDownload(SELENIUM_FILE_PATH, config.selenium.md5, done);
if (fs.existsSync(FILE)) {
validateDownload(FILE, config.selenium.md5, done);
} else {
downloadSelenium(done);
}