jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.55k stars 4.02k forks source link

Generator failing with Cypress #17497

Closed roh0sun closed 2 years ago

roh0sun commented 2 years ago
Overview of the issue

Generator fails when JWT, Cypress is selected.

Motivation for or Use Case

Can't apply 7.5.0 version to existing projects with Cypress.

Reproduce the error
Welcome to JHipster v7.5.0
Application files will be generated in folder: /Users/youngseon/temp/vue-cypress
 _______________________________________________________________________________________________________________

  Documentation for creating an application is at https://www.jhipster.tech/creating-an-app/
  If you find JHipster useful, consider sponsoring the project at https://opencollective.com/generator-jhipster
 _______________________________________________________________________________________________________________

? Which *type* of application would you like to create? Monolithic application (recommended for simple projects)
? What is the base name of your application? jhipster
? Do you want to make it reactive with Spring WebFlux? No
? What is your default Java package name? com.mycompany.myapp
? Which *type* of authentication would you like to use? JWT authentication (stateless, with a token)
? Which *type* of database would you like to use? SQL (H2, PostgreSQL, MySQL, MariaDB, Oracle, MSSQL)
? Which *production* database would you like to use? PostgreSQL
? Which *development* database would you like to use? H2 with disk-based persistence
? Which cache do you want to use? (Spring cache abstraction) Ehcache (local cache, for a single node)
? Do you want to use Hibernate 2nd level cache? Yes
? Would you like to use Maven or Gradle for building the backend? Maven
? Do you want to use the JHipster Registry to configure, monitor and scale your application? No
? Which other technologies would you like to use? 
? Which *Framework* would you like to use for the client? Angular
? Do you want to generate the admin UI? Yes
? Would you like to use a Bootswatch theme (https://bootswatch.com/)? Default JHipster
? Would you like to enable internationalization support? Yes
? Please choose the native language of the application English
? Please choose additional languages to install 
? Besides JUnit and Jest, which testing frameworks would you like to use? Cypress
? Would you like to install other generators from the JHipster Marketplace? No
? Would you like to generate code coverage for Cypress tests? [Experimental] No

KeyStore '/Users/youngseon/temp/vue-cypress/src/main/resources/config/tls//keystore.p12' already exists. Leaving unchanged.

WARNING! /Users/youngseon/jhipster/generator-jhipster/generators/cypress/templates/src/test/javascript/cypress/integration/account/register-page.spec.ts.ejs
ERROR! /Users/youngseon/jhipster/generator-jhipster/generators/cypress/templates/src/test/javascript/cypress/integration/account/register-page.spec.ts.ejs:42
    40|     cy.visit('');
    41|     cy.clickOnRegisterItem();
 >> 42|     cy.url().should('match', /<%= registerPage.replaceAll('/', '\\/') %>$/);
    43|   });
    44| 
    45|   it('should load the register page', () => {

registerPage.replaceAll is not a function
TypeError: /Users/youngseon/jhipster/generator-jhipster/generators/cypress/templates/src/test/javascript/cypress/integration/account/register-page.spec.ts.ejs:42
    40|     cy.visit('');
    41|     cy.clickOnRegisterItem();
 >> 42|     cy.url().should('match', /<%= registerPage.replaceAll('/', '\\/') %>$/);
    43|   });
    44| 
    45|   it('should load the register page', () => {

registerPage.replaceAll is not a function
    at module.exports.eval (eval at compile (/Users/youngseon/jhipster/generator-jhipster/node_modules/ejs/lib/ejs.js:662:12), <anonymous>:22:39)
    at register-page.spec.ts (/Users/youngseon/jhipster/generator-jhipster/node_modules/ejs/lib/ejs.js:692:17)
    at /Users/youngseon/jhipster/generator-jhipster/node_modules/ejs/lib/ejs.js:258:40
    at new Promise (<anonymous>)
    at tryHandleCache (/Users/youngseon/jhipster/generator-jhipster/node_modules/ejs/lib/ejs.js:256:14)
    at Object.exports.renderFile (/Users/youngseon/jhipster/generator-jhipster/node_modules/ejs/lib/ejs.js:489:10)
    at Object.renderContent (/Users/youngseon/jhipster/generator-jhipster/generators/utils.js:305:23)
    at module.exports.template (/Users/youngseon/jhipster/generator-jhipster/generators/generator-base-private.js:738:8)
    at /Users/youngseon/jhipster/generator-jhipster/generators/generator-base.js:2268:47
    at Array.map (<anonymous>)
    at /Users/youngseon/jhipster/generator-jhipster/generators/generator-base.js:2184:42
    at Array.map (<anonymous>)
    at /Users/youngseon/jhipster/generator-jhipster/generators/generator-base.js:2181:29
    at Array.map (<anonymous>)
    at module.exports.writeFilesToDisk (/Users/youngseon/jhipster/generator-jhipster/generators/generator-base.js:2180:45)
    at module.exports.writeFiles (/Users/youngseon/jhipster/generator-jhipster/generators/cypress/files.js:89:19) {
  path: '/Users/youngseon/jhipster/generator-jhipster/generators/cypress/templates/src/test/javascript/cypress/integration/account/register-page.spec.ts.ejs'
}
Suggest a Fix

Could be fixed like below?

/generator-jhipster/generators/cypress/templates/src/test/javascript/cypress/integration/account/register-page.spec.ts.ejs

line 42:
   cy.url().should('match', /<%= clientFrameworkVue ? '\\/register' : '\\/account\\/register' %>$/);
JHipster Version(s)

7.5.0

Browsers and Operating System

MacOS 11.6

mshima commented 2 years ago

That’s odd the variable is there: https://github.com/jhipster/generator-jhipster/blob/587d7e014bae6b0e017ff8d55c6549858c3a5082/generators/cypress/templates/src/test/javascript/cypress/integration/account/register-page.spec.ts.ejs#L29-L33

mshima commented 2 years ago

Ought it’s a node 16 only function. https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll need to replace it for node >=12.20 compatibility.