@@ -27,6 +27,8 @@ import { cypressEntityFiles, cypressFiles } from './files.js';
2727
2828const { ANGULAR } = clientFrameworkTypes ;
2929
30+ const WAIT_TIMEOUT = 3 * 60000 ;
31+
3032export default class CypressGenerator extends BaseApplicationGenerator {
3133 async beforeQueue ( ) {
3234 if ( ! this . fromBlueprint ) {
@@ -188,18 +190,32 @@ export default class CypressGenerator extends BaseApplicationGenerator {
188190 } ,
189191
190192 configure ( { application } ) {
193+ const { clientFrameworkAngular, devServerPort, devServerPortProxy : devServerPortE2e = devServerPort } = application ;
194+
191195 const clientPackageJson = this . createStorage ( this . destinationPath ( application . clientRootDir ! , 'package.json' ) ) ;
192196 clientPackageJson . merge ( {
193197 devDependencies : {
194198 'eslint-plugin-cypress' : application . nodeDependencies [ 'eslint-plugin-cypress' ] ,
195199 } ,
196200 scripts : {
197- e2e : 'npm run e2e:cypress:headed -- ',
198- 'e2e:headless ' : 'npm run e2e:cypress --' ,
199- 'e2e: cypress:headed' : 'npm run e2e: cypress -- --headed ',
201+ 'ci: e2e:run' : 'concurrently -k -s first -n application, e2e -c red,blue npm:ci:e2e:server:start npm:e2e:headless ',
202+ 'ci: e2e:dev ' : `concurrently -k -s first -n application, e2e -c red,blue npm:app:start npm:e2e:headless` ,
203+ cypress : ' cypress open --e2e ',
200204 'e2e:cypress' : 'cypress run --e2e --browser chrome' ,
205+ 'e2e:cypress:headed' : 'npm run e2e:cypress -- --headed' ,
201206 'e2e:cypress:record' : 'npm run e2e:cypress -- --record' ,
202- cypress : 'cypress open --e2e' ,
207+ 'e2e:dev' : `concurrently -k -s first -n application,e2e -c red,blue npm:app:start npm:e2e` ,
208+ 'pree2e:headless' : 'npm run ci:server:await' ,
209+ 'e2e:headless' : 'npm run e2e:cypress --' ,
210+ ...( clientFrameworkAngular
211+ ? {
212+ e2e : 'ng e2e' ,
213+ 'e2e:devserver' : `concurrently -k -s first -n backend,e2e -c red,blue npm:backend:start npm:start npm:e2e` ,
214+ }
215+ : {
216+ e2e : 'npm run e2e:cypress:headed --' ,
217+ 'e2e:devserver' : `concurrently -k -s first -n backend,frontend,e2e -c red,yellow,blue npm:backend:start npm:start "wait-on -t ${ WAIT_TIMEOUT } http-get://127.0.0.1:${ devServerPortE2e } && npm run e2e:headless -- -c baseUrl=http://localhost:${ devServerPortE2e } "` ,
218+ } ) ,
203219 } ,
204220 } ) ;
205221 } ,
@@ -220,7 +236,7 @@ export default class CypressGenerator extends BaseApplicationGenerator {
220236 } ) ;
221237 } ,
222238 configureCoverage ( { application, source } ) {
223- const { cypressCoverage, clientFrameworkAngular, dasherizedBaseName } = application ;
239+ const { cypressCoverage, clientFrameworkAngular, clientRootDir , dasherizedBaseName } = application ;
224240 if ( ! cypressCoverage ) return ;
225241 const clientPackageJson = this . createStorage ( this . destinationPath ( application . clientRootDir ! , 'package.json' ) ) ;
226242 clientPackageJson . merge ( {
@@ -241,7 +257,10 @@ export default class CypressGenerator extends BaseApplicationGenerator {
241257 } ) ;
242258 if ( clientFrameworkAngular ) {
243259 // Add 'ng build --configuration instrumenter' support
244- this . createStorage ( 'angular.json' ) . setPath ( `projects.${ dasherizedBaseName } .architect.build.configurations.instrumenter` , { } ) ;
260+ this . createStorage ( `${ clientRootDir } angular.json` ) . setPath (
261+ `projects.${ dasherizedBaseName } .architect.build.configurations.instrumenter` ,
262+ { } ,
263+ ) ;
245264 source . addWebpackConfig ?.( {
246265 config : `targetOptions.configuration === 'instrumenter'
247266 ? {
@@ -268,6 +287,61 @@ export default class CypressGenerator extends BaseApplicationGenerator {
268287 } ) ;
269288 }
270289 } ,
290+ cypressSchematics ( { application, source } ) {
291+ const { clientFrameworkAngular, dasherizedBaseName, cypressCoverage, clientRootDir } = application ;
292+ if ( ! clientFrameworkAngular ) return ;
293+
294+ source . mergeClientPackageJson ?.( {
295+ devDependencies : {
296+ '@cypress/schematic' : null ,
297+ } ,
298+ } ) ;
299+ this . mergeDestinationJson ( `${ clientRootDir } angular.json` , {
300+ projects : {
301+ [ application . dasherizedBaseName ] : {
302+ e2e : {
303+ builder : '@cypress/schematic:cypress' ,
304+ options : {
305+ devServerTarget : `${ dasherizedBaseName } :serve` ,
306+ watch : false ,
307+ headed : true ,
308+ browser : 'chrome' ,
309+ } ,
310+ configurations : {
311+ production : {
312+ devServerTarget : `${ dasherizedBaseName } :serve:production` ,
313+ } ,
314+ } ,
315+ } ,
316+ 'cypress-headless' : {
317+ builder : '@cypress/schematic:cypress' ,
318+ options : {
319+ devServerTarget : `${ dasherizedBaseName } :serve` ,
320+ browser : 'chrome' ,
321+ } ,
322+ configurations : {
323+ production : {
324+ devServerTarget : `${ dasherizedBaseName } :serve:production` ,
325+ } ,
326+ } ,
327+ } ,
328+ 'cypress-open' : {
329+ builder : '@cypress/schematic:cypress' ,
330+ options : {
331+ devServerTarget : `${ dasherizedBaseName } :serve` ,
332+ watch : true ,
333+ headless : false ,
334+ } ,
335+ configurations : {
336+ production : {
337+ devServerTarget : `${ dasherizedBaseName } :serve:production` ,
338+ } ,
339+ } ,
340+ } ,
341+ } ,
342+ } ,
343+ } ) ;
344+ } ,
271345 } ) ;
272346 }
273347
0 commit comments