Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better description handler for cucumber features #754

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/allure-cucumberjs/src/CucumberJSAllureReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,16 @@ export class CucumberJSAllureFormatter extends Formatter {
const currentTest = new AllureTest(this.allureRuntime, Date.now());
const thread = data.workerId || ALLURE_THREAD_NAME || process.pid.toString();
const fullName = `${pickle.uri}#${pickle.name}`;
// sometimes description starts with "Description:", but it's not actually required
baev marked this conversation as resolved.
Show resolved Hide resolved
const description = scenario?.description || doc?.feature?.description || "";
const testCaseId = md5(fullName);

this.testCaseStartedMap.set(data.id, data);
this.testCaseTestStepsResults.set(data.id, []);
this.currentTestsMap.set(data.id, currentTest);

currentTest.name = pickle.name;
currentTest.description = description.trim();
currentTest.fullName = fullName;
currentTest.testCaseId = testCaseId;

Expand Down
60 changes: 60 additions & 0 deletions packages/allure-cucumberjs/test/specs/description_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { expect } from "chai";
import { describe, it } from "mocha";
import { ITestFormatterOptions, runFeatures } from "../helpers/formatter_helpers";
import { buildSupportCodeLibrary } from "../helpers/runtime_helpers";

const dataSet: { [name: string]: ITestFormatterOptions } = {
featureDescription: {
supportCodeLibrary: buildSupportCodeLibrary(({ Given }) => {
Given("a step", () => {});
}),
sources: [
{
data: ["Feature: a", "Feature's description", " Scenario: b", " Given a step"].join("\n"),
uri: "a.feature",
},
],
},
scenarioDescription: {
supportCodeLibrary: buildSupportCodeLibrary(({ Given }) => {
Given("a step", () => {});
}),
sources: [
{
data: [
"Feature: a",
"Feature's description",
"",
" Scenario: b",
" Description: Scenario's description",
" Given a step",
].join("\n"),
uri: "a.feature",
},
],
},
};

describe("CucumberJSAllureReporter > description", () => {
describe("with feature description", () => {
it("uses feature description", async () => {
const results = await runFeatures(dataSet.featureDescription);

expect(results.tests).length(1);
const [testResult] = results.tests;

expect(testResult.description).eq("Feature's description");
});
});

describe("with scenario description", () => {
it("uses scenario description", async () => {
const results = await runFeatures(dataSet.scenarioDescription);

expect(results.tests).length(1);
const [testResult] = results.tests;

expect(testResult.description).eq("Description: Scenario's description");
});
});
});
Loading