badeball / cypress-cucumber-preprocessor

Run cucumber/gherkin-syntaxed specs with Cypress
MIT License
1.32k stars 147 forks source link

Expected to find global registry error on test case init #804

Closed richardszanyi-kasa closed 2 years ago

richardszanyi-kasa commented 2 years ago

Hi,

I recently updated our framework to use cypress 10.x, and typescript. Also changed to the latest cypress-cucumber-preprocessor from you, and I thank you for that for updating this package. Yesterday it was working perfectly. Today I did an npm update and it broke all of it. I was wondering why, and it pointed me to this package, where the error message said that I should report this as a bug, so I am doing that rn. :)

I cannot give you an example repo unfortunately due to capacity, however maybe you can point out what is its problem with my package json after npm update, or maybe there is a bug you can see from that either way.

Thank you, you are awesome!

image

at fail ([node_modules/@badeball/cypress-cucumber-preprocessor/lib/assertions.js:7:1](https://kontrol-dev.kasa.com/__/#))
    at assert ([node_modules/@badeball/cypress-cucumber-preprocessor/lib/assertions.js:14:1](https://kontrol-dev.kasa.com/__/#))
    at assertAndReturn ([node_modules/@badeball/cypress-cucumber-preprocessor/lib/assertions.js:18:1](https://kontrol-dev.kasa.com/__/#))
    at getRegistry ([node_modules/@badeball/cypress-cucumber-preprocessor/lib/registry.js:137:1](https://kontrol-dev.kasa.com/__/#))
    at defineBefore ([node_modules/@badeball/cypress-cucumber-preprocessor/lib/methods.js:32:1](https://kontrol-dev.kasa.com/__/#))
    at 1.../../support/helpers/auth0-api ([e2e/stepDefinitions/e2e.ts:38:8](https://kontrol-dev.kasa.com/__/#))
    at o ([node_modules/browser-pack/_prelude.js:1:1](https://kontrol-dev.kasa.com/__/#))
    at eval ([node_modules/browser-pack/_prelude.js:1:1](https://kontrol-dev.kasa.com/__/#))
    at 225.../../e2e/stepDefinitions/e2e ([support/helpers/kontrol-api.ts:1:1](https://kontrol-dev.kasa.com/__/#))
    at o ([node_modules/browser-pack/_prelude.js:1:1](https://kontrol-dev.kasa.com/__/#))
From previous event:
    at runScriptsFromUrls (https://kontrol-dev.kasa.com/__cypress/runner/cypress_runner.js:175359:137)
    at Object.runScripts (https://kontrol-dev.kasa.com/__cypress/runner/cypress_runner.js:175374:13)
    at $Cypress.onSpecWindow (https://kontrol-dev.kasa.com/__cypress/runner/cypress_runner.js:163545:76)

Dependencies we use:

"devDependencies": {
    "@bahmutov/cypress-extends": "^1.1.0",
    "@cypress/browserify-preprocessor": "^3.0.2",
    "@percy/cli": "^1.0.0-beta.52",
    "@percy/cypress": "^3.1.0",
    "@typescript-eslint/parser": "^5.33.0",
    "cypress-iframe": "^1.0.1",
    "cypress-plugin-stripe-elements": "^1.0.1",
    "cypress-slack-reporter": "^1.2.1",
    "cypress-social-logins": "^1.11.2",
    "cypress-terminal-report": "^4.1.2",
    "docolatte": "^2.10.2",
    "eslint": "^8.10.0",
    "mochawesome": "^7.1.3",
    "mochawesome-merge": "^4.2.1",
    "mochawesome-report-generator": "^6.2.0",
    "path": "^0.12.7",
    "resolve": "^1.22.1",
    "stream": "^0.0.2"
  },
  "dependencies": {
    "@badeball/cypress-cucumber-preprocessor": "^12.0.1",
    "@cucumber/cucumber": "^7.0.0",
    "@cypress/webpack-preprocessor": "^5.12.1",
    "@privateRepo1": "^9.18.0",
    "@privateRepo2": "0.1.1",
    "@privateRepo3": "^2.43.0",
    "@typescript-eslint/eslint-plugin": "^5.33.0",
    "aws-sdk": "^2.932.0",
    "axios": "^0.27.2",
    "clean-jsdoc-theme": "^3.3.1",
    "commander": "^7.2.0",
    "cypress": "^10.6.0",
    "cypress-commands": "^1.1.0",
    "cypress-real-events": "^1.7.1",
    "cypress-waitfor": "^1.1.0",
    "dayjs": "^1.10.4",
    "express": "^4.18.1",
    "jira-client-xray": "^1.0.1",
    "jsdoc-cypress-cucumber-plugin": "^1.1.0",
    "lodash": "^4.17.21",
    "luxon": "^1.26.0",
    "mocha": "^10.0.0",
    "mongodb": "^4.7.0",
    "namecase": "^1.1.2",
    "prettier": "^2.5.1",
    "prettier-eslint": "^13.0.0",
    "ts-loader": "^9.3.1"
  },

Current behavior

After using npm update and updating my packages, this error message comes up after loading a test case.

Desired behavior

Works as expected

Versions

Checklist

badeball commented 2 years ago

It appears that you’re mixing two versions and haven’t upgraded completely.

richardszanyi-kasa commented 2 years ago

I just removed it, sorry. Same error.

badeball commented 2 years ago

Then you need to provide a reproducible example.

richardszanyi-kasa commented 2 years ago

I've found the issue. if stepDefinitions/e2e.ts has any hook, it fails loading and the error message occurs. However, if I delete every hook from that file, it can run correctly. Afaik the stepDefinitions/e2e.ts can be used for hooks that has to run before every scenario. The error message points to an error in the support/e2e.ts however I suspect that some reading issue is happening here.

Edit1: Renaming the stepDefinitions/e2e.ts to stepDefinitions/beforeAll.ts seems to not solve the issue. Only removing the hooks resolve it.

Do you have any idea why is that, or how to workaround?

badeball commented 2 years ago

See my comment above.

richardszanyi-kasa commented 2 years ago

I cannot reproduce it properly on a clean fw. It sometimes comes up, sometimes it does not. I'm not even sure what it is that its trying to resolve, and what is global registry, so I might find the issue here? Is that something to do with me rewriting JS to TS, and it parses the code badly, or some configuration option? I'm really not sure. I could find out that:

richardszanyi-kasa commented 2 years ago

Also note, I'm starting an integration test with *.ts, and not a .feature test inside the fw. I'm pretty sure the dependency should not init on those.

richardszanyi-kasa commented 2 years ago

My issue seems to be resolved by removing import 'cypress-waitfor' with the cypress-waitfor package.

richardszanyi-kasa commented 2 years ago

nvm, still having the issue. It is really flaky. If anyone has any idea let me know.

richardszanyi-kasa commented 2 years ago

Sorry for taking that long, I've found the issue and have a workaround for that, however:

https://github.com/richardszanyi-kasa/cypress-cucumber-preprocessor-bug-repro/

Here is the reproducible example.

(The issue was that the e2e.ts which has a Before and After hook also stores a globally used variable object called Vars. If any test uses this Vars object, e2e.ts will be loaded, and somehow the preprocessor cannot do anything with that, if you remove Vars from e2e\e2e.ts it works.)

Let me know your thoughts. Cheers, Richard

badeball commented 2 years ago

You can't run methods imported from @badeball/cypress-cucumber-preprocessor in a non-feature test (google.ts), which is essentially what you're doing (although maybe not you intended to or even realized).

richardszanyi-kasa commented 2 years ago

A better error message would suffice here then. That makes sense, thanks.