Skip to content

Commit 206d62a

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.
1 parent cb32006 commit 206d62a

File tree

8 files changed

+23
-54
lines changed

8 files changed

+23
-54
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
@@ -25,9 +25,6 @@ export default async function () {
2525
}
2626

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

tests/legacy-cli/e2e/tests/generate/library/library-consumption-linker.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ export default async function () {
1212

1313
await ng('generate', 'library', 'my-lib');
1414

15-
// Ensure webdriver is present for E2E (yarn will remove any downloaded drivers)
16-
if (getActivePackageManager() === 'yarn') {
17-
await silentYarn('run', 'webdriver-update');
18-
}
19-
2015
// Enable partial compilation mode (linker) for the library
2116
// Enable ivy for production as well (current schematic disables ivy in production)
2217
await updateJsonFile('projects/my-lib/tsconfig.lib.prod.json', config => {

tests/legacy-cli/e2e/tests/misc/webpack-5.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export default async function() {
99
json.resolutions = { webpack: '5.1.3' };
1010
});
1111
await silentYarn();
12-
await silentYarn('webdriver-update');
1312

1413
// Ensure webpack 5 is used
1514
const { stdout } = await silentYarn('list', '--pattern', 'webpack');

tests/legacy-cli/e2e/tests/update/update-8.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ export default async function() {
1313
await useCIChrome('./');
1414
await useCIChrome('./e2e/');
1515
await useCIDefaults('eight-project');
16-
await installWorkspacePackages(false);
16+
await installWorkspacePackages();
1717

1818
// Update Angular.
1919
const extraUpdateArgs = await isPrereleaseCli() ? ['--next', '--force'] : [];
2020
await ng('update', '@angular/core', ...extraUpdateArgs);
21-
await silentNpm('run', 'webdriver-update');
2221

2322
// Run CLI commands.
2423
await ng('generate', 'component', 'my-comp');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function createProjectFromAsset(
5353
}
5454

5555
if (!skipInstall) {
56-
await installWorkspacePackages(false);
56+
await installWorkspacePackages();
5757
}
5858

5959
return dir;

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@ export function getActivePackageManager(): 'npm' | 'yarn' {
1010
return value || 'npm';
1111
}
1212

13-
export async function installWorkspacePackages(updateWebdriver = true): Promise<void> {
13+
export async function installWorkspacePackages(): Promise<void> {
1414
switch (getActivePackageManager()) {
1515
case 'npm':
1616
await silentNpm('install');
17-
if (updateWebdriver) {
18-
await silentNpm('run', 'webdriver-update');
19-
}
2017
break;
2118
case 'yarn':
2219
await silentYarn();
23-
if (updateWebdriver) {
24-
await silentYarn('webdriver-update');
25-
}
2620
break;
2721
}
2822
}

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

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export async function prepareProjectForE2e(name) {
9595
console.log(
9696
`Project ${name} created... Installing npm.`,
9797
);
98-
await installWorkspacePackages(false);
98+
await installWorkspacePackages();
9999
await useCIDefaults(
100100
name,
101101
);
@@ -244,49 +244,44 @@ export function useCIDefaults(projectName = 'test-project') {
244244
const e2eTargets = e2eProject.targets || e2eProject.architect;
245245
e2eTargets.e2e.options.webdriverUpdate = false;
246246
}
247-
})
248-
.then(() => updateJsonFile('package.json', json => {
249-
// Use matching versions of Chromium and ChromeDriver.
250-
// https://github.com/GoogleChrome/puppeteer/releases
251-
// http://chromedriver.chromium.org/downloads
252-
json['scripts']['webdriver-update'] = 'webdriver-manager update' +
253-
` --standalone false --gecko false --versions.chrome 89.0.4389.0`; // Supports Chrome 89
254-
255-
}))
256-
.then(() => npm('run', 'webdriver-update'));
247+
});
257248
}
258249

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

255+
const chromePath = require('puppeteer').executablePath();
256+
const chromeDriverPath = require('webdriver-manager/selenium/update-config.json').chrome.last;
257+
264258
return Promise.resolve()
265259
.then(() => updateJsonFile('package.json', json => {
266-
// Use matching versions of Chromium (via puppeteer) and ChromeDriver.
267-
// https://github.com/GoogleChrome/puppeteer/releases
268-
// http://chromedriver.chromium.org/downloads
269-
json['devDependencies']['puppeteer'] = '7.0.0'; // Chromium 89.0.4389.0 (r843427)
270260
json['devDependencies']['karma-chrome-launcher'] = '~3.1.0';
271261
}))
272262
// Use Pupeteer in protractor if a config is found on the project.
273-
.then(() => {
263+
.then(async () => {
274264
if (fs.existsSync(protractorConf)) {
275-
return replaceInFile(protractorConf,
265+
await replaceInFile(protractorConf,
276266
`browserName: 'chrome'`,
277267
`browserName: 'chrome',
278268
chromeOptions: {
279269
args: ['--headless'],
280-
binary: require('puppeteer').executablePath()
270+
binary: String.raw\`${chromePath}\`,
281271
}
282272
`);
273+
await replaceInFile(
274+
protractorConf,
275+
'directConnect: true,',
276+
`directConnect: true, chromeDriver: String.raw\`${chromeDriverPath}\`,`,
277+
);
283278
}
284279
})
285280
// Use Pupeteer in karma if a config is found on the project.
286281
.then(() => {
287282
if (fs.existsSync(karmaConf)) {
288283
return prependToFile(karmaConf,
289-
`process.env.CHROME_BIN = require('puppeteer').executablePath();`)
284+
`process.env.CHROME_BIN = String.raw\`${chromePath}\`;`)
290285
.then(() => replaceInFile(karmaConf,
291286
`browsers: ['Chrome']`,
292287
`browsers: ['Chrome'],

0 commit comments

Comments
 (0)