Skip to content

Commit 3b90e5e

Browse files
committed
cypress: add @cypress/schematic for angular
1 parent 8c6f863 commit 3b90e5e

File tree

5 files changed

+100
-21
lines changed

5 files changed

+100
-21
lines changed

generators/app/__snapshots__/generator.spec.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
650650
"@angular/cli": "ANGULAR_CLI_VERSION",
651651
"@angular/common": "ANGULAR_COMMON_VERSION",
652652
"@cypress/code-coverage": "CYPRESS_CODE_COVERAGE_VERSION",
653+
"@cypress/schematic": "CYPRESS_SCHEMATIC_VERSION",
653654
"@eslint/js": "ESLINT_JS_VERSION",
654655
"@fortawesome/angular-fontawesome": "FORTAWESOME_ANGULAR_FONTAWESOME_VERSION",
655656
"@fortawesome/fontawesome-svg-core": "FORTAWESOME_FONTAWESOME_SVG_CORE_VERSION",
@@ -1312,6 +1313,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
13121313
"@angular/cli": "ANGULAR_CLI_VERSION",
13131314
"@angular/common": "ANGULAR_COMMON_VERSION",
13141315
"@cypress/code-coverage": "CYPRESS_CODE_COVERAGE_VERSION",
1316+
"@cypress/schematic": "CYPRESS_SCHEMATIC_VERSION",
13151317
"@eslint/js": "ESLINT_JS_VERSION",
13161318
"@fortawesome/angular-fontawesome": "FORTAWESOME_ANGULAR_FONTAWESOME_VERSION",
13171319
"@fortawesome/fontawesome-svg-core": "FORTAWESOME_FONTAWESOME_SVG_CORE_VERSION",

generators/client/resources/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
},
55
"devDependencies": {
66
"@cypress/code-coverage": "3.13.9",
7+
"@cypress/schematic": "2.5.1",
78
"babel-loader": "9.2.1",
89
"babel-plugin-istanbul": "7.0.0",
910
"cypress": "13.16.1",

generators/cypress/__snapshots__/generator.spec.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ exports[`generator - cypress jwt-cypressAudit(false)-angular-withAdminUi(false)-
88
".yo-rc.json": {
99
"stateCleared": "modified",
1010
},
11+
"clientRoot/angular.json": {
12+
"stateCleared": "modified",
13+
},
1114
"clientRoot/cypress.config.ts": {
1215
"stateCleared": "modified",
1316
},
@@ -68,6 +71,9 @@ exports[`generator - cypress jwt-cypressAudit(false)-angular-withAdminUi(false)-
6871
"clientRoot/test/cypress/tsconfig.json": {
6972
"stateCleared": "modified",
7073
},
74+
"package.json": {
75+
"stateCleared": "modified",
76+
},
7177
}
7278
`;
7379

@@ -145,6 +151,9 @@ exports[`generator - cypress jwt-cypressAudit(true)-vue-withAdminUi(true)-cypres
145151
"clientRoot/test/cypress/tsconfig.json": {
146152
"stateCleared": "modified",
147153
},
154+
"package.json": {
155+
"stateCleared": "modified",
156+
},
148157
}
149158
`;
150159

@@ -156,6 +165,9 @@ exports[`generator - cypress oauth2-cypressAudit(false)-angular-withAdminUi(fals
156165
".yo-rc.json": {
157166
"stateCleared": "modified",
158167
},
168+
"angular.json": {
169+
"stateCleared": "modified",
170+
},
159171
"cypress.config.ts": {
160172
"stateCleared": "modified",
161173
},
@@ -342,6 +354,9 @@ exports[`generator - cypress session-cypressAudit(false)-angular-withAdminUi(fal
342354
".yo-rc.json": {
343355
"stateCleared": "modified",
344356
},
357+
"angular.json": {
358+
"stateCleared": "modified",
359+
},
345360
"cypress.config.ts": {
346361
"stateCleared": "modified",
347362
},

generators/cypress/generator.ts

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import { cypressEntityFiles, cypressFiles } from './files.js';
2727

2828
const { ANGULAR } = clientFrameworkTypes;
2929

30+
const WAIT_TIMEOUT = 3 * 60000;
31+
3032
export 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

generators/java/generators/server/generator.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ export default class ServerGenerator extends BaseApplicationGenerator {
4949
if (buildTool === 'maven') {
5050
const excludeWebapp = application.skipClient ? '' : ' -Dskip.installnodenpm -Dskip.npm';
5151
scriptsStorage.set({
52-
'app:start': './mvnw',
52+
'app:start': './mvnw -ntp --batch-mode',
5353
'backend:info': './mvnw --version',
5454
'backend:doc:test': './mvnw -ntp javadoc:javadoc --batch-mode',
5555
'backend:nohttp:test': './mvnw -ntp checkstyle:check --batch-mode',
56-
'backend:start': `./mvnw${excludeWebapp}`,
56+
'backend:start': `./mvnw${excludeWebapp} -ntp --batch-mode`,
5757
'java:jar': './mvnw -ntp verify -DskipTests --batch-mode',
5858
'java:war': './mvnw -ntp verify -DskipTests --batch-mode -Pwar',
5959
'java:docker': './mvnw -ntp verify -DskipTests -Pprod jib:dockerBuild',
@@ -98,9 +98,7 @@ export default class ServerGenerator extends BaseApplicationGenerator {
9898
});
9999
},
100100
packageJsonE2eScripts({ application }) {
101-
const { devServerPort, devServerPortProxy: devServerPortE2e = devServerPort } = application;
102101
const scriptsStorage = this.packageJson.createStorage('scripts');
103-
const buildCmd = application.buildToolGradle ? 'gradlew' : 'mvnw -ntp';
104102

105103
let applicationWaitTimeout = WAIT_TIMEOUT * (application.applicationTypeGateway ? 2 : 1);
106104
applicationWaitTimeout = application.authenticationTypeOauth2 ? applicationWaitTimeout * 2 : applicationWaitTimeout;
@@ -110,17 +108,6 @@ export default class ServerGenerator extends BaseApplicationGenerator {
110108
scriptsStorage.set({
111109
'ci:server:await': `echo "Waiting for server at port $npm_package_config_backend_port to start" && wait-on -t ${applicationWaitTimeout} ${applicationEndpoint} && echo "Server at port $npm_package_config_backend_port started"`,
112110
});
113-
114-
// TODO add e2eTests property to application.
115-
if (this.jhipsterConfig.testFrameworks?.includes('cypress')) {
116-
scriptsStorage.set({
117-
'pree2e:headless': 'npm run ci:server:await',
118-
'ci:e2e:run': 'concurrently -k -s first -n application,e2e -c red,blue npm:ci:e2e:server:start npm:e2e:headless',
119-
'ci:e2e:dev': `concurrently -k -s first -n application,e2e -c red,blue "./${buildCmd}" npm:e2e:headless`,
120-
'e2e:dev': `concurrently -k -s first -n application,e2e -c red,blue "./${buildCmd}" npm:e2e`,
121-
'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}"`,
122-
});
123-
}
124111
},
125112
});
126113
}

0 commit comments

Comments
 (0)