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