Skip to content

Commit 903e472

Browse files
author
Bobby Earl
authored
Updated technique to test html-webpack-plugin. (blackbaud#191)
* Updated technique to test html-webpack-plugin. * Updated Chromedriver version * Refactored e2e's calling of chromedriver-manager-update so it can be called for Appveyor. * Debugging * Trying verbose logging * More debugging * Disabled verbose logging. Trying Chrome beta. * Trying firefox. * Wrong file. * Chrome on default dist. * Installing Chrome. * Trying additional flags. * Trying just sandbox flag with bionic. * Incorporated feedback. * Updated to non pre-release version of chromedriver-version-matcher.
1 parent a1331cd commit 903e472

11 files changed

+233
-144
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ yarn.lock
4747
*.iml
4848
*.ipr
4949
*.iws
50+
51+
dist

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
os:
22
- linux
33
- osx
4-
4+
55
language: node_js
66
dist: bionic
77

cli/e2e.js

+4-58
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44
const fs = require('fs-extra');
55
const glob = require('glob');
66
const path = require('path');
7-
const spawn = require('cross-spawn');
87
const selenium = require('selenium-standalone');
98
const protractorLauncher = require('protractor/built/launcher');
109
const logger = require('@blackbaud/skyux-logger');
11-
const matcher = require('chromedriver-version-matcher');
1210

1311
const build = require('./utils/run-build');
1412
const server = require('./utils/server');
1513
const configResolver = require('./utils/config-resolver');
16-
17-
// Disable this to quiet the output
18-
const spawnOptions = { stdio: 'inherit' };
14+
const chromeDriverManager = require('./utils/chromedriver-manager');
1915

2016
let seleniumServer;
2117
let start;
@@ -56,25 +52,6 @@ function spawnProtractor(configPath, chunks, port, skyPagesConfig) {
5652
process.on('exit', killServers);
5753
}
5854

59-
/**
60-
* Calls the getChromeDriverVersion method in our library, but handles any errors.
61-
*/
62-
function getChromeDriverVersion() {
63-
return new Promise(resolve => {
64-
const defaultVersion = 'latest';
65-
66-
matcher.getChromeDriverVersion()
67-
.then(result => {
68-
if (result.chromeDriverVersion) {
69-
resolve(result.chromeDriverVersion);
70-
} else {
71-
resolve(defaultVersion);
72-
}
73-
})
74-
.catch(() => resolve(defaultVersion));
75-
});
76-
}
77-
7855
/**
7956
* Spawns the selenium server if directConnect is not enabled.
8057
* @name spawnSelenium
@@ -105,40 +82,9 @@ function spawnSelenium(configPath) {
10582

10683
// Otherwise we need to prep protractor's selenium
10784
} else {
108-
109-
logger.info(`Getting webdriver version.`);
110-
111-
getChromeDriverVersion().then(version => {
112-
logger.info(`Updating webdriver to version ${version}`);
113-
114-
const webdriverManagerPath = path.resolve(
115-
'node_modules',
116-
'.bin',
117-
'webdriver-manager'
118-
);
119-
120-
const results = spawn.sync(
121-
webdriverManagerPath,
122-
[
123-
'update',
124-
'--standalone',
125-
'false',
126-
'--gecko',
127-
'false',
128-
'--versions.chrome',
129-
version
130-
],
131-
spawnOptions
132-
);
133-
134-
if (results.error) {
135-
reject(results.error);
136-
return;
137-
}
138-
139-
logger.info('Selenium server is ready.');
140-
resolve();
141-
});
85+
chromeDriverManager.update()
86+
.then(() => resolve())
87+
.catch(err => reject(err));
14288
}
14389
});
14490
}

cli/utils/chromedriver-manager.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*jslint node: true */
2+
'use strict';
3+
4+
const path = require('path');
5+
const spawn = require('cross-spawn');
6+
const logger = require('@blackbaud/skyux-logger');
7+
const matcher = require('chromedriver-version-matcher');
8+
9+
/**
10+
* Calls the getChromeDriverVersion method in our library.
11+
* Handles any errors and defaults to 'latest'.
12+
*/
13+
function getVersion() {
14+
return new Promise(resolve => {
15+
const defaultVersion = 'latest';
16+
17+
matcher.getChromeDriverVersion()
18+
.then(result => {
19+
if (result.chromeDriverVersion) {
20+
resolve(result.chromeDriverVersion);
21+
} else {
22+
resolve(defaultVersion);
23+
}
24+
})
25+
.catch(() => resolve(defaultVersion));
26+
});
27+
}
28+
29+
function update() {
30+
return new Promise((resolve, reject) => {
31+
getVersion().then(version => {
32+
logger.info(`Updating webdriver to version ${version}`);
33+
34+
const webdriverManagerPath = path.resolve(
35+
'node_modules',
36+
'.bin',
37+
'webdriver-manager'
38+
);
39+
40+
const results = spawn.sync(
41+
webdriverManagerPath,
42+
[
43+
'update',
44+
'--standalone',
45+
'false',
46+
'--gecko',
47+
'false',
48+
'--versions.chrome',
49+
version
50+
],
51+
{
52+
stdio: 'inherit'
53+
}
54+
);
55+
56+
if (results.error) {
57+
reject(results.error);
58+
} else {
59+
logger.info('webdriver successfully updated.');
60+
resolve();
61+
}
62+
});
63+
});
64+
}
65+
66+
module.exports = {
67+
getVersion,
68+
update
69+
};

config/protractor/protractor-dev.conf.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ if (process.env.TRAVIS) {
113113
config.capabilities = {
114114
browserName: 'chrome',
115115
'chromeOptions': {
116-
'args': ['--disable-extensions --ignore-certificate-errors']
116+
'args': [
117+
'--disable-extensions',
118+
'--ignore-certificate-errors',
119+
'--no-sandbox'
120+
]
117121
}
118122
};
119123
}

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"coverage:builder": "istanbul cover --report=html --dir=./coverage/builder ./node_modules/jasmine/bin/jasmine.js JASMINE_CONFIG_PATH=jasmine.json",
99
"coverage:runtime": "node ./utils/cli-test.js dev-runtime",
1010
"coverage:src-app": "node ./utils/cli-test.js dev-src-app",
11-
"e2e": "webdriver-manager update --standalone false --gecko false && npm run protractor",
11+
"e2e": "node ./utils/cli-chromedriver-manager-update && npm run protractor",
1212
"protractor": "protractor ./config/protractor/protractor-dev.conf.js",
1313
"lint": "eslint -c .eslintrc.json cli config lib loader plugin utils index.js",
1414
"test": "npm run lint && npm run coverage && npm run e2e"
@@ -70,7 +70,7 @@
7070
"angular2-template-loader": "0.6.2",
7171
"async": "2.6.3",
7272
"awesome-typescript-loader": "5.2.1",
73-
"chromedriver-version-matcher": "^1.0.0-alpha.2",
73+
"chromedriver-version-matcher": "^1.0.0",
7474
"cors": "2.8.5",
7575
"cross-spawn": "6.0.5",
7676
"enhanced-resolve": "4.1.1",

test/cli-e2e.spec.js

+9-77
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
'use strict';
33

44
const fs = require('fs-extra');
5-
const glob = require('glob');
65
const path = require('path');
76
const mock = require('mock-require');
8-
const spawn = require('cross-spawn');
97
const selenium = require('selenium-standalone');
108
const logger = require('@blackbaud/skyux-logger');
119

@@ -182,98 +180,32 @@ describe('cli e2e', () => {
182180

183181
it('should catch protractor\'s selenium failures', (done) => {
184182

183+
const error = new Error('custom-error');
184+
185185
mock('cross-spawn', {
186186
spawn: () => {
187187
return {
188188
on: () => { }
189189
};
190-
},
191-
sync: () => {
192-
return {
193-
error: new Error('Webdriver update failed.')
194-
};
195190
}
196191
});
197192

193+
mock('../cli/utils/chromedriver-manager', {
194+
update: () => Promise.reject(error)
195+
});
196+
198197
spyOn(process, 'exit').and.callFake(exitCode => {
199198
expect(exitCode).toEqual(1);
199+
expect(logger.error).toHaveBeenCalledWith(error);
200200
done();
201201
});
202202

203203
mock.reRequire('../cli/e2e')('e2e', ARGV, SKY_PAGES_CONFIG, WEBPACK);
204204
});
205205

206-
function webdriverManagerUpdate(version, expected, done) {
207-
208-
mock(configPath, {
209-
config: { }
210-
});
211-
212-
mock('../cli/utils/run-build', () => new Promise(resolve => {
213-
resolve({
214-
toJson: () => {
215-
return {
216-
chunks: CHUNKS
217-
}
218-
}
219-
});
220-
}));
221-
222-
mock('chromedriver-version-matcher', {
223-
getChromeDriverVersion: () => {
224-
if (version === undefined) {
225-
return Promise.reject();
226-
} else {
227-
return Promise.resolve({
228-
chromeDriverVersion: version
229-
});
230-
}
231-
}
232-
});
233-
234-
const spyCrossSpawnSync = jasmine.createSpy('sync').and.callFake(() => ({ error: '' }));
235-
mock('cross-spawn', {
236-
sync: spyCrossSpawnSync
237-
});
238-
239-
spyOn(fs, 'existsSync').and.returnValue(true);
240-
241-
mock.reRequire('../cli/e2e')(
242-
'e2e',
243-
ARGV,
244-
SKY_PAGES_CONFIG,
245-
WEBPACK
246-
);
247-
248-
spyOn(process, 'exit').and.callFake(() => {
249-
expect(spyCrossSpawnSync.calls.argsFor(0)[1]).toEqual([
250-
'update',
251-
'--standalone',
252-
'false',
253-
'--gecko',
254-
'false',
255-
'--versions.chrome',
256-
expected
257-
]);
258-
done();
259-
});
260-
}
261-
262-
it('should run webdriver-manager update command with the required version', (done) => {
263-
webdriverManagerUpdate('123', '123', done);
264-
});
265-
266-
it('should run webdriver-manager update command with latest if no version found', (done) => {
267-
webdriverManagerUpdate('', 'latest', done);
268-
});
269-
270-
it('should run webdriver-manager update command with latest if finding version fails', (done) => {
271-
webdriverManagerUpdate(undefined, 'latest', done);
272-
});
273-
274206
it('should not continue if no e2e spec files exist', (done) => {
275207
mock('glob', {
276-
sync: path => []
208+
sync: () => []
277209
});
278210

279211
spyOn(process, 'exit').and.callFake(exitCode => {
@@ -318,7 +250,7 @@ describe('cli e2e', () => {
318250

319251
it('should pass chunks from the build stats to selenium', (done) => {
320252
mock.reRequire('../cli/e2e')('e2e', ARGV, SKY_PAGES_CONFIG, WEBPACK);
321-
spyOn(process, 'exit').and.callFake(exitCode => {
253+
spyOn(process, 'exit').and.callFake(() => {
322254
expect(PROTRACTOR_CONFIG_ARGS.params.chunks).toEqual(CHUNKS);
323255
done();
324256
});

0 commit comments

Comments
 (0)