badeball / cypress-cucumber-preprocessor

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

Json report is not generated with Allure Writer #797

Closed novicovs closed 2 years ago

novicovs commented 2 years ago

Current behavior

When my automation is finished and I expect Json to be generated with active Allure Writer - createPickle() function returns an error. Removing/commenting part with allure writer fixes this.

Console log from cypress-cucumber-preprocessor:

{ function: 'createPickle', fileUrl: 'hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature', originalFile: 'node_modules/@badeball/cypress-cucumber-preprocessor/lib/create-tests.js', relativeFile: 'node_modules/@badeball/cypress-cucumber-preprocessor/lib/create-tests.js', absoluteFile: 'C:\\Users\\user\\IdeaProjects\\ui-functional/node_modules/@badeball/cypress-cucumber-preprocessor/lib/create-tests.js', line: 240, column: 1, whitespace: '    ', stack: 'Error\n' + '    at createPickle (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:6660:5)\n' + '    at createScenario (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:6577:9)\n' + '    at Suite.eval (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:6500:21)\n' + '    at createFeature (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:6496:5)\n' + '    at createTests (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:6876:9)\n' + '    at 1.C:/Users/user/IdeaProjects/ui-functional/cypress/stepdefs/addAuthorizationSteps.js (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:23:5)\n' + '    at o (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:1:265)\n' + '    at r (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:1:431)\n' + '    at eval (hostname/__cypress/tests?p=cypress\\features\\connectivity\\FacebookAds.feature:1:460)\n' + '    at eval (<anonymous>)' }

Desired behavior

Json should be generated (according to doc) with active Allure Writer.

Test code to reproduce

cypress.config.js

const {defineConfig} = require('cypress')
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const browserify = require("@badeball/cypress-cucumber-preprocessor/browserify");
const allureWriter = require("@shelex/cypress-allure-plugin/writer");

async function setupNodeEvents(on, config) {
    await preprocessor.addCucumberPreprocessorPlugin(on, config);

    on("file:preprocessor", browserify.default(config));

    allureWriter(on, config);

    return config
}

module.exports = defineConfig({
    projectId: 'cypress-e2e',
    downloadsFolder: 'downloads',
    env: {
        username: 'atf_user'
    },
    video: false,
    watchForFileChanges: false,
    reporter: 'junit',
    chromeWebSecurity: false,
    reporterOptions: {
        mochaFile: 'results/cypress-report-[hash].xml',
        toConsole: true,
    },
    numTestsKeptInMemory: 0,
    e2e: {
        baseUrl: 'hostname',
        specPattern: 'cypress/features/**/*.{feature,features}',
        setupNodeEvents
    },
})

package.json

{
  "name": "ui-functional",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "devDependencies": {
    "@badeball/cypress-cucumber-preprocessor": "^12.0.1",
    "@cypress/browserify-preprocessor": "^3.0.2",
    "@shelex/cypress-allure-plugin": "^2.28.4",
    "cucumber-json-merge": "^0.0.8",
    "cypress": "^10.3.1",
    "cypress-wait-until": "^1.7.2",
    "cypress-xpath": "^1.6.2"
  },
  "dependencies": {
    "cy2": "^2.0.0",
    "lodash": "^4.17.21"
  },
  "cypress-cucumber-preprocessor": {
    "stepDefinitions": "cypress/stepdefs/*.{js,ts}",
    "filterSpecs": true,
    "omitFiltered": true,
    "json": {
      "enabled": true,
      "output": "cypress/cucumber-json/cucumber-json.json",
      "formatter": "cucumber-json-formatter"
    },
    "messages": {
      "enabled": true,
      "output": "cypress/cucumber-json/messages.ndjson"
    }
  }
}

Versions

Checklist

badeball commented 2 years ago

Can't reproduce. You have to provide me a cloneable repository that illustrates the error.

novicovs commented 2 years ago

@badeball Hello, sir. As discussed above - I've prepated demo-repo.

Link to the repository: https://github.com/novicovs/cypress-cucumber-no-json

Steps to reproduce:

Actual result: There is 'createPickle' function error at the end of the logs and Json & ndJson are not generated.

Expected result: Should not be errors and Json & ndJson are generated.

badeball commented 2 years ago

Still can't reproduce. Have you actually tried running said repository yourself or have you been assuming it would reproduce the issue?

novicovs commented 2 years ago

Ofc I did testings before publishing demo-repo.

From my side the main framework and for demo one reproduce issue described above.

badeball commented 2 years ago

Yeah, I followed your steps and observed no error.

Either way, you're not going to get any JSON report because @shelex/cypress-allure-plugin appears to be incompatible with other plugins that listens to Cypress events such as after:run (this has come up before). The authors of the plugin must to modify it to play nicer with other plugins, similar to what I did in 15ae6d0, if this is to be supported. Feel free to open up an issue in their repository to bring it to their attention (reference this comment).