|
1 |
| -import { readFile, writeFile, replaceInFile } from './fs'; |
| 1 | +import * as fs from 'fs-extra'; |
| 2 | +import { readFile, writeFile, replaceInFile, prependToFile } from './fs'; |
2 | 3 | import { execAndWaitForOutputToMatch, npm, silentNpm, ng } from './process';
|
3 | 4 | import { getGlobalVariable } from './env';
|
4 | 5 |
|
@@ -186,58 +187,61 @@ export function useCIDefaults(projectName = 'test-project') {
|
186 | 187 | const appTargets = project.targets || project.architect;
|
187 | 188 | appTargets.build.options.progress = false;
|
188 | 189 | appTargets.test.options.progress = false;
|
| 190 | + // Use the CI chrome setup in karma. |
| 191 | + appTargets.test.options.browsers = 'ChromeHeadlessCI'; |
189 | 192 | // Disable auto-updating webdriver in e2e.
|
190 | 193 | const e2eProject = workspaceJson.projects[projectName + '-e2e'];
|
191 | 194 | const e2eTargets = e2eProject.targets || e2eProject.architect;
|
192 | 195 | e2eTargets.e2e.options.webdriverUpdate = false;
|
193 | 196 | })
|
194 | 197 | .then(() => updateJsonFile('package.json', json => {
|
195 |
| - // We want to always use the same version of webdriver but can only do so on CircleCI. |
196 |
| - // Appveyor and Travis will use latest Chrome stable. |
197 |
| - // CircleCI (via ngcontainer:0.1.1) uses Chrome 63.0.3239.84. |
198 |
| - // Appveyor (via chocolatey) cannot use older versions of Chrome at all: |
199 |
| - // https://github.com/chocolatey/chocolatey-coreteampackages/tree/master/automatic/googlechrome |
200 |
| - // webdriver 2.33 matches Chrome 63.0.3239.84. |
201 |
| - // webdriver 2.37 matches Chrome 65.0.3325.18100 (latest stable). |
202 |
| - // The webdriver versions for latest stable will need to be manually updated. |
203 |
| - const webdriverVersion = process.env['CIRCLECI'] ? '2.33' : '2.37'; |
204 |
| - const driverOption = process.env['CHROMEDRIVER_VERSION_ARG'] |
205 |
| - || `--versions.chrome ${webdriverVersion}`; |
| 198 | + // Use matching versions of Chrome and Webdriver. |
206 | 199 | json['scripts']['webdriver-update'] = 'webdriver-manager update' +
|
207 |
| - ` --standalone false --gecko false ${driverOption}`; |
| 200 | + ` --standalone false --gecko false --versions.chrome 2.45`; // Supports Chrome v70-72 |
| 201 | + |
208 | 202 | }))
|
209 | 203 | .then(() => npm('run', 'webdriver-update'));
|
210 | 204 | }
|
211 | 205 |
|
212 | 206 | export function useCIChrome(projectDir: string) {
|
213 |
| - // There's a race condition happening in Chrome. Enabling logging in chrome used by |
214 |
| - // protractor actually fixes it. Logging is piped to a file so it doesn't affect our setup. |
215 |
| - // --no-sandbox is needed for Circle CI. |
216 |
| - // Travis can use headless chrome, but not appveyor. |
| 207 | + const protractorConf = `${projectDir}/protractor.conf.js`; |
| 208 | + const karmaConf = `${projectDir}/karma.conf.js`; |
| 209 | + |
217 | 210 | return Promise.resolve()
|
218 |
| - .then(() => replaceInFile(`${projectDir}/protractor.conf.js`, |
219 |
| - `'browserName': 'chrome'`, |
220 |
| - `'browserName': 'chrome', |
221 |
| - chromeOptions: { |
222 |
| - args: [ |
223 |
| - "--enable-logging", |
224 |
| - // "--no-sandbox", |
225 |
| - // "--headless" |
226 |
| - ] |
227 |
| - } |
228 |
| - `)) |
229 |
| - // Not a problem if the file can't be found. |
230 |
| - // .catch(() => null) |
231 |
| - // .then(() => replaceInFile(`${projectDir}/karma.conf.js`, `browsers: ['Chrome'],`, |
232 |
| - // `browsers: ['ChromeCI'], |
233 |
| - // customLaunchers: { |
234 |
| - // ChromeCI: { |
235 |
| - // base: 'ChromeHeadless', |
236 |
| - // flags: ['--no-sandbox'] |
237 |
| - // } |
238 |
| - // }, |
239 |
| - // `)) |
240 |
| - .catch(() => null); |
| 211 | + .then(() => updateJsonFile('package.json', json => { |
| 212 | + // Use matching versions of Chrome and Webdriver. |
| 213 | + json['devDependencies']['puppeteer'] = '1.11.0'; // Chromium 72.0.3618.0 (r609904) |
| 214 | + json['devDependencies']['karma-chrome-launcher'] = '~2.2.0'; // Minimum for ChromeHeadless. |
| 215 | + })) |
| 216 | + // Use Pupeteer in protractor if a config is found on the project. |
| 217 | + .then(() => { |
| 218 | + if (fs.existsSync(protractorConf)) { |
| 219 | + return replaceInFile(protractorConf, |
| 220 | + `'browserName': 'chrome'`, |
| 221 | + `'browserName': 'chrome', |
| 222 | + chromeOptions: { |
| 223 | + args: ['--headless'], |
| 224 | + binary: require('puppeteer').executablePath() |
| 225 | + } |
| 226 | + `); |
| 227 | + } |
| 228 | + }) |
| 229 | + // Use Pupeteer in karma if a config is found on the project. |
| 230 | + .then(() => { |
| 231 | + if (fs.existsSync(karmaConf)) { |
| 232 | + return prependToFile(karmaConf, |
| 233 | + `process.env.CHROME_BIN = require('puppeteer').executablePath();`) |
| 234 | + .then(() => replaceInFile(karmaConf, |
| 235 | + `browsers: ['Chrome']`, |
| 236 | + `browsers: ['Chrome'], |
| 237 | + customLaunchers: { |
| 238 | + ChromeHeadlessCI: { |
| 239 | + base: 'ChromeHeadless', |
| 240 | + } |
| 241 | + } |
| 242 | + `)); |
| 243 | + } |
| 244 | + }); |
241 | 245 | }
|
242 | 246 |
|
243 | 247 | // Convert a Angular 5 project to Angular 2.
|
|
0 commit comments