-
Notifications
You must be signed in to change notification settings - Fork 3
/
installer.spec.js
114 lines (100 loc) · 3.71 KB
/
installer.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'use strict';
/* eslint-disable no-console */
const chai = require('chai');
const expect = require('chai').expect;
const installer = require('./installer');
const path = require('path');
const shell = require('shelljs');
const sinonChai = require('sinon-chai');
const sinon = require('sinon');
chai.use(sinonChai);
describe('browserDriverInstaller', () =>
{
const DRIVER_OUTPUT_PATH = './output';
beforeEach(() =>
{
sinon.spy(console, 'log');
});
afterEach(() =>
{
console.log.restore();
cleanTheOutput();
});
function cleanTheOutput()
{
shell.rm('-rf', DRIVER_OUTPUT_PATH);
}
async function catchError(callback)
{
let thrownError;
try
{
await callback();
}
catch (error)
{
thrownError = error;
}
return thrownError;
}
it(
'should not attempt to install anything if one of the path, the version, or both parameters are not provided',
async () =>
{
expect((await catchError(() => installer.browserDriverInstaller())).message).to.equal(
'the parameters are not valid strings');
});
it(
'should throw an error if the requested version for a driver corresponding to an invalid version of a ' +
'browser is not included in the JSON file',
async () =>
{
const invalidVersion = '1';
expect((
await catchError(() => installer.browserDriverInstaller('Chrome', invalidVersion,
'/some/target/path')))
.message).to.match(
new RegExp(
'failed to locate a version of the chromedriver that matches the installed Chrome version ' +
'\\(1\\), the valid Chrome versions are:*'));
});
it(
'should install the \'chromedriver\' driver in the specified path if the version is included in the JSON file',
async () =>
{
await installer.browserDriverInstaller('Chrome', '70', DRIVER_OUTPUT_PATH);
expect(shell.test('-e', path.resolve(DRIVER_OUTPUT_PATH, 'chromedriver'))).to.be.true;
});
it(
'should install the \'geckodriver\' driver in the specified path if the version is included in the JSON file',
async () =>
{
await installer.browserDriverInstaller('Firefox', '58', DRIVER_OUTPUT_PATH);
expect(shell.test('-e', path.resolve(DRIVER_OUTPUT_PATH, 'geckodriver'))).to.be.true;
});
it(
'should install the \'chromedriver\' driver in the specified path if the version is greater than the max ' +
'version in the JSON',
async () =>
{
await installer.browserDriverInstaller('Chrome', '75', DRIVER_OUTPUT_PATH);
expect(shell.test('-e', path.resolve(DRIVER_OUTPUT_PATH, 'chromedriver'))).to.be.true;
});
it(
'should install the \'geckodriver\' driver in the specified path if the version is greater than the max ' +
'version in the JSON',
async () =>
{
await installer.browserDriverInstaller('Firefox', '65', DRIVER_OUTPUT_PATH);
expect(shell.test('-e', path.resolve(DRIVER_OUTPUT_PATH, 'geckodriver'))).to.be.true;
});
it(
'should not install a driver again if its expected version is already installed',
async () =>
{
let result = await installer.browserDriverInstaller('Chrome', '70', DRIVER_OUTPUT_PATH);
expect(result).to.be.true;
result = await installer.browserDriverInstaller('Chrome', '70', DRIVER_OUTPUT_PATH);
expect(result).to.be.false;
});
});