11import express from 'express' ;
22import * as path from 'node:path' ;
33import { copyProjectAsset } from '../../utils/assets' ;
4- import { replaceInFile } from '../../utils/fs' ;
4+ import { appendToFile , createDir , replaceInFile , writeFile } from '../../utils/fs' ;
55import { ng } from '../../utils/process' ;
6+ import { installPackage } from '../../utils/packages' ;
7+ import { updateJsonFile } from '../../utils/project' ;
8+
9+ /**
10+ * The list of development dependencies used by the E2E protractor-based builder.
11+ */
12+ const E2E_DEV_DEPENDENCIES = [
13+ 'protractor@~7.0.0' ,
14+ 'jasmine-spec-reporter@~7.0.0' ,
15+ 'ts-node@~10.9.0' ,
16+ '@types/node@^20.17.19' ,
17+ ] ;
618
719export default async function ( ) {
820 // Ensure SauceLabs configuration
921 if ( ! process . env [ 'SAUCE_USERNAME' ] || ! process . env [ 'SAUCE_ACCESS_KEY' ] ) {
1022 throw new Error ( 'SauceLabs is not configured.' ) ;
1123 }
1224
13- await ng ( 'generate' , 'private-e2e' , '--related-app-name' , 'test-project' ) ;
25+ for ( const e2eDep of E2E_DEV_DEPENDENCIES ) {
26+ await installPackage ( e2eDep ) ;
27+ }
28+
29+ // Setup `protractor` builder.
30+ await updateJsonFile ( 'angular.json' , ( config ) => {
31+ config . projects [ 'test-project' ] . architect [ 'e2e' ] = {
32+ builder : '@angular-devkit/build-angular:protractor' ,
33+ options : {
34+ devServerTarget : '' ,
35+ protractorConfig : 'e2e/protractor-saucelabs.conf.js' ,
36+ } ,
37+ } ;
38+ } ) ;
39+
40+ await appendToFile (
41+ 'src/app/app.config.ts' ,
42+ "import { provideProtractorTestingSupport } from '@angular/platform-browser';\n" ,
43+ ) ;
44+ await replaceInFile (
45+ 'src/app/app.config.ts' ,
46+ 'providers: [' ,
47+ 'providers: [\n provideProtractorTestingSupport,\n' ,
48+ ) ;
1449
1550 // Workaround for https://github.com/angular/angular/issues/32192
1651 await replaceInFile ( 'src/app/app.html' , / c l a s s = " m a t e r i a l - i c o n s " / g, '' ) ;
@@ -20,19 +55,39 @@ export default async function () {
2055 // Add Protractor configuration
2156 await copyProjectAsset ( 'protractor-saucelabs.conf.js' , 'e2e/protractor-saucelabs.conf.js' ) ;
2257
23- // Remove browser log checks as they are only supported with the chrome webdriver
24- await replaceInFile (
58+ // Add App E2E test file
59+ await createDir ( 'e2e/src' ) ;
60+ await writeFile (
2561 'e2e/src/app.e2e-spec.ts' ,
26- 'await browser.manage().logs().get(logging.Type.BROWSER)' ,
27- '[] as any' ,
62+ `
63+ import { browser, by, element, logging } from 'protractor';
64+
65+ describe('workspace-project App', () => {
66+ it('should display welcome message', async () => {
67+ await browser.get(browser.baseUrl);
68+ expect((await element(by.css('h1')).getText()).trim()).toEqual('Hello, test-project');
69+ });
70+ });
71+ ` ,
2872 ) ;
2973
30- // Workaround defect in getText WebDriver implementation for Safari/Edge
31- // Leading and trailing space is not removed
32- await replaceInFile (
33- 'e2e/src/app.e2e-spec.ts' ,
34- 'await page.getTitleText()' ,
35- '(await page.getTitleText()).trim()' ,
74+ // Add App E2E tsconfig file
75+ await writeFile (
76+ 'e2e/tsconfig.json' ,
77+ `
78+ {
79+ "extends": "../tsconfig.json",
80+ "compilerOptions": {
81+ "outDir": "out-tsc/e2e",
82+ "module": "commonjs",
83+ "target": "es2019",
84+ "types": [
85+ "jasmine",
86+ "node"
87+ ]
88+ }
89+ }
90+ ` ,
3691 ) ;
3792
3893 // Setup server
0 commit comments