1
1
import * as fs from 'fs' ;
2
+ import * as path from 'path' ;
2
3
import { prerelease } from 'semver' ;
3
4
import { packages } from '../../../../lib/packages' ;
4
5
import { getGlobalVariable } from './env' ;
5
6
import { prependToFile , readFile , replaceInFile , writeFile } from './fs' ;
6
7
import { gitCommit } from './git' ;
7
8
import { installWorkspacePackages } from './packages' ;
8
- import { execAndWaitForOutputToMatch , git , ng , npm } from './process' ;
9
+ import { execAndWaitForOutputToMatch , git , ng } from './process' ;
9
10
10
11
const tsConfigPath = 'tsconfig.json' ;
11
12
@@ -229,8 +230,6 @@ export function useCIDefaults(projectName = 'test-project') {
229
230
const appTargets = project . targets || project . architect ;
230
231
appTargets . build . options . progress = false ;
231
232
appTargets . test . options . progress = false ;
232
- // Use the CI chrome setup in karma.
233
- appTargets . test . options . browsers = 'ChromeHeadlessCI' ;
234
233
// Disable auto-updating webdriver in e2e.
235
234
if ( appTargets . e2e ) {
236
235
appTargets . e2e . options . webdriverUpdate = false ;
@@ -245,52 +244,43 @@ export function useCIDefaults(projectName = 'test-project') {
245
244
} ) ;
246
245
}
247
246
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' ) ;
252
250
253
251
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 ;
255
260
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
+ }
294
284
}
295
285
296
286
export async function isPrereleaseCli ( ) {
0 commit comments