allure-js icon indicating copy to clipboard operation
allure-js copied to clipboard

Allure for Cypress not working

Open harmin-parra opened this issue 10 months ago • 20 comments

Describe the Bug

I get this error when running cypress

Oops...we found an error preparing this test file:

  > cypress/support/e2e.js

The error was:

Error: Webpack Compilation Error
./cypress/support/e2e.js
Module not found: Error: Can't resolve 'allure-cypress/commands' in '/home/hpr/cypress-allure-plugin-example/cypress/support'
resolve 'allure-cypress/commands' in '/home/hpr/cypress-allure-plugin-example/cypress/support'
  Parsed request is a module
  using description file: /home/hpr/cypress-allure-plugin-example/package.json (relative path: ./cypress/support)
    Field 'browser' doesn't contain a valid alias configuration
    Looked for and couldn't find the file at the following paths:
[/home/hpr/cypress-allure-plugin-example/cypress/support/node_modules]
[/home/hpr/cypress-allure-plugin-example/cypress/node_modules]
[/home/hpr/node_modules]
[/home/node_modules]
[/node_modules]
[/home/hpr/cypress-allure-plugin-example/node_modules/allure-cypress/commands]
[/home/hpr/cypress-allure-plugin-example/node_modules/allure-cypress/commands.js]
[/home/hpr/cypress-allure-plugin-example/node_modules/allure-cypress/commands.json]
[/home/hpr/cypress-allure-plugin-example/node_modules/allure-cypress/commands.jsx]
[/home/hpr/cypress-allure-plugin-example/node_modules/allure-cypress/commands.mjs]
[/home/hpr/cypress-allure-plugin-example/node_modules/allure-cypress/commands.coffee]
 @ ./cypress/support/e2e.js 4:0-34
 
    at handle (/home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/@packages/server/node_modules/@cypress/webpack-preprocessor/dist/index.js:212:23)
    at finalCallback (/home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/webpack/lib/Compiler.js:257:39)
    at /home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/webpack/lib/Compiler.js:306:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at /home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/webpack/lib/Compiler.js:304:22
    at Compiler.emitRecords (/home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/webpack/lib/Compiler.js:499:39)
    at /home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/webpack/lib/Compiler.js:298:10
    at /home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/webpack/lib/Compiler.js:485:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at /home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/webpack/lib/Compiler.js:482:27
    at /home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/neo-async/async.js:2818:7
    at done (/home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/neo-async/async.js:3522:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/tapable/lib/Hook.js:154:20)
    at /home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/webpack/lib/Compiler.js:464:33
    at /home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/@packages/server/node_modules/graceful-fs/graceful-fs.js:143:16
    at /home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/@packages/server/node_modules/graceful-fs/graceful-fs.js:143:16
    at /home/hpr/.cache/Cypress/12.14.0/Cypress/resources/app/node_modules/@packages/server/node_modules/graceful-fs/graceful-fs.js:61:14
    at FSReqCallback.oncomplete (node:fs:192:23)

This occurred while Cypress was compiling and bundling your test code. This is usually caused by:

- A missing file or dependency
- A syntax error in the file or one of its dependencies

Fix the error in your code and re-run your tests.

Steps to Reproduce

npm install --save-dev allure-cypress

cypress/support/e2e.js file:

import './commands';
import "allure-cypress/commands";

cypress.config.js file:

const { defineConfig } = require('cypress');
const { allureCypress } = require("allure-cypress/reporter");

module.exports = defineConfig({
    video: false,
    e2e: {
        experimentalStudio: true,
        specPattern: 'cypress/tests/**/*.cy.{js,jsx,ts,tsx}',
        setupNodeEvents: async function (on, config) {
            allureCypress(on);
            return config;
        }
    }

npx cypress run

Expected Behaviour

cypress runs without errors and aluure report is generated

Screenshots or Additional Context

No response

What Language are you using?

JavaScript

What Framework/Allure Integration you are using?

allure-cypress 2.15.1

What version of Allure Integration you are using?

2.15.1

What version of Allure Report you are using?

2.27.0

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

harmin-parra avatar Apr 11 '24 18:04 harmin-parra

I am experiencing the same issue, is there a solution in the near future?

bhadmusautomates avatar Apr 14 '24 16:04 bhadmusautomates

Hey there! You don't need to import commands. Add just this import to make the integration works:

import "allure-cypress";

epszaw avatar May 14 '24 11:05 epszaw

Hey there! You don't need to import commands. Add just this import to make the integration works:

import "allure-cypress";

It doesn't work, the allure-results folder is empty

bhadmus avatar May 14 '24 12:05 bhadmus

Could you provide the process log? Do you see any runtime error?

epszaw avatar May 14 '24 13:05 epszaw

Could you provide the process log? Do you see any runtime error?

0 verbose cli /Users/sanguine/.nvm/versions/node/v18.14.0/bin/node /Users/sanguine/.nvm/versions/node/v18.14.0/lib/node_modules/npm/bin/npm-cli.js
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 5ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:/Users/sanguine/.nvm/versions/node/v18.14.0/lib/node_modules/npm/npmrc Completed in 3ms
6 timing config:load:builtin Completed in 4ms
7 timing config:load:cli Completed in 0ms
8 timing config:load:env Completed in 1ms
9 timing config:load:file:/Users/sanguine/Tutorial/cohort-2/classes/week-one/.npmrc Completed in 0ms
10 timing config:load:project Completed in 1ms
11 timing config:load:file:/Users/sanguine/.npmrc Completed in 3ms
12 timing config:load:user Completed in 3ms
13 timing config:load:file:/Users/sanguine/.nvm/versions/node/v18.14.0/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:setEnvs Completed in 0ms
16 timing config:load Completed in 11ms
17 timing npm:load:configload Completed in 12ms
18 timing npm:load:mkdirpcache Completed in 0ms
19 timing npm:load:mkdirplogs Completed in 1ms
20 verbose title npm exec allure generate allure-results --clean
21 verbose argv "exec" "--" "allure" "generate" "allure-results" "--clean"
22 timing npm:load:setTitle Completed in 12ms
23 timing config:load:flatten Completed in 1ms
24 timing npm:load:display Completed in 2ms
25 verbose logfile logs-max:10 dir:/Users/sanguine/.npm/_logs/2024-05-14T22_23_05_029Z-
26 verbose logfile /Users/sanguine/.npm/_logs/2024-05-14T22_23_05_029Z-debug-0.log
27 timing npm:load:logFile Completed in 38ms
28 timing npm:load:timers Completed in 0ms
29 timing npm:load:configScope Completed in 0ms
30 timing npm:load Completed in 70ms
31 silly logfile start cleaning logs, removing 1 files
32 silly logfile done cleaning log files
33 timing arborist:ctor Completed in 0ms
34 timing arborist:ctor Completed in 1ms
35 http fetch GET 200 https://registry.npmjs.org/allure 627ms (cache revalidated)
36 timing command:exec Completed in 695ms
37 verbose stack Error: could not determine executable to run
37 verbose stack     at getBinFromManifest (/Users/sanguine/.nvm/versions/node/v18.14.0/lib/node_modules/npm/node_modules/libnpmexec/lib/get-bin-from-manifest.js:17:23)
37 verbose stack     at exec (/Users/sanguine/.nvm/versions/node/v18.14.0/lib/node_modules/npm/node_modules/libnpmexec/lib/index.js:187:15)
37 verbose stack     at async module.exports (/Users/sanguine/.nvm/versions/node/v18.14.0/lib/node_modules/npm/lib/cli.js:134:5)
38 verbose pkgid [email protected]
39 verbose cwd /Users/sanguine/Tutorial/cohort-2/classes/week-one
40 verbose Darwin 23.4.0
41 verbose node v18.14.0
42 verbose npm  v9.3.1
43 error could not determine executable to run
44 verbose exit 1
45 timing npm Completed in 778ms
46 verbose code 1
47 error A complete log of this run can be found in:
47 error     /Users/sanguine/.npm/_logs/2024-05-14T22_23_05_029Z-debug-0.log

bhadmus avatar May 14 '24 22:05 bhadmus

Ei! Você não precisa importar commands. Adicione apenas esta importação para fazer a integração funcionar:

import "allure-cypress";

Não funciona, a allure-resultspasta está vazia

@bhadmus I have the same problem, did you find any solution?

dayaneCsantos avatar May 15 '24 13:05 dayaneCsantos

@dayaneCsantos check my comment below. if it works for you, help me vote for my answer on stackoverflow as well https://stackoverflow.com/questions/77067015/cypress-allure-reports-are-not-getting-generated/78487640#78487640

bhadmus avatar May 15 '24 15:05 bhadmus

I eventually fixed this issue.

The workaround is to downgrade to v.2.14.0. If you're installing for the first time install using npm i -D [email protected] else just change the version to 2.14.0 in your package.json file then run npm i or yarn install.

Keep all config the same. i.e. import allure-cypress into the support\e2e.js using import 'allure-cypress/commands' and setting up allure-cypress in the cypress.config.js file like this:

const { allureCypress } = require("allure-cypress/reporter");

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      allureCypress(on)
    },
  },
});

run cypress in headless mode npx cypress run after this, the folder should be populated json files. to generate result, do not add npx to the allure command just use allure serve allure-results to create the result and view on a browser or use allure generate allure-results --clean to create a report folder containing the html version in the repository.

bhadmus avatar May 16 '24 05:05 bhadmus

The problem has been already resolved in the next allure-cypress version. Stay in touch to get information about the new releases!

epszaw avatar May 16 '24 15:05 epszaw

Even following https://github.com/allure-framework/allure-js/issues/934#issuecomment-2114032056, I get build errors:

Error: Cannot find module 'allure-cypress/commands' from '/e2e/cypress/support' at /e2e/node_modules/resolve/lib/async.js:46:17 at process (/e2e/node_modules/resolve/lib/async.js:173:43) at ondir (/e2e/node_modules/resolve/lib/async.js:188:17) at load (/e2e/node_modules/resolve/lib/async.js:69:43) at onex (/e2e/node_modules/resolve/lib/async.js:92:31) at /e2e/node_modules/resolve/lib/async.js:22:47 at callback (/root/.cache/Cypress/13.4.0/Cypress/resources/app/node_modules/@packages/server/node_modules/graceful-fs/polyfills.js:299:20) at callback (/root/.cache/Cypress/13.4.0/Cypress/resources/app/node_modules/@packages/server/node_modules/graceful-fs/polyfills.js:299:20)

RobertBattaglia avatar May 16 '24 15:05 RobertBattaglia

Even following #934 (comment), I get build errors:

Error: Cannot find module 'allure-cypress/commands' from '/e2e/cypress/support' at /e2e/node_modules/resolve/lib/async.js:46:17 at process (/e2e/node_modules/resolve/lib/async.js:173:43) at ondir (/e2e/node_modules/resolve/lib/async.js:188:17) at load (/e2e/node_modules/resolve/lib/async.js:69:43) at onex (/e2e/node_modules/resolve/lib/async.js:92:31) at /e2e/node_modules/resolve/lib/async.js:22:47 at callback (/root/.cache/Cypress/13.4.0/Cypress/resources/app/node_modules/@packages/server/node_modules/graceful-fs/polyfills.js:299:20) at callback (/root/.cache/Cypress/13.4.0/Cypress/resources/app/node_modules/@packages/server/node_modules/graceful-fs/polyfills.js:299:20)

Are you trying to use it for Cucumber with Cypress? It doesn't work for it at the moment. I will like to fork this entire repo and see if I can make it work for Cucumber.js

bhadmus avatar May 16 '24 16:05 bhadmus

The problem has been already resolved in the next allure-cypress version. Stay in touch to get information about the new releases!

Looking forward to it

bhadmus avatar May 16 '24 16:05 bhadmus

Even following #934 (comment), I get build errors: Error: Cannot find module 'allure-cypress/commands' from '/e2e/cypress/support' at /e2e/node_modules/resolve/lib/async.js:46:17 at process (/e2e/node_modules/resolve/lib/async.js:173:43) at ondir (/e2e/node_modules/resolve/lib/async.js:188:17) at load (/e2e/node_modules/resolve/lib/async.js:69:43) at onex (/e2e/node_modules/resolve/lib/async.js:92:31) at /e2e/node_modules/resolve/lib/async.js:22:47 at callback (/root/.cache/Cypress/13.4.0/Cypress/resources/app/node_modules/@packages/server/node_modules/graceful-fs/polyfills.js:299:20) at callback (/root/.cache/Cypress/13.4.0/Cypress/resources/app/node_modules/@packages/server/node_modules/graceful-fs/polyfills.js:299:20)

Are you trying to use it for Cucumber with Cypress? It doesn't work for it at the moment. I will like to fork this entire repo and see if I can make it work for Cucumber.js

No, not using Cucumber

RobertBattaglia avatar May 16 '24 16:05 RobertBattaglia

@RobertBattaglia use this for a workaround https://github.com/allure-framework/allure-js/issues/934#issuecomment-2114032056 until @epszaw releases the fix

bhadmus avatar May 16 '24 18:05 bhadmus

@dayaneCsantos check my comment below. if it works for you, help me vote for my answer on stackoverflow as well https://stackoverflow.com/questions/77067015/cypress-allure-reports-are-not-getting-generated/78487640#78487640

Made changes as per this comment but its not working in my case.

Facing this issue while running the scripts on CICD but works fine locally!

sadhishsk avatar May 19 '24 11:05 sadhishsk

The problem has been already resolved in the next allure-cypress version. Stay in touch to get information about the new releases!

Thank you for all the efforts! When can we expect a release @epszaw

sadhishsk avatar May 19 '24 11:05 sadhishsk

@dayaneCsantos check my comment below. if it works for you, help me vote for my answer on stackoverflow as well https://stackoverflow.com/questions/77067015/cypress-allure-reports-are-not-getting-generated/78487640#78487640

Made changes as per this comment but its not working in my case.

Facing this issue while running the scripts on CICD but works fine locally!

Can you share the pipeline error? I still used this in a class demo and it worked even with the v.2.15.0

bhadmusautomates avatar May 19 '24 11:05 bhadmusautomates

@bhadmus This is the error which I got:

**Oops...we found an error preparing this test file:

cypress/support/hooks.ts

The error was:

Error: Can't walk dependency graph: Cannot find module 'allure-cypress/commands' from '/e2e/cypress/support/hooks.ts' required by /e2e/cypress/support/hooks.ts at /e2e/node_modules/resolve/lib/async.js:146:35 at processDirs (/e2e/node_modules/resolve/lib/async.js:299:39) at isdir (/e2e/node_modules/resolve/lib/async.js:306:32) at /e2e/node_modules/resolve/lib/async.js:34:69 at callback (/root/node_modules/@packages/server/node_modules/graceful-fs/polyfills.js:299:20) at callback (/root/node_modules/@packages/server/node_modules/graceful-fs/polyfills.js:299:20) at FSReqCallback.oncomplete (node:fs:210:21)

This occurred while Cypress was compiling and bundling your test code. This is usually caused by:

  • A missing file or dependency
  • A syntax error in the file or one of its dependencies

Fix the error in your code and re-run your tests.**

sadhishsk avatar May 19 '24 12:05 sadhishsk

@sadhishsk let me see if I can replicate this in the pipeline

bhadmusautomates avatar May 19 '24 12:05 bhadmusautomates

@dayaneCsantos check my comment below. if it works for you, help me vote for my answer on stackoverflow as well https://stackoverflow.com/questions/77067015/cypress-allure-reports-are-not-getting-generated/78487640#78487640

Made changes as per this comment but its not working in my case.

Facing this issue while running the scripts on CICD but works fine locally!

Even following the instructions, it doesn't work. Thanks!

dayaneCsantos avatar May 20 '24 13:05 dayaneCsantos

The problem isn't actual anymore since the latest 3.0.0-beta versions. Please try the latest version and use the integration following the instructions from README file. If the problem persists for you – feel free to reopen the issue.

epszaw avatar Jul 05 '24 11:07 epszaw