Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions packages/allure-codeceptjs/test/spec/labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ it("should add package label", async () => {
labels: expect.arrayContaining([
{
name: "package",
value: "nested.login.test.js",
value: "dummy.nested.login.test.js",
},
]),
}),
Expand All @@ -82,7 +82,7 @@ it("should add package label", async () => {
labels: expect.arrayContaining([
{
name: "package",
value: "nested.login.test.js",
value: "dummy.nested.login.test.js",
},
]),
}),
Expand Down Expand Up @@ -110,21 +110,21 @@ it("should not depend on CWD", async () => {
expect.arrayContaining([
expect.objectContaining({
name: "failed-scenario",
fullName: "nested/login.test.js: login-feature > failed-scenario",
fullName: "dummy:nested/login.test.js: login-feature > failed-scenario",
labels: expect.arrayContaining([
{
name: "package",
value: "nested.login.test.js",
value: "dummy.nested.login.test.js",
},
]),
}),
expect.objectContaining({
name: "passed-scenario",
fullName: "nested/login.test.js: login-feature > passed-scenario",
fullName: "dummy:nested/login.test.js: login-feature > passed-scenario",
labels: expect.arrayContaining([
{
name: "package",
value: "nested.login.test.js",
value: "dummy.nested.login.test.js",
},
]),
}),
Expand Down
35 changes: 23 additions & 12 deletions packages/allure-codeceptjs/test/spec/simple.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, it } from "vitest";
import { Stage, Status } from "allure-js-commons";
import { md5 } from "allure-js-commons/sdk/reporter";
import { runCodeceptJsInlineTest } from "../utils.js";

it("handles simple scenarios", async () => {
Expand All @@ -22,35 +23,45 @@ it("handles simple scenarios", async () => {
expect.objectContaining({
status: Status.PASSED,
name: "logout-scenario1",
fullName: "logout.test.js: logout-feature > logout-scenario1",
testCaseId: "b1cbd7e3cf91f03aa08b912903a297a0",
historyId: "b1cbd7e3cf91f03aa08b912903a297a0:d41d8cd98f00b204e9800998ecf8427e",
fullName: "dummy:logout.test.js: logout-feature > logout-scenario1",
testCaseId: "eda0335a13829baf445a25f7f3183813",
historyId: "eda0335a13829baf445a25f7f3183813:d41d8cd98f00b204e9800998ecf8427e",
}),

expect.objectContaining({
status: Status.PASSED,
stage: Stage.FINISHED,
name: "logout-scenario2",
fullName: "logout.test.js: logout-feature > logout-scenario2",
testCaseId: "cf2fc4ae2f9143145a3ee3bae6dff66b",
historyId: "cf2fc4ae2f9143145a3ee3bae6dff66b:d41d8cd98f00b204e9800998ecf8427e",
fullName: "dummy:logout.test.js: logout-feature > logout-scenario2",
testCaseId: "bf828e36674defe3995294bf2aa475d7",
historyId: "bf828e36674defe3995294bf2aa475d7:d41d8cd98f00b204e9800998ecf8427e",
}),
expect.objectContaining({
status: Status.PASSED,
stage: Stage.FINISHED,
name: "login-scenario1",
fullName: "nested/login.test.js: login-feature > login-scenario1",
testCaseId: "157be92d422d04e9b79d6d2fbb5020de",
historyId: "157be92d422d04e9b79d6d2fbb5020de:d41d8cd98f00b204e9800998ecf8427e",
fullName: "dummy:nested/login.test.js: login-feature > login-scenario1",
testCaseId: "090a2afe525cb9897eed2ea2543913a1",
historyId: "090a2afe525cb9897eed2ea2543913a1:d41d8cd98f00b204e9800998ecf8427e",
}),
expect.objectContaining({
status: Status.PASSED,
stage: Stage.FINISHED,
name: "login-scenario2",
fullName: "nested/login.test.js: login-feature > login-scenario2",
testCaseId: "fbb987bcdcd21440bb0a4f4d79711387",
historyId: "fbb987bcdcd21440bb0a4f4d79711387:d41d8cd98f00b204e9800998ecf8427e",
fullName: "dummy:nested/login.test.js: login-feature > login-scenario2",
testCaseId: "7f8a96c5d7ea3db2f75c8dee77f732c2",
historyId: "7f8a96c5d7ea3db2f75c8dee77f732c2:d41d8cd98f00b204e9800998ecf8427e",
}),
]),
);

const logoutScenario = tests.find((test) => test.name === "logout-scenario1");
expect(logoutScenario?.labels).toEqual(
expect.arrayContaining([
{
name: "_fallbackTestCaseId",
value: md5(JSON.stringify(["logout.test.js", "logout-feature", "logout-scenario1"])),
},
]),
);
});
8 changes: 4 additions & 4 deletions packages/allure-codeceptjs/test/spec/skipped.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ it("doesn't report skipped features and steps", async () => {
expect(tests).toEqual(
expect.arrayContaining([
expect.objectContaining({
fullName: "skipped_feature1.test.js: logout-feature1 > logout-scenario1",
fullName: "dummy:skipped_feature1.test.js: logout-feature1 > logout-scenario1",
name: "logout-scenario1",
status: Status.SKIPPED,
statusDetails: expect.objectContaining({
message: "Test skipped",
}),
}),
expect.objectContaining({
fullName: "skipped_feature2.test.js: logout-feature2 > logout-scenario1",
fullName: "dummy:skipped_feature2.test.js: logout-feature2 > logout-scenario1",
name: "logout-scenario1",
status: Status.SKIPPED,
statusDetails: expect.objectContaining({
message: "Test skipped",
}),
}),
expect.objectContaining({
fullName: "skipped_scenario1.test.js: logout-feature3 > logout-scenario1",
fullName: "dummy:skipped_scenario1.test.js: logout-feature3 > logout-scenario1",
name: "logout-scenario1",
status: Status.SKIPPED,
statusDetails: expect.objectContaining({
message: "Test skipped",
}),
}),
expect.objectContaining({
fullName: "skipped_scenario2.test.js: logout-feature4 > logout-scenario1",
fullName: "dummy:skipped_scenario2.test.js: logout-feature4 > logout-scenario1",
name: "logout-scenario1",
status: Status.SKIPPED,
statusDetails: expect.objectContaining({
Expand Down
10 changes: 5 additions & 5 deletions packages/allure-codeceptjs/test/spec/testplan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ it("should support test plan", async () => {
selector: "invalid",
},
{
selector: "nested/login.test.js: login-feature > login-scenario1",
selector: "dummy:nested/login.test.js: login-feature > login-scenario1",
},
{
selector: "logout.test.js: logout-feature > logout-scenario1",
selector: "dummy:logout.test.js: logout-feature > logout-scenario1",
},
],
};
Expand Down Expand Up @@ -47,19 +47,19 @@ it("should support test plan", async () => {
expect.objectContaining({
status: Status.PASSED,
name: "logout-scenario1",
fullName: "logout.test.js: logout-feature > logout-scenario1",
fullName: "dummy:logout.test.js: logout-feature > logout-scenario1",
}),
expect.objectContaining({
status: Status.PASSED,
stage: Stage.FINISHED,
name: "login-scenario1",
fullName: "nested/login.test.js: login-feature > login-scenario1",
fullName: "dummy:nested/login.test.js: login-feature > login-scenario1",
}),
expect.objectContaining({
status: Status.PASSED,
stage: Stage.FINISHED,
name: "login-scenario3",
fullName: "nested/login.test.js: login-feature > login-scenario3 @allure.id:321",
fullName: "dummy:nested/login.test.js: login-feature > login-scenario3 @allure.id:321",
}),
]),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-codeceptjs/test/spec/titlePath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ it("should assign titlePath property to the test result", async () => {

const [tr] = tests;

expect(tr.titlePath).toEqual(["spec", "test", "sample.test.js", "login-feature"]);
expect(tr.titlePath).toEqual(["dummy", "spec", "test", "sample.test.js", "login-feature"]);
});
2 changes: 1 addition & 1 deletion packages/allure-codeceptjs/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const runCodeceptJsInlineTest = async (
): Promise<RunResult> => {
const testFiles = {
// package.json is used to find project root in case of absolute file paths are used
"package.json": '{ "name": "dummy"}',
"package.json": JSON.stringify({ name: "dummy" }),
"codecept.conf.js": await readFile(resolvePath(__dirname, "./samples/codecept.conf.js"), "utf-8"),
"helper.js": await readFile(resolvePath(__dirname, "./samples/helper.js"), "utf-8"),
...files,
Expand Down
7 changes: 3 additions & 4 deletions packages/allure-cucumberjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Before, BeforeAll, world } from "@cucumber/cucumber";
import { includedInTestPlan } from "allure-js-commons/sdk/reporter";
import { parseTestPlan } from "allure-js-commons/sdk/reporter";
import { getProjectName, includedInTestPlan, parseTestPlan } from "allure-js-commons/sdk/reporter";
import { setGlobalTestRuntime } from "allure-js-commons/sdk/runtime";
import { AllureCucumberWorld } from "./legacy.js";
import { AllureCucumberTestRuntime } from "./runtime.js";
Expand All @@ -17,8 +16,8 @@ Before({ name: "ALLURE_FIXTURE_IGNORE" }, (scenario) => {
}
const pickle = scenario.pickle;
const posixPath = getPosixPathRelativeToProjectRoot(pickle);

const fullName = `${posixPath}#${pickle.name}`;
const projectName = getProjectName();
const fullName = `${projectName ? `${projectName}:${posixPath}` : posixPath}#${pickle.name}`;
const tags = pickle.tags.map((tag) => tag.name);

if (!includedInTestPlan(testPlan, { fullName, tags })) {
Expand Down
13 changes: 10 additions & 3 deletions packages/allure-cucumberjs/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import {
createDefaultWriter,
createStepResult,
getEnvironmentLabels,
getFallbackTestCaseIdLabel,
getFrameworkLabel,
getHostLabel,
getLanguageLabel,
getPackageLabel,
getProjectName,
getThreadLabel,
getWorstTestStepResult,
md5,
Expand Down Expand Up @@ -238,9 +240,12 @@ export default class AllureCucumberReporter extends Formatter {
const [scenarioId, ...astIds] = pickle.astNodeIds;
const scenario = this.scenarioMap.get(scenarioId);

const projectName = getProjectName();
const posixPath = getPosixPathRelativeToProjectRoot(pickle);
const fullName = `${posixPath}#${pickle.name}`;
const testCaseId = md5(`${posixPath}#${scenario?.name ?? pickle.name}`);
const fullNameBase = projectName ? `${projectName}:${posixPath}` : posixPath;
const fullName = `${fullNameBase}#${pickle.name}`;
const testCaseId = md5(`${fullNameBase}#${scenario?.name ?? pickle.name}`);
const legacyTestCaseId = md5(`${posixPath}#${scenario?.name ?? pickle.name}`);
const result: Partial<TestResult> = {
name: pickle.name,
description: (scenario?.description || doc?.feature?.description || "").trim(),
Expand All @@ -256,6 +261,7 @@ export default class AllureCucumberReporter extends Formatter {
getLanguageLabel(),
getFrameworkLabel("cucumberjs"),
getPackageLabel(getPathRelativeToProjectRoot(pickle)),
getFallbackTestCaseIdLabel(legacyTestCaseId),
getHostLabel(),
getThreadLabel(data.workerId),
);
Expand All @@ -274,10 +280,11 @@ export default class AllureCucumberReporter extends Formatter {
const scenarioLinks = this.parseTagsLinks(scenario?.tags || []);

// remove feature file name from the title path
result.titlePath = posixPath
const titlePath = posixPath
.split("/")
.slice(0, -1)
.concat([doc?.feature?.name].filter(Boolean) as string[]);
result.titlePath = projectName ? [projectName, ...titlePath] : titlePath;
result.labels!.push(...featureLabels, ...scenarioLabels, ...pickleLabels);
result.links!.push(...featureLinks, ...scenarioLinks);

Expand Down
6 changes: 3 additions & 3 deletions packages/allure-cucumberjs/test/spec/duration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ it("should set correct timings for tests", async () => {
expect(tr.name).toEqual("scenario with sleep");
expect(tr.start).toBeGreaterThanOrEqual(before);
expect(tr.start).toBeLessThanOrEqual(after);
expect(tr.stop).toBeGreaterThanOrEqual(tr.start!);
expect(tr.stop).toBeGreaterThanOrEqual(tr.start);
});

it("should set correct timings for steps", async () => {
Expand All @@ -25,7 +25,7 @@ it("should set correct timings for steps", async () => {
expect(s1.name).toEqual("Given a sleep");
expect(s1.start).toBeGreaterThanOrEqual(before);
expect(s1.start).toBeLessThanOrEqual(after);
expect(s1.stop).toBeGreaterThanOrEqual(s1.start!);
expect(s1.stop).toBeGreaterThanOrEqual(s1.start);
expect(s1.stop! - s1.start!).toBeGreaterThanOrEqual(100);
});

Expand All @@ -39,6 +39,6 @@ it("should set correct timings for hooks", async () => {
const [f1] = trc.befores;
expect(f1.start).toBeGreaterThanOrEqual(before);
expect(f1.start).toBeLessThanOrEqual(after);
expect(f1.stop).toBeGreaterThanOrEqual(f1.start!);
expect(f1.stop).toBeGreaterThanOrEqual(f1.start);
expect(f1.stop! - f1.start!).toBeGreaterThanOrEqual(80);
});
69 changes: 69 additions & 0 deletions packages/allure-cucumberjs/test/spec/fullName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { expect, it } from "vitest";
import { Status } from "allure-js-commons";
import { md5 } from "allure-js-commons/sdk/reporter";
import { runCucumberInlineTest } from "../utils.js";

it("should set full name", async () => {
const { tests } = await runCucumberInlineTest(["simple"], ["simple"]);

expect(tests).toHaveLength(3);
const passedTest = tests.find((test) => test.name === "passed");
expect(passedTest?.labels).toEqual(
expect.arrayContaining([
{
name: "_fallbackTestCaseId",
value: md5("features/simple.feature#passed"),
},
]),
);
expect(tests).toContainEqual(
expect.objectContaining({
name: "passed",
fullName: "dummy:features/simple.feature#passed",
status: Status.PASSED,
}),
);
expect(tests).toContainEqual(
expect.objectContaining({
name: "failed",
fullName: "dummy:features/simple.feature#failed",
status: Status.FAILED,
}),
);
expect(tests).toContainEqual(
expect.objectContaining({
name: "broken",
fullName: "dummy:features/simple.feature#broken",
status: Status.BROKEN,
}),
);
});

it("should calculate fullName in a CWD-independent manner", async () => {
const { tests } = await runCucumberInlineTest(["nested/simple"], ["simple"], {
cwd: "features/nested",
});

expect(tests).toHaveLength(3);
expect(tests).toContainEqual(
expect.objectContaining({
name: "passed",
fullName: "dummy:features/nested/simple.feature#passed",
status: Status.PASSED,
}),
);
expect(tests).toContainEqual(
expect.objectContaining({
name: "failed",
fullName: "dummy:features/nested/simple.feature#failed",
status: Status.FAILED,
}),
);
expect(tests).toContainEqual(
expect.objectContaining({
name: "broken",
fullName: "dummy:features/nested/simple.feature#broken",
status: Status.BROKEN,
}),
);
});
Loading
Loading