Skip to content

Commit 9acbcf9

Browse files
committed
test(@angular/cli): reuse chrome/chromedriver in E2E tests
This changes the E2E test project setup to reuse the repository's existing puppeteer chrome instance and already downloaded chrome driver. Previously puppeteer was added to each E2E test project which required an additional download of both chrome and an associated chromedriver. Downloads previously needed to occur multiple times during the test process due to tests changing/removing the test project's node modules directory. (cherry picked from commit 206d62a)
1 parent d0c32bd commit 9acbcf9

File tree

3 files changed

+19
-37
lines changed

3 files changed

+19
-37
lines changed

tests/legacy-cli/e2e/tests/basic/e2e.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
// TODO(architect): edit the architect config instead of the cli config.
2-
31
import {
42
ng,
5-
npm,
63
execAndWaitForOutputToMatch,
74
killAllProcesses
85
} from '../../utils/process';
9-
import {updateJsonFile} from '../../utils/project';
106
import {expectToFail} from '../../utils/utils';
117
import {moveFile, copyFile, replaceInFile} from '../../utils/fs';
128

139
export default function () {
14-
// Should fail without updated webdriver
15-
return updateJsonFile('package.json', packageJson => {
16-
// Add to npm scripts to make running the binary compatible with Windows
17-
const scripts = packageJson['scripts'];
18-
scripts['wd:clean'] = 'webdriver-manager clean';
19-
})
20-
.then(() => npm('run', 'wd:clean'))
21-
.then(() => expectToFail(() => ng('e2e', 'test-project', '--no-webdriver-update', '--devServerTarget=')))
22-
// Add back the pre-defined version of webdriver. This script is defined when making projects.
23-
.then(() => npm('run', 'webdriver-update'))
10+
return Promise.resolve()
2411
// Should fail without serving
2512
.then(() => expectToFail(() => ng('e2e', 'test-project', '--devServerTarget=')))
2613
// These should work.
@@ -61,7 +48,10 @@ export default function () {
6148
.then(() => execAndWaitForOutputToMatch('ng', ['serve'],
6249
/: Compiled successfully./))
6350
.then(() => ng('e2e', 'test-project', '--devServerTarget='))
64-
.then(() => killAllProcesses(), (err: any) => {
51+
// Should fail without updated webdriver
52+
.then(() => replaceInFile('e2e/protractor.conf.js', /chromeDriver: String.raw`[^`]*`,/, ''))
53+
.then(() => expectToFail(() => ng('e2e', 'test-project', '--no-webdriver-update', '--devServerTarget=')))
54+
.then(() => killAllProcesses(), (err) => {
6555
killAllProcesses();
6656
throw err;
6757
});

tests/legacy-cli/e2e/tests/commands/add/add-pwa-yarn.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ export default async function () {
2020
}
2121

2222
// 'yarn' will nuke the entire node_modules when it is triggered during the above tests.
23-
// Let's restore the previous node_modules state by re-installing using 'npm'
24-
// and run 'webdriver-update'. Otherwise, we will start seeing errors in CI like:
25-
// Error: Could not find update-config.json. Run 'webdriver-manager update' to download binaries.
23+
await rimraf('node_modules');
2624
await npm('install');
27-
await npm('run', 'webdriver-update');
2825
}

tests/legacy-cli/e2e/utils/project.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,49 +245,44 @@ export function useCIDefaults(projectName = 'test-project') {
245245
const e2eTargets = e2eProject.targets || e2eProject.architect;
246246
e2eTargets.e2e.options.webdriverUpdate = false;
247247
}
248-
})
249-
.then(() => updateJsonFile('package.json', json => {
250-
// Use matching versions of Chromium and ChromeDriver.
251-
// https://github.com/GoogleChrome/puppeteer/releases
252-
// http://chromedriver.chromium.org/downloads
253-
json['scripts']['webdriver-update'] = 'webdriver-manager update' +
254-
` --standalone false --gecko false --versions.chrome 81.0.4044.0`; // Supports Chrome 81
255-
256-
}))
257-
.then(() => npm('run', 'webdriver-update'));
248+
});
258249
}
259250

260251
export function useCIChrome(projectDir: string) {
261252
const dir = projectDir ? projectDir + '/' : '';
262253
const protractorConf = `${dir}protractor.conf.js`;
263254
const karmaConf = `${dir}karma.conf.js`;
264255

256+
const chromePath = require('puppeteer').executablePath();
257+
const chromeDriverPath = require('webdriver-manager/selenium/update-config.json').chrome.last;
258+
265259
return Promise.resolve()
266260
.then(() => updateJsonFile('package.json', json => {
267-
// Use matching versions of Chromium (via puppeteer) and ChromeDriver.
268-
// https://github.com/GoogleChrome/puppeteer/releases
269-
// http://chromedriver.chromium.org/downloads
270-
json['devDependencies']['puppeteer'] = '3.0.2'; // Chromium 81.0.4044.0 (r737027)
271261
json['devDependencies']['karma-chrome-launcher'] = '~3.1.0';
272262
}))
273263
// Use Pupeteer in protractor if a config is found on the project.
274-
.then(() => {
264+
.then(async () => {
275265
if (fs.existsSync(protractorConf)) {
276-
return replaceInFile(protractorConf,
266+
await replaceInFile(protractorConf,
277267
`browserName: 'chrome'`,
278268
`browserName: 'chrome',
279269
chromeOptions: {
280270
args: ['--headless'],
281-
binary: require('puppeteer').executablePath()
271+
binary: String.raw\`${chromePath}\`,
282272
}
283273
`);
274+
await replaceInFile(
275+
protractorConf,
276+
'directConnect: true,',
277+
`directConnect: true, chromeDriver: String.raw\`${chromeDriverPath}\`,`,
278+
);
284279
}
285280
})
286281
// Use Pupeteer in karma if a config is found on the project.
287282
.then(() => {
288283
if (fs.existsSync(karmaConf)) {
289284
return prependToFile(karmaConf,
290-
`process.env.CHROME_BIN = require('puppeteer').executablePath();`)
285+
`process.env.CHROME_BIN = String.raw\`${chromePath}\`;`)
291286
.then(() => replaceInFile(karmaConf,
292287
`browsers: ['Chrome']`,
293288
`browsers: ['Chrome'],

0 commit comments

Comments
 (0)