badeball / cypress-cucumber-preprocessor

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

TypeError: Cannot destructure property 'message' of 'testStepResult' as it is undefined. #1161

Closed akshaygupta5233 closed 7 months ago

akshaygupta5233 commented 8 months ago

Current behavior

When I run my tests in local or jenkins, I do see this error mentioned below- The error is way random and I am not able to understand at what point this error is coming. Because of this, my reports are not being generated.

An error was thrown in your plugins file while executing the handler for the after:run event. The error we received was: TypeError: Cannot destructure property 'message' of 'testStepResult' as it is undefined. at JsonFormatter.getStepData (/app/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:281:13) at /app/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:161:23 at Array.map () at /app/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:159:58 at Array.map () at /app/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:155:30 at Array.map () at JsonFormatter.onTestRunFinished (/app/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:147:59) at EventEmitter. (/app/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:92:14) at EventEmitter.emit (node:events:526:35) at EventEmitter.emit (node:domain:488:12) at afterRunHandler (/app/node_modules/@badeball/cypress-cucumber-preprocessor/dist/plugin-event-handlers.js:134:30)

Screenshot 2024-02-20 at 23 00 49

Desired behavior

The error should not appear and let the reports be generated.

Test code to reproduce

My cypress.config.ts file-

import { defineConfig } from "cypress"; import * as createBundler from "@bahmutov/cypress-esbuild-preprocessor"; import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor"; import createEsbuildPlugin from "@badeball/cypress-cucumber-preprocessor/esbuild";

export default defineConfig({ env: { CYPRESS_PROCESS_PROFILER_INTERVAL: 60000, baseUrl: "A url", }, viewportWidth: 1600, viewportHeight: 900, numTestsKeptInMemory: 0, scrollBehavior: "top", screenshotOnRunFailure: true, e2e: { defaultCommandTimeout: 50000, testIsolation: true, experimentalMemoryManagement: true, experimentalInteractiveRunEvents: true, specPattern: "*/.feature", async setupNodeEvents( on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions ): Promise { await addCucumberPreprocessorPlugin(on, config); on( "file:preprocessor", createBundler({ plugins: [createEsbuildPlugin(config)], }) ); return config; }, }, });

Versions

Checklist

akshaygupta5233 commented 8 months ago

@badeball Kindly help me on this

badeball commented 8 months ago

As I've already explained in other issues of yours - I can't help you unless you provide me with reproducible examples. A configuration file simply doesn't tell the whole story here.

suneelfm-tandem commented 8 months ago

This error is originated from @cucumber/cucumber https://github.com/cucumber/cucumber-js/blob/9e4d7bd2e85a4342837956308c874b3f67bec14e/src/formatter/json_formatter.ts#L281C5-L281C47.

There testStepResult is handling. If we have testStepResult then proceed with the logic else not. Just one if condition can fix this issue I believe. This issue should be fixed by @cucumber/cucumber side it seems. Even I am also getting this issue, but it's very difficult to understand that which scenario it's coming on? as it is not consistent. But this issue was not there for lower versions like 15.0.0

I hope this comment will help to fix this issue.

badeball commented 8 months ago

If we have testStepResult then proceed with the logic else not. Just one if condition can fix this issue I believe. This issue should be fixed by @cucumber/cucumber side it seems.

No. The JsonFormatter is a stateful component and it expects there to be a testStepResult at that point. Anything else means that the envelopes sent by this library are wrong. Maintaining envelope state is where all edge cases are taken into account.

This is why you both need to provide reproducible examples, as I can't determine your edge case otherwise.

nurullahsahin44 commented 8 months ago

Same problem, I could not change anything but I saw same fail last time

AMEntwistle commented 8 months ago

We have the same issue. This occurs for us when chrome crashes during test execution. It's particularly a problem because for us it leads to a false positive even though the test did not run and pass.

@badeball To reproduce this do the following:

  1. Add a cy.pause() to a test
  2. Run the test in headed mod, e.g cypress run --env TAGS="@focus" --browser chrome --headed
  3. When you hit the pause, trigger the crash by pasting this into the browser: chrome://inducebrowsercrashforrealz

You will then see this error.

This is a very real scenario as cypress has issues with memory crashes lately. I appreciate the plugin may not be able to handle full reporting in this instance, but not erroring out like this is very important since it breaks our other plugin that also uses the after:run event.

badeball commented 8 months ago

@AMEntwistle, are you seeing the same error as depicted in OP's screenshot?

AMEntwistle commented 8 months ago

@badeball Yes same error:

TypeError: Cannot destructure property 'message' of 'testStepResult'

badeball commented 8 months ago

Given the this example, if I navigate to chrome://inducebrowsercrashforrealz during the pause, I get the following error.

An error was thrown in your plugins file while executing the handler for the after:spec event.

The error we received was:

Error: Unexpected state in afterSpecHandler: step-started (this might be a bug, please report at https://github.com/badeball/cypress-cucumber-preprocessor)
    at createError (/home/jonas/projects/reproducible-issues/cypress-cucumber-preprocessor/crash-during-step/node_modules/@badeball/cypress-cucumber-preprocessor/dist/helpers/error.js:9:12)
    at afterSpecHandler (/home/jonas/projects/reproducible-issues/cypress-cucumber-preprocessor/crash-during-step/node_modules/@badeball/cypress-cucumber-preprocessor/dist/plugin-event-handlers.js:276:43)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Are you doing something different?

AMEntwistle commented 8 months ago

My bad, looks like I was on an older plugin version. I see what you do on the latest. I suppose this is a separate issue to what's mentioned here.

suneelfm-tandem commented 8 months ago

Given the this example, if I navigate to chrome://inducebrowsercrashforrealz during the pause, I get the following error.

An error was thrown in your plugins file while executing the handler for the after:spec event.

The error we received was:

Error: Unexpected state in afterSpecHandler: step-started (this might be a bug, please report at https://github.com/badeball/cypress-cucumber-preprocessor)
    at createError (/home/jonas/projects/reproducible-issues/cypress-cucumber-preprocessor/crash-during-step/node_modules/@badeball/cypress-cucumber-preprocessor/dist/helpers/error.js:9:12)
    at afterSpecHandler (/home/jonas/projects/reproducible-issues/cypress-cucumber-preprocessor/crash-during-step/node_modules/@badeball/cypress-cucumber-preprocessor/dist/plugin-event-handlers.js:276:43)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Are you doing something different?

I have a issue https://github.com/badeball/cypress-cucumber-preprocessor/issues/1166 for this error. This may help to fix that issue.

badeball commented 8 months ago

I have a issue https://github.com/badeball/cypress-cucumber-preprocessor/issues/1166 for this error. This may help to fix that issue.

It won't. You need to provide reproducible examples to your issues.

badeball commented 7 months ago

Closing due to lack of a reproducible example. Feel free to open up another issue if anything changes in this regard.

nounnoune commented 4 months ago

Hi @akshaygupta5233, I was having the same issue

The problem was baseUrl != url actually visited (cy.visit('other_url_than_the_one_defined_for_baseUrl)) Visit the same url you defined in baseUrl and it should be fine

It worked for me, hope it helps

jdserranoc commented 1 month ago

Hi, this is the first time a wrote here because the same thing is happening to me in my Github Actions workflow and locally. And the problem with this error is that it happens randomly and I can't find a way to reproduce it. If someone found a way to fix it differently than comment of @nounnoune I would appreciate it. Thanks!

image

Bit-Banging commented 1 month ago

I've been dealing with this problem for a while now. I have finally been able to solve it for myself and hope to be able to help someone else. I have several pipelines that run tests with Cypress 13.13.0. The tests are carried out with Chrome, Edge and Firefox . At a certain point this problem always occurred consistently only with Firefox after the very last test of the run.

It turned out that some tests consumed so much memory that Firefox could no longer handle it and was terminated with Out-Of-Memory. Sadly there were no logs from Cypress about it and no screenshot got created. Chromium based browsers never had a problem.

I was able to reduce the load on Firefox by greatly reducing logging especially for loops. Cypress offers the option of suppressing logging for individual commands { log: false }. Of course it also would make sense to write shorter tests so that the memory is released more quickly. So the problem for me was not the cucumber preprocessor but that the browser terminated and the test data was not available to process.

badeball commented 1 month ago

Crash behavior in Cypress is a mess and always has been. It's possible to simulate different types of crash in chromium, but this isn't possible in firefox afaik. There was talk about supporting this. However, Cypress isn't being developed in any meaningful way nowadays, so I wouldn't count on ever seeing this improved.

jdserranoc commented 2 weeks ago

Hi, this is the first time a wrote here because the same thing is happening to me in my Github Actions workflow and locally. And the problem with this error is that it happens randomly and I can't find a way to reproduce it. If someone found a way to fix it differently than comment of @nounnoune I would appreciate it. Thanks!

image

I updated to the last version of preprocessor v21.0.2, but still seeing the issue

image

badeball commented 2 weeks ago

@jdserranoc, your image shows a different error. If you're trying to solicit help, then I recommend that you open a new issue and make sure to follow the issue template (ie. provide a reproducable example).

jdserranoc commented 6 days ago

@jdserranoc, your image shows a different error. If you're trying to solicit help, then I recommend that you open a new issue and make sure to follow the issue template (ie. provide a reproducable example).

Sorry, I updated the image with the correct error. It's the same behavior and still too random, I tested running locally and in my GitHub actions.