mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 10:33:43 +08:00
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.
This commit is contained in:
parent
dbce2a3f28
commit
78e18c0047
@ -7,5 +7,5 @@ export default function() {
|
|||||||
return ng('generate', 'application', 'app2')
|
return ng('generate', 'application', 'app2')
|
||||||
.then(() => expectFileToMatch('angular.json', /\"app2\":/))
|
.then(() => expectFileToMatch('angular.json', /\"app2\":/))
|
||||||
.then(() => useCIChrome('projects/app2'))
|
.then(() => useCIChrome('projects/app2'))
|
||||||
.then(() => ng('test', 'app2', '--watch=false', '--browsers=ChromeHeadlessCI'));
|
.then(() => ng('test', 'app2', '--watch=false'));
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,5 @@ export default function () {
|
|||||||
.then(() => expectFileToMatch('angular.json', /\"my-lib\":/))
|
.then(() => expectFileToMatch('angular.json', /\"my-lib\":/))
|
||||||
.then(() => useCIChrome('projects/my-lib'))
|
.then(() => useCIChrome('projects/my-lib'))
|
||||||
.then(() => ng('build', 'my-lib'))
|
.then(() => ng('build', 'my-lib'))
|
||||||
.then(() => ng('test', 'my-lib', '--watch=false', '--browsers=ChromeHeadlessCI'));
|
.then(() => ng('test', 'my-lib', '--watch=false'));
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import * as path from 'path';
|
||||||
import { prerelease } from 'semver';
|
import { prerelease } from 'semver';
|
||||||
import { packages } from '../../../../lib/packages';
|
import { packages } from '../../../../lib/packages';
|
||||||
import { getGlobalVariable } from './env';
|
import { getGlobalVariable } from './env';
|
||||||
import { prependToFile, readFile, replaceInFile, writeFile } from './fs';
|
import { prependToFile, readFile, replaceInFile, writeFile } from './fs';
|
||||||
import { gitCommit } from './git';
|
import { gitCommit } from './git';
|
||||||
import { installWorkspacePackages } from './packages';
|
import { installWorkspacePackages } from './packages';
|
||||||
import { execAndWaitForOutputToMatch, git, ng, npm } from './process';
|
import { execAndWaitForOutputToMatch, git, ng } from './process';
|
||||||
|
|
||||||
const tsConfigPath = 'tsconfig.json';
|
const tsConfigPath = 'tsconfig.json';
|
||||||
|
|
||||||
@ -229,8 +230,6 @@ export function useCIDefaults(projectName = 'test-project') {
|
|||||||
const appTargets = project.targets || project.architect;
|
const appTargets = project.targets || project.architect;
|
||||||
appTargets.build.options.progress = false;
|
appTargets.build.options.progress = false;
|
||||||
appTargets.test.options.progress = false;
|
appTargets.test.options.progress = false;
|
||||||
// Use the CI chrome setup in karma.
|
|
||||||
appTargets.test.options.browsers = 'ChromeHeadlessCI';
|
|
||||||
// Disable auto-updating webdriver in e2e.
|
// Disable auto-updating webdriver in e2e.
|
||||||
if (appTargets.e2e) {
|
if (appTargets.e2e) {
|
||||||
appTargets.e2e.options.webdriverUpdate = false;
|
appTargets.e2e.options.webdriverUpdate = false;
|
||||||
@ -245,52 +244,43 @@ export function useCIDefaults(projectName = 'test-project') {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useCIChrome(projectDir: string) {
|
export async function useCIChrome(projectDir: string = ''): Promise<void> {
|
||||||
const dir = projectDir ? projectDir + '/' : '';
|
const protractorConf = path.join(projectDir, 'protractor.conf.js');
|
||||||
const protractorConf = `${dir}protractor.conf.js`;
|
const karmaConf = path.join(projectDir, 'karma.conf.js');
|
||||||
const karmaConf = `${dir}karma.conf.js`;
|
|
||||||
|
|
||||||
const chromePath = require('puppeteer').executablePath();
|
const chromePath = require('puppeteer').executablePath();
|
||||||
const chromeDriverPath = require('webdriver-manager/selenium/update-config.json').chrome.last;
|
const protractorPath = require.resolve('protractor');
|
||||||
|
const webdriverUpdatePath = require.resolve('webdriver-manager/selenium/update-config.json', {
|
||||||
|
paths: [protractorPath],
|
||||||
|
});
|
||||||
|
const webdriverUpdate = JSON.parse(await readFile(webdriverUpdatePath)) as {
|
||||||
|
chrome: { last: string };
|
||||||
|
};
|
||||||
|
const chromeDriverPath = webdriverUpdate.chrome.last;
|
||||||
|
|
||||||
return Promise.resolve()
|
// Use Puppeteer in protractor if a config is found on the project.
|
||||||
.then(() => updateJsonFile('package.json', json => {
|
if (fs.existsSync(protractorConf)) {
|
||||||
json['devDependencies']['karma-chrome-launcher'] = '~3.1.0';
|
await replaceInFile(
|
||||||
}))
|
protractorConf,
|
||||||
// Use Pupeteer in protractor if a config is found on the project.
|
`browserName: 'chrome'`,
|
||||||
.then(async () => {
|
`browserName: 'chrome',
|
||||||
if (fs.existsSync(protractorConf)) {
|
chromeOptions: {
|
||||||
await replaceInFile(protractorConf,
|
args: ['--headless'],
|
||||||
`browserName: 'chrome'`,
|
binary: String.raw\`${chromePath}\`,
|
||||||
`browserName: 'chrome',
|
}`,
|
||||||
chromeOptions: {
|
);
|
||||||
args: ['--headless'],
|
await replaceInFile(
|
||||||
binary: String.raw\`${chromePath}\`,
|
protractorConf,
|
||||||
}
|
'directConnect: true,',
|
||||||
`);
|
`directConnect: true, chromeDriver: String.raw\`${chromeDriverPath}\`,`,
|
||||||
await replaceInFile(
|
);
|
||||||
protractorConf,
|
}
|
||||||
'directConnect: true,',
|
|
||||||
`directConnect: true, chromeDriver: String.raw\`${chromeDriverPath}\`,`,
|
// Use Puppeteer in karma if a config is found on the project.
|
||||||
);
|
if (fs.existsSync(karmaConf)) {
|
||||||
}
|
await prependToFile(karmaConf, `process.env.CHROME_BIN = String.raw\`${chromePath}\`;`);
|
||||||
})
|
await replaceInFile(karmaConf, `browsers: ['Chrome']`, `browsers: ['ChromeHeadless']`);
|
||||||
// Use Pupeteer in karma if a config is found on the project.
|
}
|
||||||
.then(() => {
|
|
||||||
if (fs.existsSync(karmaConf)) {
|
|
||||||
return prependToFile(karmaConf,
|
|
||||||
`process.env.CHROME_BIN = String.raw\`${chromePath}\`;`)
|
|
||||||
.then(() => replaceInFile(karmaConf,
|
|
||||||
`browsers: ['Chrome']`,
|
|
||||||
`browsers: ['Chrome'],
|
|
||||||
customLaunchers: {
|
|
||||||
ChromeHeadlessCI: {
|
|
||||||
base: 'ChromeHeadless',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function isPrereleaseCli() {
|
export async function isPrereleaseCli() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user