badeball / cypress-cucumber-preprocessor

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

Getting Invalid or unexpected token error when running in pipeline using cypress dashboard parallel #1221

Closed magarwal19 closed 2 months ago

magarwal19 commented 2 months ago

Current behavior

When i execute tests using parallel execution from CI, then some random tests are failing due to errors

Invalid or unexpected token Unexpected end of input

Screenshot 2024-08-14 at 11 31 56 PM

Screenshot 2024-08-14 at 11 32 27 PM

while executing tests in local sequentially then no issue is observed.

I was going through few links and seems this might be due to parallel behaviour

https://davidwcai.medium.com/fix-cypress-invalid-or-unexpected-token-errors-in-parallel-runs-e887d7efa945

Note: I am using JS based solution for cypress

Desired behavior

Error messages should not be thrown and we should be able to execute tests in parallel

Test code to reproduce

Sorry can not share the code directly

Versions

badeball commented 2 months ago

I can't help you without a way of reproducing this.

magarwal19 commented 2 months ago

it would be for any code if we run it using cypress dashboard parallel..

it is not code related part but more like when we run it on parallel thread using CI and Dashboard..

we can try to run any code with this setup to reproduce issue

badeball commented 2 months ago

If it can be reproduced using any code, then that is what you should provide. A runnable example which showcases the error. In no way am I interested in your production code, as explained in the contributing guidelines.

magarwal19 commented 2 months ago

if possible can you please check this link https://davidwcai.medium.com/fix-cypress-invalid-or-unexpected-token-errors-in-parallel-runs-e887d7efa945 and suggest changes which can be done for config js file?

i currently have code :

const createBundler = require("@bahmutov/cypress-esbuild-preprocessor"); const { addCucumberPreprocessorPlugin, } = require("@badeball/cypress-cucumber-preprocessor"); const { createEsbuildPlugin, } = require("@badeball/cypress-cucumber-preprocessor/esbuild");

on( "file:preprocessor", createBundler({ plugins: [createEsbuildPlugin(config)], }) );

magarwal19 commented 2 months ago

If it can be reproduced using any code, then that is what you should provide. A runnable example which showcases the error. In no way am I interested in your production code, as explained in the contributing guidelines.

I understand it, but my part is even though i will share a sample code, this issue will not be reproducible on local run..

as this will only be reproducible when we run on parallel agent over CI/CD and using cypress dashboard

badeball commented 2 months ago

You need to figure out what you're doing different in CI vs. local.

For instance, using Cypress Cloud to parallelize isn't exclusive to CI. You can run that stuff locally. If you haven't, then you're essentially running two different programs and wondering why the results aren't the same.

magarwal19 commented 2 months ago

Sorry, but as per my knowledge, cypress does not support parallel execution on local.. we can achieve parallel run using dashboard when we have multiple agents/nodes executing over CI https://docs.cypress.io/guides/cloud/smart-orchestration/parallelization

would be happy to know if there is a way to run tests in parallel in cypress on local machine

badeball commented 2 months ago

CI isn't special in this regard, you just run $ cypress run --record --key=abc123 --parallel, as per the mentioned docs, on your local machine, possibly simultaneously.

magarwal19 commented 2 months ago

issue is same as it is mentioned in https://davidwcai.medium.com/fix-cypress-invalid-or-unexpected-token-errors-in-parallel-runs-e887d7efa945

since we are executing parallel, different threads try to overwrite same data, due which it fails...

i am not able to use the solution given in this link, but able to resolve issue for me by adding manual waits of 15seconds for each parallel run

badeball commented 2 months ago

Okey. Closing as not an issue with the preprocessor.

magarwal19 commented 2 months ago

sorry but it is issue with preprocessor only when we are executing in parallel, we might need to update the code where we are creating file conversion to use uuid

badeball commented 2 months ago

This preprocessor doesn't touch the filesystem during compile stage. The above-mentioned article explains the issue without referencing this preprocessor at all, further indicating that this isn't my problem.

badeball commented 2 months ago

https://github.com/cypress-io/cypress/issues/26211