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