allure-js: Allure for Cypress not working

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

  • I agree to follow this project’s Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 21 (4 by maintainers)

Commits related to this issue

Most upvoted comments

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 allure-cypress@2.14.0 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.

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

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

import "allure-cypress";

@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!

@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

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

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)