generator-jhipster icon indicating copy to clipboard operation
generator-jhipster copied to clipboard

Cypress tests could not be launched

Open venustulips opened this issue 4 years ago • 22 comments

Overview of the issue
PS D:\temp\jhcypress> npm run e2e

> [email protected] e2e D:\temp\jhcypress
> npm run e2e:cypress


> [email protected] e2e:cypress D:\temp\jhcypress
> cypress run --browser chrome --record ${CYPRESS_ENABLE_RECORD:-false}


You passed the --record flag but this project has not been setup to record.

This project is missing the 'projectId' inside of 'cypress.json'.

We cannot uniquely identify this project without this id.

You need to setup this project to record. This will generate a unique 'projectId'.

Alternatively if you omit the --record flag this project will run without recording.

https://on.cypress.io/recording-project-runs
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] e2e:cypress: `cypress run --browser chrome --record ${CYPRESS_ENABLE_RECORD:-false}`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] e2e:cypress script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user\AppData\Roaming\npm-cache\_logs\2021-03-14T07_43_51_176Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] e2e: `npm run e2e:cypress`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] e2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user\AppData\Roaming\npm-cache\_logs\2021-03-14T07_43_51_198Z-debug.log
PS D:\temp\jhcypress>
Motivation for or Use Case

A new application should be able to run cypress without any issue.

Reproduce the error
  1. Create an app selecting cypress
  2. Run npm run e2e
Related issues
Suggest a Fix
JHipster Version(s)
[email protected] D:\temp\jhcypress
`-- [email protected]

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "blueprints": [],
    "otherModules": [],
    "applicationType": "monolith",
    "baseName": "jhcypress",
    "jhipsterVersion": "7.0.0-beta.1",
    "skipClient": false,
    "skipServer": false,
    "skipUserManagement": false,
    "skipCheckLengthOfIdentifier": false,
    "skipFakeData": false,
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "testFrameworks": ["cypress"],
    "pages": [],
    "creationTimestamp": 1615707064549,
    "serviceDiscoveryType": false,
    "reactive": false,
    "authenticationType": "session",
    "packageName": "com.mycompany.myapp",
    "serverPort": "8080",
    "cacheProvider": "no",
    "enableHibernateCache": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "postgresql",
    "buildTool": "maven",
    "serverSideOptions": [],
    "websocket": false,
    "searchEngine": false,
    "messageBroker": false,
    "enableSwaggerCodegen": false,
    "clientFramework": "angularX",
    "withAdminUi": true,
    "clientTheme": "none",
    "enableTranslation": false,
    "nativeLanguage": "en",
    "packageFolder": "com/mycompany/myapp",
    "rememberMeKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "clientPackageManager": "npm",
    "clientThemeVariant": "",
    "languages": ["en", "fr"]
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions

Environment and Tools

java version "11.0.9" 2020-10-20 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.9+7-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)

git version 2.29.0.windows.1

node: v14.15.5

npm: 6.14.11

Docker version 20.10.5, build 55c4c88

docker-compose version 1.28.5, build c4eb3a1f

Browsers and Operating System
  • [ ] Checking this box is mandatory (this is just to show you read everything)

venustulips avatar Mar 14 '21 07:03 venustulips

Hi @venustulips Thanks for reporting this.

Can you try something for me by editing the script e2e:cypress and remove this part --record ${CYPRESS_ENABLE_RECORD:-false}?

or and replace it by --record false

Thanks

avdev4j avatar Mar 15 '21 13:03 avdev4j

It seems --record is a standalone option, it does not accept a boolean value.

https://docs.cypress.io/guides/guides/command-line.html#cypress-run-record-key-lt-record-key-gt

venustulips avatar Mar 16 '21 07:03 venustulips

I'm pretty sure --record false is correct since you can enable Dashboard recording dynamically, however, I admit the common way to use it is --record.

I think here, the problem is coming from this part ${CYPRESS_ENABLE_RECORD:-false} probably not recognized by Windows.

avdev4j avatar Mar 16 '21 09:03 avdev4j

I can confirm it works on my env. Did you try to do what I suggest to you? I don't have a Windows env to test it, if you can maybe we can find the way to fix that.

avdev4j avatar Mar 16 '21 10:03 avdev4j

See my original comment https://github.com/jhipster/generator-jhipster/pull/13717#discussion_r566744125. I’ve failed to make it cross platform already.

We could try double -- . concurrently -k -s first "npm run ci:e2e:server:start" "npm run e2e:headless -- -- --record ${CYPRESS_ENABLE_RECORD:-false}" If that fails, we should duplicate e2e:headless to ci:e2e:headless and add the condition there.

mshima avatar Mar 16 '21 11:03 mshima

@avdev4j

cypress run --browser chrome works

but neither cypress run --browser edge --record ${CYPRESS_ENABLE_RECORD:-false} nor cypress run --browser edge --record false works on windows.

The actual issue as per my above-pasted log, if you include --record then adding a projectId in cypress.json seems mandatory.

venustulips avatar Mar 16 '21 11:03 venustulips

BTW, I really wish all the npm scripts works on windows too without WSL. Currently, most of the commands fail on windows as the npm scripts was mainly developed for *nix.

PS D:\temp\jhcypress> npm run backend:info
> [email protected] backend:info D:\temp\jhcypress
> ./mvnw -ntp enforcer:display-info --batch-mode

'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] backend:info: `./mvnw -ntp enforcer:display-info --batch-mode`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] backend:info script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Even with GitBash, manually running the same command works while run via npm script fails.

./mvnw -ntp enforcer:display-info --batch-mode

venustulips avatar Mar 16 '21 11:03 venustulips

@avdev4j @mshima I found https://github.com/elijahmanor/cross-var which solves windows/*nix problem nicely.

Instead of

"backend:info": "./mvnw -ntp enforcer:display-info --batch-mode",

prepend with cross-var,

"backend:info": "cross-var ./mvnw -ntp enforcer:display-info --batch-mode",

I have confirmed with

  • cmd.exe
  • Powershell (New Win Terminal)
  • GitBash

I belive with this, we can have portable cross-platform npm scripts.

venustulips avatar Mar 16 '21 12:03 venustulips

hey it seems to be a good alternative. WDYT @mshima?

@venustulips can you confirm it fixes the Cypress problem too?

avdev4j avatar Mar 17 '21 09:03 avdev4j

I think I've came across cross-env and cross-var back in the time. But IMO we shouldn't use any of them, cross-env is reportedly deprecated (the original repository was archived) and cross-var repository is untouched for more than 3 and a half years, and brings in some babel dependencies and outdated cross-spawn.

The ./ problem can be fixed by linking mvnw/gradlew into node_modules/.bin in postinstall script. I couldn't find a package that does that, but I have in mind how to implement it, if it's the way to go.

mshima avatar Mar 17 '21 15:03 mshima

This issue is stale because it has been open 30 days with no activity. Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted. We are accepting PRs :smiley:. Comment or this will be closed in 7 days

github-actions[bot] avatar Apr 17 '21 00:04 github-actions[bot]

Maybe windows did not pick up ${CYPRESS_ENABLE_RECORD:-false}" Try this: add this to package.json "cy:run": "(is-ci && cypress run --browser chrome --record) || cypress run --browser chrome" Then, run "npm run cy:run" And you can run it with or without set up your key You can see this post: https://github.com/cypress-io/cypress/issues/4876

yuchilai avatar Apr 22 '21 05:04 yuchilai

This issue is stale because it has been open 30 days with no activity. Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted. We are accepting PRs :smiley:. Comment or this will be closed in 7 days

github-actions[bot] avatar May 24 '21 00:05 github-actions[bot]

I am running jhipster 7.7.0 per Matt Raible's "Get Started with JHipster 7", and this error still occurs with npm run e2e. The tests will work using the first suggestion of editing package.json; and updating line "e2e:cypress": "cypress run --browser chrome --record ${CYPRESS_ENABLE_RECORD:-false}", to "e2e:cypress": "cypress run --browser chrome --record false".

tautera avatar Mar 31 '22 20:03 tautera

@mshima Can you confirm this issue is fixed and issue can be closed?

DanielFran avatar May 13 '22 13:05 DanielFran

@mshima Can you confirm this issue is fixed and issue can be closed?

I upgraded Jhipster to the latest version; 7.8.1, and the issue still occurs. If I update package.json, as stated earlier, the test works.

tautera avatar May 13 '22 15:05 tautera

@tautera can you add this file: https://github.com/jhipster/generator-jhipster-native/blob/main/generators/server/templates/.npmrc

mshima avatar May 13 '22 15:05 mshima

@tautera can you add this file: https://github.com/jhipster/generator-jhipster-native/blob/main/generators/server/templates/.npmrc

That does not work. Seeing this with that change (I'm using Windows 11 btw...):

C:\source\blog>npm run e2e

[email protected] e2e C:\source\blog npm run e2e:cypress:headed --

/bin/bash: /mnt/c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter: No such file or directory npm ERR! code ELIFECYCLE npm ERR! errno 126 npm ERR! [email protected] e2e: npm run e2e:cypress:headed -- npm ERR! Exit status 126 npm ERR! npm ERR! Failed at the [email protected] e2e script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\tomau\AppData\Roaming\npm-cache_logs\2022-05-13T15_58_39_642Z-debug.log

C:\source\blog>

tautera avatar May 13 '22 16:05 tautera

@tautera try updating npm to 8.10.0. https://github.com/npm/cli/commit/e69be2ac5c35e985732e2baa00b70d39332e4b9f

Actually v7.6.1.

mshima avatar May 13 '22 16:05 mshima

Or running npmw run e2e

mshima avatar May 13 '22 16:05 mshima

Or running npmw run e2e

Upgraded to 8.10.0, ran npm run e2e, ran npmw run e2e, same error

C:\source\blog>npm --version 8.10.0

C:\source\blog>npm run e2e

[email protected] e2e npm run e2e:cypress:headed --

/usr/bin/env: ‘bash\r’: No such file or directory

C:\source\blog>npmw run e2e

[email protected] e2e npm run e2e:cypress:headed --

/usr/bin/env: ‘bash\r’: No such file or directory

tautera avatar May 13 '22 17:05 tautera

Adding bug bounty to try and get this fixed for Windows users.

mraible avatar Aug 28 '22 17:08 mraible

So what is the issue exactly need to solve? 👀

zhyd1997 avatar Apr 22 '23 03:04 zhyd1997

https://opencollective.com/generator-jhipster/expenses/138316 :)

zhyd1997 avatar May 10 '23 01:05 zhyd1997