UNPKG

1.74 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7 * Code distributed by Google as part of the polymer project is also
8 * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9 */
10
11var SELENIUM_OVERRIDES = require('../package.json')['selenium-overrides'];
12// Work around a potential npm race condition:
13// https://github.com/npm/npm/issues/6624
14function requireSelenium(done, attempt) {
15 attempt = attempt || 0;
16 var selenium;
17 try {
18 selenium = require('selenium-standalone');
19 } catch (error) {
20 if (attempt > 3) { throw error; }
21 setTimeout(
22 requireSelenium.bind(null, done, attempt + 1),
23 Math.pow(2, attempt) // Exponential backoff to play it safe.
24 );
25 }
26 // All is well.
27 done(selenium);
28}
29
30var config = SELENIUM_OVERRIDES || {};
31config.logger = console.log.bind(console);
32
33if (!process.env.NOSELENIUM) {
34 requireSelenium(function(selenium) {
35 selenium.install(config, function(error) {
36 if (error) {
37 console.log('Failed to download selenium and/or chromedriver:', error);
38 console.log('selenium-standalone will attempt to re-download next time it is run.');
39 // We explicitly do not fail the install process if this happens; the user
40 // can still recover, unless their permissions are completely screwey.
41 }
42 });
43 });
44} else {
45 console.log('skipping install of selenium because of NOSELENIUM flag');
46}