cucumber / cucumber-js

Cucumber for JavaScript
https://cucumber.io
MIT License
5.02k stars 1.09k forks source link

playWright+Cucumber+Allure - Run status is not showing in CLI if user configure format option as allure in cucumber.json #2304

Closed varshanharshank closed 1 year ago

varshanharshank commented 1 year ago

👓 What did you see?

playWright+Cucumber+Allure - Run cucumber.js test via CLI and it is not showing any failure in terminal if any of the test case is failed

This issue is happening if allure report is configured under format in the cucumber.json file:

{
  "default": {
    "paths": ["src/test/features"],
    "require": ["src/test/stepDefinitions/*.ts", "src/hooks/hooks.ts"],
    "requireModule": ["ts-node/register"],
    "publishQuiet": true,
    "format": [
      "./src/helper/report/allureReport.ts",
    ]
  }
}

But, we can see the fail message in terminal if cucumber report is configured under format in the cucumber.jsonfile:

{
  "default": {
    "paths": ["src/test/features"],
    "require": ["src/test/stepDefinitions/*.ts", "src/hooks/hooks.ts"],
    "requireModule": ["ts-node/register"],
    "publishQuiet": true,
    "format": [
      "html:cucumberReport/cucumber-report.html",
      "json:cucumberReport/cucumber-report.json"
    ]
  }
}

The below allureReport.ts file used

import { AllureRuntime, CucumberJSAllureFormatter } from 'allure-cucumberjs'

function Reporter(options: any) {
  return new CucumberJSAllureFormatter(
    options,
    new AllureRuntime({ resultsDir: './allure-results' }),
    {
      labels: [
        {
          name: 'epic',
          pattern: [/@feature:(.*)/],
        },
        {
          name: 'severity',
          pattern: [/@severity:(.*)/],
        },
      ],
      links: [
        {
          type: 'issue',
          pattern: [/@issue=(.*)/],
          urlTemplate: 'http://localhost:8080/issue/%s',
        },
        {
          type: 'tms',
          pattern: [/@tms=(.*)/],
          urlTemplate: 'http://localhost:8080/tms/%s',
        },
      ],
    }
  )
}

Reporter.prototype = Object.create(CucumberJSAllureFormatter.prototype)
Reporter.prototype.constructor = Reporter

exports.default = Reporter

✅ What did you expect to see?

CLI screen should show fail message irrespective any report (either cucmber or allure)

📦 Which tool/library version are you using?

Using the below package.json:

{
  "name": "lautomation",
  "version": "1.0.0",
  "description": "Automation",
  "main": "index.js",
  "scripts": {
    "test": "node_modules/.bin/cucumber-js test --tags '@smoke'",
    "report": "npx ts-node src/helper/report/cucumberReport.ts",
    "allure": "npx allure generate allure-results --clean -o allure-report && ./node_modules/.bin/allure open allure-report",
    "lint": "node_modules/.bin/eslint . --ext .ts"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@cucumber/cucumber": "^9.3.0"
  },
  "devDependencies": {
    "@playwright/test": "^1.36.2",
    "@typescript-eslint/eslint-plugin": "^6.2.0",
    "@typescript-eslint/parser": "^6.2.0",
    "allure-commandline": "^2.23.1",
    "allure-cucumberjs": "^2.4.0",
    "allure-js-commons": "^2.4.0",
    "eslint": "^8.46.0",
    "moment": "^2.29.4",
    "multiple-cucumber-html-reporter": "^3.4.0",
    "prettier": "^3.0.0",
    "ts-node": "^10.9.1",
    "typescript": "^5.1.6"
  }
}

🔬 How could we reproduce it?

Steps to reproduce the behavior: This is private report unable to share it here

  1. Create Playwright with BDD project
  2. In cucumber.json file, just mention the allureReport.ts file
  3. Run the following command node_modules/.bin/cucumber-js test --tags '@smoke

📚 Any additional context?


This text was originally generated from a template, then edited by hand. You can modify the template here.

davidjgoss commented 1 year ago

This would be best raised against the https://github.com/allure-framework/allure-js repo, but something I would note from the readme there:

If you want to retain default formatter add some dummy file as output:

cucumber-js --format ./path/to/reporter.js:./dummy.txt

It looks like the Allure formatter doesn't emit anything to the given stream, so you need to give it a file (the second part after the :) to point at otherwise it overrides the default progress/summary formatter which is why you get no terminal output.

varshanharshank commented 1 year ago

@davidjgoss Great. Thanks for the quick response. I tried the above step and it is working fine now.