Skip to content

Commit 78e18c0

Browse files
committed
test(@angular/cli): minimize project changes during E2E project CI setup
This change removes the attempted addition of the `karma-chrome-launcher` package which is already present in new projects. The karma configuration custom launcher section is also no longer added and instead `ChromeHeadless` is configured as the default browser which removes the need to modify the Angular workspace configuration to add the custom browser launcher.
1 parent dbce2a3 commit 78e18c0

File tree

3 files changed

+38
-48
lines changed

3 files changed

+38
-48
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export default function() {
77
return ng('generate', 'application', 'app2')
88
.then(() => expectFileToMatch('angular.json', /\"app2\":/))
99
.then(() => useCIChrome('projects/app2'))
10-
.then(() => ng('test', 'app2', '--watch=false', '--browsers=ChromeHeadlessCI'));
10+
.then(() => ng('test', 'app2', '--watch=false'));
1111
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export default function () {
77
.then(() => expectFileToMatch('angular.json', /\"my-lib\":/))
88
.then(() => useCIChrome('projects/my-lib'))
99
.then(() => ng('build', 'my-lib'))
10-
.then(() => ng('test', 'my-lib', '--watch=false', '--browsers=ChromeHeadlessCI'));
10+
.then(() => ng('test', 'my-lib', '--watch=false'));
1111
}

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

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as fs from 'fs';
2+
import * as path from 'path';
23
import { prerelease } from 'semver';
34
import { packages } from '../../../../lib/packages';
45
import { getGlobalVariable } from './env';
56
import { prependToFile, readFile, replaceInFile, writeFile } from './fs';
67
import { gitCommit } from './git';
78
import { installWorkspacePackages } from './packages';
8-
import { execAndWaitForOutputToMatch, git, ng, npm } from './process';
9+
import { execAndWaitForOutputToMatch, git, ng } from './process';
910

1011
const tsConfigPath = 'tsconfig.json';
1112

@@ -229,8 +230,6 @@ export function useCIDefaults(projectName = 'test-project') {
229230
const appTargets = project.targets || project.architect;
230231
appTargets.build.options.progress = false;
231232
appTargets.test.options.progress = false;
232-
// Use the CI chrome setup in karma.
233-
appTargets.test.options.browsers = 'ChromeHeadlessCI';
234233
// Disable auto-updating webdriver in e2e.
235234
if (appTargets.e2e) {
236235
appTargets.e2e.options.webdriverUpdate = false;
@@ -245,52 +244,43 @@ export function useCIDefaults(projectName = 'test-project') {
245244
});
246245
}
247246

248-
export function useCIChrome(projectDir: string) {
249-
const dir = projectDir ? projectDir + '/' : '';
250-
const protractorConf = `${dir}protractor.conf.js`;
251-
const karmaConf = `${dir}karma.conf.js`;
247+
export async function useCIChrome(projectDir: string = ''): Promise<void> {
248+
const protractorConf = path.join(projectDir, 'protractor.conf.js');
249+
const karmaConf = path.join(projectDir, 'karma.conf.js');
252250

253251
const chromePath = require('puppeteer').executablePath();
254-
const chromeDriverPath = require('webdriver-manager/selenium/update-config.json').chrome.last;
252+
const protractorPath = require.resolve('protractor');
253+
const webdriverUpdatePath = require.resolve('webdriver-manager/selenium/update-config.json', {
254+
paths: [protractorPath],
255+
});
256+
const webdriverUpdate = JSON.parse(await readFile(webdriverUpdatePath)) as {
257+
chrome: { last: string };
258+
};
259+
const chromeDriverPath = webdriverUpdate.chrome.last;
255260

256-
return Promise.resolve()
257-
.then(() => updateJsonFile('package.json', json => {
258-
json['devDependencies']['karma-chrome-launcher'] = '~3.1.0';
259-
}))
260-
// Use Pupeteer in protractor if a config is found on the project.
261-
.then(async () => {
262-
if (fs.existsSync(protractorConf)) {
263-
await replaceInFile(protractorConf,
264-
`browserName: 'chrome'`,
265-
`browserName: 'chrome',
266-
chromeOptions: {
267-
args: ['--headless'],
268-
binary: String.raw\`${chromePath}\`,
269-
}
270-
`);
271-
await replaceInFile(
272-
protractorConf,
273-
'directConnect: true,',
274-
`directConnect: true, chromeDriver: String.raw\`${chromeDriverPath}\`,`,
275-
);
276-
}
277-
})
278-
// Use Pupeteer in karma if a config is found on the project.
279-
.then(() => {
280-
if (fs.existsSync(karmaConf)) {
281-
return prependToFile(karmaConf,
282-
`process.env.CHROME_BIN = String.raw\`${chromePath}\`;`)
283-
.then(() => replaceInFile(karmaConf,
284-
`browsers: ['Chrome']`,
285-
`browsers: ['Chrome'],
286-
customLaunchers: {
287-
ChromeHeadlessCI: {
288-
base: 'ChromeHeadless',
289-
}
290-
}
291-
`));
292-
}
293-
});
261+
// Use Puppeteer in protractor if a config is found on the project.
262+
if (fs.existsSync(protractorConf)) {
263+
await replaceInFile(
264+
protractorConf,
265+
`browserName: 'chrome'`,
266+
`browserName: 'chrome',
267+
chromeOptions: {
268+
args: ['--headless'],
269+
binary: String.raw\`${chromePath}\`,
270+
}`,
271+
);
272+
await replaceInFile(
273+
protractorConf,
274+
'directConnect: true,',
275+
`directConnect: true, chromeDriver: String.raw\`${chromeDriverPath}\`,`,
276+
);
277+
}
278+
279+
// Use Puppeteer in karma if a config is found on the project.
280+
if (fs.existsSync(karmaConf)) {
281+
await prependToFile(karmaConf, `process.env.CHROME_BIN = String.raw\`${chromePath}\`;`);
282+
await replaceInFile(karmaConf, `browsers: ['Chrome']`, `browsers: ['ChromeHeadless']`);
283+
}
294284
}
295285

296286
export async function isPrereleaseCli() {

0 commit comments

Comments
 (0)