Skip to content

Commit

Permalink
cypress: adjust scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Dec 12, 2024
1 parent 9f1f453 commit 150984b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
23 changes: 17 additions & 6 deletions generators/cypress/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { cypressEntityFiles, cypressFiles } from './files.js';

const { ANGULAR } = clientFrameworkTypes;

const WAIT_TIMEOUT = 3 * 60000;

export default class CypressGenerator extends BaseApplicationGenerator {
async beforeQueue() {
if (!this.fromBlueprint) {
Expand Down Expand Up @@ -188,22 +190,28 @@ export default class CypressGenerator extends BaseApplicationGenerator {
},

configure({ application }) {
const { devServerPort, devServerPortProxy: devServerPortE2e = devServerPort } = application;

const clientPackageJson = this.createStorage(this.destinationPath(application.clientRootDir!, 'package.json'));
clientPackageJson.merge({
devDependencies: {
'eslint-plugin-cypress': application.nodeDependencies['eslint-plugin-cypress'],
},
scripts: {
'ci:e2e:run': 'concurrently -k -s first -n application,e2e -c red,blue npm:ci:e2e:server:start npm:e2e:headless',
'ci:e2e:dev': `concurrently -k -s first -n application,e2e -c red,blue npm:app:start npm:e2e:headless`,
cypress: 'cypress open --e2e',
e2e: 'npm run e2e:cypress:headed --',
'e2e:headless': 'npm run e2e:cypress --',
'e2e:cypress:headed': 'npm run e2e:cypress -- --headed',
'e2e:cypress': 'cypress run --e2e --browser chrome',
'e2e:cypress:headed': 'npm run e2e:cypress -- --headed',
'e2e:cypress:record': 'npm run e2e:cypress -- --record',
cypress: 'cypress open --e2e',
'e2e:dev': `concurrently -k -s first -n application,e2e -c red,blue npm:app:start npm:e2e`,
'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}"`,
'pree2e:headless': 'npm run ci:server:await',
'e2e:headless': 'npm run e2e:cypress --',
},
});
},

configureAudits({ application }) {
if (!application.cypressAudit) return;
const clientPackageJson = this.createStorage(this.destinationPath(application.clientRootDir!, 'package.json'));
Expand All @@ -220,7 +228,7 @@ export default class CypressGenerator extends BaseApplicationGenerator {
});
},
configureCoverage({ application, source }) {
const { cypressCoverage, clientFrameworkAngular, dasherizedBaseName } = application;
const { cypressCoverage, clientFrameworkAngular, clientRootDir, dasherizedBaseName } = application;
if (!cypressCoverage) return;
const clientPackageJson = this.createStorage(this.destinationPath(application.clientRootDir!, 'package.json'));
clientPackageJson.merge({
Expand All @@ -241,7 +249,10 @@ export default class CypressGenerator extends BaseApplicationGenerator {
});
if (clientFrameworkAngular) {
// Add 'ng build --configuration instrumenter' support
this.createStorage('angular.json').setPath(`projects.${dasherizedBaseName}.architect.build.configurations.instrumenter`, {});
this.createStorage(`${clientRootDir}angular.json`).setPath(
`projects.${dasherizedBaseName}.architect.build.configurations.instrumenter`,
{},
);
source.addWebpackConfig?.({
config: `targetOptions.configuration === 'instrumenter'
? {
Expand Down
13 changes: 0 additions & 13 deletions generators/java/generators/server/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ export default class ServerGenerator extends BaseApplicationGenerator {
});
},
packageJsonE2eScripts({ application }) {
const { devServerPort, devServerPortProxy: devServerPortE2e = devServerPort } = application;
const scriptsStorage = this.packageJson.createStorage('scripts');
const buildCmd = application.buildToolGradle ? 'gradlew' : 'mvnw -ntp';

let applicationWaitTimeout = WAIT_TIMEOUT * (application.applicationTypeGateway ? 2 : 1);
applicationWaitTimeout = application.authenticationTypeOauth2 ? applicationWaitTimeout * 2 : applicationWaitTimeout;
Expand All @@ -110,17 +108,6 @@ export default class ServerGenerator extends BaseApplicationGenerator {
scriptsStorage.set({
'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"`,
});

// TODO add e2eTests property to application.
if (this.jhipsterConfig.testFrameworks?.includes('cypress')) {
scriptsStorage.set({
'pree2e:headless': 'npm run ci:server:await',
'ci:e2e:run': 'concurrently -k -s first -n application,e2e -c red,blue npm:ci:e2e:server:start npm:e2e:headless',
'ci:e2e:dev': `concurrently -k -s first -n application,e2e -c red,blue "./${buildCmd}" npm:e2e:headless`,
'e2e:dev': `concurrently -k -s first -n application,e2e -c red,blue "./${buildCmd}" npm:e2e`,
'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}"`,
});
}
},
});
}
Expand Down

0 comments on commit 150984b

Please sign in to comment.