Skip to content

Commit 60eeb21

Browse files
committed
fix(allure-js): fix test duplicating by adding package name to path
1 parent 7428daa commit 60eeb21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+773
-279
lines changed

packages/allure-codeceptjs/test/spec/labels.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ it("should add package label", async () => {
7373
labels: expect.arrayContaining([
7474
{
7575
name: "package",
76-
value: "nested.login.test.js",
76+
value: "dummy.nested.login.test.js",
7777
},
7878
]),
7979
}),
@@ -82,7 +82,7 @@ it("should add package label", async () => {
8282
labels: expect.arrayContaining([
8383
{
8484
name: "package",
85-
value: "nested.login.test.js",
85+
value: "dummy.nested.login.test.js",
8686
},
8787
]),
8888
}),
@@ -110,21 +110,21 @@ it("should not depend on CWD", async () => {
110110
expect.arrayContaining([
111111
expect.objectContaining({
112112
name: "failed-scenario",
113-
fullName: "nested/login.test.js: login-feature > failed-scenario",
113+
fullName: "dummy:nested/login.test.js: login-feature > failed-scenario",
114114
labels: expect.arrayContaining([
115115
{
116116
name: "package",
117-
value: "nested.login.test.js",
117+
value: "dummy.nested.login.test.js",
118118
},
119119
]),
120120
}),
121121
expect.objectContaining({
122122
name: "passed-scenario",
123-
fullName: "nested/login.test.js: login-feature > passed-scenario",
123+
fullName: "dummy:nested/login.test.js: login-feature > passed-scenario",
124124
labels: expect.arrayContaining([
125125
{
126126
name: "package",
127-
value: "nested.login.test.js",
127+
value: "dummy.nested.login.test.js",
128128
},
129129
]),
130130
}),

packages/allure-codeceptjs/test/spec/simple.test.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect, it } from "vitest";
22
import { Stage, Status } from "allure-js-commons";
3+
import { md5 } from "allure-js-commons/sdk/reporter";
34
import { runCodeceptJsInlineTest } from "../utils.js";
45

56
it("handles simple scenarios", async () => {
@@ -22,35 +23,45 @@ it("handles simple scenarios", async () => {
2223
expect.objectContaining({
2324
status: Status.PASSED,
2425
name: "logout-scenario1",
25-
fullName: "logout.test.js: logout-feature > logout-scenario1",
26-
testCaseId: "b1cbd7e3cf91f03aa08b912903a297a0",
27-
historyId: "b1cbd7e3cf91f03aa08b912903a297a0:d41d8cd98f00b204e9800998ecf8427e",
26+
fullName: "dummy:logout.test.js: logout-feature > logout-scenario1",
27+
testCaseId: "eda0335a13829baf445a25f7f3183813",
28+
historyId: "eda0335a13829baf445a25f7f3183813:d41d8cd98f00b204e9800998ecf8427e",
2829
}),
2930

3031
expect.objectContaining({
3132
status: Status.PASSED,
3233
stage: Stage.FINISHED,
3334
name: "logout-scenario2",
34-
fullName: "logout.test.js: logout-feature > logout-scenario2",
35-
testCaseId: "cf2fc4ae2f9143145a3ee3bae6dff66b",
36-
historyId: "cf2fc4ae2f9143145a3ee3bae6dff66b:d41d8cd98f00b204e9800998ecf8427e",
35+
fullName: "dummy:logout.test.js: logout-feature > logout-scenario2",
36+
testCaseId: "bf828e36674defe3995294bf2aa475d7",
37+
historyId: "bf828e36674defe3995294bf2aa475d7:d41d8cd98f00b204e9800998ecf8427e",
3738
}),
3839
expect.objectContaining({
3940
status: Status.PASSED,
4041
stage: Stage.FINISHED,
4142
name: "login-scenario1",
42-
fullName: "nested/login.test.js: login-feature > login-scenario1",
43-
testCaseId: "157be92d422d04e9b79d6d2fbb5020de",
44-
historyId: "157be92d422d04e9b79d6d2fbb5020de:d41d8cd98f00b204e9800998ecf8427e",
43+
fullName: "dummy:nested/login.test.js: login-feature > login-scenario1",
44+
testCaseId: "090a2afe525cb9897eed2ea2543913a1",
45+
historyId: "090a2afe525cb9897eed2ea2543913a1:d41d8cd98f00b204e9800998ecf8427e",
4546
}),
4647
expect.objectContaining({
4748
status: Status.PASSED,
4849
stage: Stage.FINISHED,
4950
name: "login-scenario2",
50-
fullName: "nested/login.test.js: login-feature > login-scenario2",
51-
testCaseId: "fbb987bcdcd21440bb0a4f4d79711387",
52-
historyId: "fbb987bcdcd21440bb0a4f4d79711387:d41d8cd98f00b204e9800998ecf8427e",
51+
fullName: "dummy:nested/login.test.js: login-feature > login-scenario2",
52+
testCaseId: "7f8a96c5d7ea3db2f75c8dee77f732c2",
53+
historyId: "7f8a96c5d7ea3db2f75c8dee77f732c2:d41d8cd98f00b204e9800998ecf8427e",
5354
}),
5455
]),
5556
);
57+
58+
const logoutScenario = tests.find((test) => test.name === "logout-scenario1");
59+
expect(logoutScenario?.labels).toEqual(
60+
expect.arrayContaining([
61+
{
62+
name: "_fallbackTestCaseId",
63+
value: md5(JSON.stringify(["logout.test.js", "logout-feature", "logout-scenario1"])),
64+
},
65+
]),
66+
);
5667
});

packages/allure-codeceptjs/test/spec/skipped.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,31 @@ it("doesn't report skipped features and steps", async () => {
2626
expect(tests).toEqual(
2727
expect.arrayContaining([
2828
expect.objectContaining({
29-
fullName: "skipped_feature1.test.js: logout-feature1 > logout-scenario1",
29+
fullName: "dummy:skipped_feature1.test.js: logout-feature1 > logout-scenario1",
3030
name: "logout-scenario1",
3131
status: Status.SKIPPED,
3232
statusDetails: expect.objectContaining({
3333
message: "Test skipped",
3434
}),
3535
}),
3636
expect.objectContaining({
37-
fullName: "skipped_feature2.test.js: logout-feature2 > logout-scenario1",
37+
fullName: "dummy:skipped_feature2.test.js: logout-feature2 > logout-scenario1",
3838
name: "logout-scenario1",
3939
status: Status.SKIPPED,
4040
statusDetails: expect.objectContaining({
4141
message: "Test skipped",
4242
}),
4343
}),
4444
expect.objectContaining({
45-
fullName: "skipped_scenario1.test.js: logout-feature3 > logout-scenario1",
45+
fullName: "dummy:skipped_scenario1.test.js: logout-feature3 > logout-scenario1",
4646
name: "logout-scenario1",
4747
status: Status.SKIPPED,
4848
statusDetails: expect.objectContaining({
4949
message: "Test skipped",
5050
}),
5151
}),
5252
expect.objectContaining({
53-
fullName: "skipped_scenario2.test.js: logout-feature4 > logout-scenario1",
53+
fullName: "dummy:skipped_scenario2.test.js: logout-feature4 > logout-scenario1",
5454
name: "logout-scenario1",
5555
status: Status.SKIPPED,
5656
statusDetails: expect.objectContaining({

packages/allure-codeceptjs/test/spec/testplan.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ it("should support test plan", async () => {
1212
selector: "invalid",
1313
},
1414
{
15-
selector: "nested/login.test.js: login-feature > login-scenario1",
15+
selector: "dummy:nested/login.test.js: login-feature > login-scenario1",
1616
},
1717
{
18-
selector: "logout.test.js: logout-feature > logout-scenario1",
18+
selector: "dummy:logout.test.js: logout-feature > logout-scenario1",
1919
},
2020
],
2121
};
@@ -47,19 +47,19 @@ it("should support test plan", async () => {
4747
expect.objectContaining({
4848
status: Status.PASSED,
4949
name: "logout-scenario1",
50-
fullName: "logout.test.js: logout-feature > logout-scenario1",
50+
fullName: "dummy:logout.test.js: logout-feature > logout-scenario1",
5151
}),
5252
expect.objectContaining({
5353
status: Status.PASSED,
5454
stage: Stage.FINISHED,
5555
name: "login-scenario1",
56-
fullName: "nested/login.test.js: login-feature > login-scenario1",
56+
fullName: "dummy:nested/login.test.js: login-feature > login-scenario1",
5757
}),
5858
expect.objectContaining({
5959
status: Status.PASSED,
6060
stage: Stage.FINISHED,
6161
name: "login-scenario3",
62-
fullName: "nested/login.test.js: login-feature > login-scenario3 @allure.id:321",
62+
fullName: "dummy:nested/login.test.js: login-feature > login-scenario3 @allure.id:321",
6363
}),
6464
]),
6565
);

packages/allure-codeceptjs/test/spec/titlePath.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ it("should assign titlePath property to the test result", async () => {
1313

1414
const [tr] = tests;
1515

16-
expect(tr.titlePath).toEqual(["spec", "test", "sample.test.js", "login-feature"]);
16+
expect(tr.titlePath).toEqual(["dummy", "spec", "test", "sample.test.js", "login-feature"]);
1717
});

packages/allure-codeceptjs/test/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const runCodeceptJsInlineTest = async (
2424
): Promise<RunResult> => {
2525
const testFiles = {
2626
// package.json is used to find project root in case of absolute file paths are used
27-
"package.json": '{ "name": "dummy"}',
27+
"package.json": JSON.stringify({ name: "dummy" }),
2828
"codecept.conf.js": await readFile(resolvePath(__dirname, "./samples/codecept.conf.js"), "utf-8"),
2929
"helper.js": await readFile(resolvePath(__dirname, "./samples/helper.js"), "utf-8"),
3030
...files,

packages/allure-cucumberjs/src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Before, BeforeAll, world } from "@cucumber/cucumber";
2-
import { includedInTestPlan } from "allure-js-commons/sdk/reporter";
3-
import { parseTestPlan } from "allure-js-commons/sdk/reporter";
2+
import { getProjectName, includedInTestPlan, parseTestPlan } from "allure-js-commons/sdk/reporter";
43
import { setGlobalTestRuntime } from "allure-js-commons/sdk/runtime";
54
import { AllureCucumberWorld } from "./legacy.js";
65
import { AllureCucumberTestRuntime } from "./runtime.js";
@@ -17,8 +16,8 @@ Before({ name: "ALLURE_FIXTURE_IGNORE" }, (scenario) => {
1716
}
1817
const pickle = scenario.pickle;
1918
const posixPath = getPosixPathRelativeToProjectRoot(pickle);
20-
21-
const fullName = `${posixPath}#${pickle.name}`;
19+
const projectName = getProjectName();
20+
const fullName = `${projectName ? `${projectName}:${posixPath}` : posixPath}#${pickle.name}`;
2221
const tags = pickle.tags.map((tag) => tag.name);
2322

2423
if (!includedInTestPlan(testPlan, { fullName, tags })) {

packages/allure-cucumberjs/src/reporter.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import {
2020
createDefaultWriter,
2121
createStepResult,
2222
getEnvironmentLabels,
23+
getFallbackTestCaseIdLabel,
2324
getFrameworkLabel,
2425
getHostLabel,
2526
getLanguageLabel,
2627
getPackageLabel,
28+
getProjectName,
2729
getThreadLabel,
2830
getWorstTestStepResult,
2931
md5,
@@ -238,9 +240,12 @@ export default class AllureCucumberReporter extends Formatter {
238240
const [scenarioId, ...astIds] = pickle.astNodeIds;
239241
const scenario = this.scenarioMap.get(scenarioId);
240242

243+
const projectName = getProjectName();
241244
const posixPath = getPosixPathRelativeToProjectRoot(pickle);
242-
const fullName = `${posixPath}#${pickle.name}`;
243-
const testCaseId = md5(`${posixPath}#${scenario?.name ?? pickle.name}`);
245+
const fullNameBase = projectName ? `${projectName}:${posixPath}` : posixPath;
246+
const fullName = `${fullNameBase}#${pickle.name}`;
247+
const testCaseId = md5(`${fullNameBase}#${scenario?.name ?? pickle.name}`);
248+
const legacyTestCaseId = md5(`${posixPath}#${scenario?.name ?? pickle.name}`);
244249
const result: Partial<TestResult> = {
245250
name: pickle.name,
246251
description: (scenario?.description || doc?.feature?.description || "").trim(),
@@ -256,6 +261,7 @@ export default class AllureCucumberReporter extends Formatter {
256261
getLanguageLabel(),
257262
getFrameworkLabel("cucumberjs"),
258263
getPackageLabel(getPathRelativeToProjectRoot(pickle)),
264+
getFallbackTestCaseIdLabel(legacyTestCaseId),
259265
getHostLabel(),
260266
getThreadLabel(data.workerId),
261267
);
@@ -274,10 +280,11 @@ export default class AllureCucumberReporter extends Formatter {
274280
const scenarioLinks = this.parseTagsLinks(scenario?.tags || []);
275281

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

packages/allure-cucumberjs/test/spec/duration.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ it("should set correct timings for tests", async () => {
1111
expect(tr.name).toEqual("scenario with sleep");
1212
expect(tr.start).toBeGreaterThanOrEqual(before);
1313
expect(tr.start).toBeLessThanOrEqual(after);
14-
expect(tr.stop).toBeGreaterThanOrEqual(tr.start!);
14+
expect(tr.stop).toBeGreaterThanOrEqual(tr.start);
1515
});
1616

1717
it("should set correct timings for steps", async () => {
@@ -25,7 +25,7 @@ it("should set correct timings for steps", async () => {
2525
expect(s1.name).toEqual("Given a sleep");
2626
expect(s1.start).toBeGreaterThanOrEqual(before);
2727
expect(s1.start).toBeLessThanOrEqual(after);
28-
expect(s1.stop).toBeGreaterThanOrEqual(s1.start!);
28+
expect(s1.stop).toBeGreaterThanOrEqual(s1.start);
2929
expect(s1.stop! - s1.start!).toBeGreaterThanOrEqual(100);
3030
});
3131

@@ -39,6 +39,6 @@ it("should set correct timings for hooks", async () => {
3939
const [f1] = trc.befores;
4040
expect(f1.start).toBeGreaterThanOrEqual(before);
4141
expect(f1.start).toBeLessThanOrEqual(after);
42-
expect(f1.stop).toBeGreaterThanOrEqual(f1.start!);
42+
expect(f1.stop).toBeGreaterThanOrEqual(f1.start);
4343
expect(f1.stop! - f1.start!).toBeGreaterThanOrEqual(80);
4444
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { expect, it } from "vitest";
2+
import { Status } from "allure-js-commons";
3+
import { md5 } from "allure-js-commons/sdk/reporter";
4+
import { runCucumberInlineTest } from "../utils.js";
5+
6+
it("should set full name", async () => {
7+
const { tests } = await runCucumberInlineTest(["simple"], ["simple"]);
8+
9+
expect(tests).toHaveLength(3);
10+
const passedTest = tests.find((test) => test.name === "passed");
11+
expect(passedTest?.labels).toEqual(
12+
expect.arrayContaining([
13+
{
14+
name: "_fallbackTestCaseId",
15+
value: md5("features/simple.feature#passed"),
16+
},
17+
]),
18+
);
19+
expect(tests).toContainEqual(
20+
expect.objectContaining({
21+
name: "passed",
22+
fullName: "dummy:features/simple.feature#passed",
23+
status: Status.PASSED,
24+
}),
25+
);
26+
expect(tests).toContainEqual(
27+
expect.objectContaining({
28+
name: "failed",
29+
fullName: "dummy:features/simple.feature#failed",
30+
status: Status.FAILED,
31+
}),
32+
);
33+
expect(tests).toContainEqual(
34+
expect.objectContaining({
35+
name: "broken",
36+
fullName: "dummy:features/simple.feature#broken",
37+
status: Status.BROKEN,
38+
}),
39+
);
40+
});
41+
42+
it("should calculate fullName in a CWD-independent manner", async () => {
43+
const { tests } = await runCucumberInlineTest(["nested/simple"], ["simple"], {
44+
cwd: "features/nested",
45+
});
46+
47+
expect(tests).toHaveLength(3);
48+
expect(tests).toContainEqual(
49+
expect.objectContaining({
50+
name: "passed",
51+
fullName: "dummy:features/nested/simple.feature#passed",
52+
status: Status.PASSED,
53+
}),
54+
);
55+
expect(tests).toContainEqual(
56+
expect.objectContaining({
57+
name: "failed",
58+
fullName: "dummy:features/nested/simple.feature#failed",
59+
status: Status.FAILED,
60+
}),
61+
);
62+
expect(tests).toContainEqual(
63+
expect.objectContaining({
64+
name: "broken",
65+
fullName: "dummy:features/nested/simple.feature#broken",
66+
status: Status.BROKEN,
67+
}),
68+
);
69+
});

0 commit comments

Comments
 (0)