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

Support allure metadata in playwright test and group annotations #1219

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 10 additions & 0 deletions packages/allure-playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ export class AllureReporter implements ReporterV2 {
result.labels!.push(...tags);
}

if ("annotations" in test) {
const annotations: Label[] = test.annotations?.filter(
(annotation) => annotation.type !== "skip" && annotation.type !== "fixme",
).map((annotation) => ({
name: annotation.type,
value: annotation.description!,
}));
result.labels!.push(...annotations);
}

if (project?.name) {
result.parameters!.push({ name: "Project", value: project.name });
}
Expand Down
104 changes: 104 additions & 0 deletions packages/allure-playwright/test/spec/annotations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, it } from "vitest";
import { LabelName } from "allure-js-commons";
import { runPlaywrightInlineTest } from "../utils.js";

it("should support skip annotation", async () => {
Expand Down Expand Up @@ -56,3 +57,106 @@ it("should support fixme annotation", async () => {
]),
);
});


it("should support allure metadata in playwright annotation", async () => {
const { tests } = await runPlaywrightInlineTest({
"sample.test.js": `
import { test } from '@playwright/test';
import { LabelName } from 'allure-js-commons';
test('test full report', {
annotation: [
{ type: "skip", description: "skipped via skip annotation" },
{ type: "fixme", description: "skipped via fixme annotation" },
{ type: "foo", description: "bar" },
{ type: LabelName.ALLURE_ID, description: "foo" },
{ type: LabelName.EPIC, description: "foo" },
{ type: LabelName.FEATURE, description: "foo" },
{ type: LabelName.LAYER, description: "foo" },
{ type: LabelName.OWNER, description: "foo" },
{ type: LabelName.PARENT_SUITE, description: "foo" },
{ type: LabelName.SUB_SUITE, description: "foo" },
{ type: LabelName.SUITE, description: "foo" },
{ type: LabelName.SEVERITY, description: "foo" },
{ type: LabelName.STORY, description: "foo" },
{ type: LabelName.TAG, description: "foo" },
],
}, async () => {
});
`,
});

expect(tests).toHaveLength(1);
expect(tests[0].labels).not.toContainEqual({ name: "fixme", value: "skipped via fixme annotation" });
expect(tests[0].labels).not.toContainEqual({ name: "skip", value: "skipped via skip annotation" });
expect(tests[0].labels).toContainEqual({ name: "foo", value: "bar" });
expect(tests[0].labels).toContainEqual({ name: LabelName.ALLURE_ID, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.EPIC, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.FEATURE, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.LAYER, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.OWNER, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.PARENT_SUITE, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.SUB_SUITE, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.SUITE, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.SEVERITY, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.STORY, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.TAG, value: "foo" });
});

it("should support allure metadata in playwright group annotation", async () => {
const { tests } = await runPlaywrightInlineTest({
"sample.test.js": `
import { test } from '@playwright/test';
import { LabelName } from 'allure-js-commons';
test.describe(
'nested',
{
annotation: [
{ type: "foo", description: "bar" },
{ type: LabelName.EPIC, description: "foo" },
{ type: LabelName.FEATURE, description: "foo" },
{ type: LabelName.LAYER, description: "foo" },
{ type: LabelName.OWNER, description: "foo" },
{ type: LabelName.PARENT_SUITE, description: "foo" },
{ type: LabelName.SUB_SUITE, description: "foo" },
{ type: LabelName.SUITE, description: "foo" },
{ type: LabelName.SEVERITY, description: "foo" },
{ type: LabelName.STORY, description: "foo" },
{ type: LabelName.TAG, description: "foo" },
],
},
() => {
test('test full report 1', async () => {
});
test('test full report 2', async () => {
});
},
);
`,
});

expect(tests).toHaveLength(2);
expect(tests[0].labels).toContainEqual({ name: "foo", value: "bar" });
expect(tests[0].labels).toContainEqual({ name: LabelName.EPIC, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.FEATURE, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.LAYER, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.OWNER, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.PARENT_SUITE, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.SUB_SUITE, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.SUITE, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.SEVERITY, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.STORY, value: "foo" });
expect(tests[0].labels).toContainEqual({ name: LabelName.TAG, value: "foo" });

expect(tests[1].labels).toContainEqual({ name: "foo", value: "bar" });
expect(tests[1].labels).toContainEqual({ name: LabelName.EPIC, value: "foo" });
expect(tests[1].labels).toContainEqual({ name: LabelName.FEATURE, value: "foo" });
expect(tests[1].labels).toContainEqual({ name: LabelName.LAYER, value: "foo" });
expect(tests[1].labels).toContainEqual({ name: LabelName.OWNER, value: "foo" });
expect(tests[1].labels).toContainEqual({ name: LabelName.PARENT_SUITE, value: "foo" });
expect(tests[1].labels).toContainEqual({ name: LabelName.SUB_SUITE, value: "foo" });
expect(tests[1].labels).toContainEqual({ name: LabelName.SUITE, value: "foo" });
expect(tests[1].labels).toContainEqual({ name: LabelName.SEVERITY, value: "foo" });
expect(tests[1].labels).toContainEqual({ name: LabelName.STORY, value: "foo" });
expect(tests[1].labels).toContainEqual({ name: LabelName.TAG, value: "foo" });
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ it("sets multiply tags", async () => {
{ name: LabelName.TAG, value: "TestInfo" },
{ name: LabelName.TAG, value: "some" },
{ name: LabelName.TAG, value: "other" },
{ name: LabelName.TAG, value: "other" },
{ name: LabelName.TAG, value: "tags" },
]),
}),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ it("sets multiply tags", async () => {
{ name: LabelName.TAG, value: "TestInfo" },
{ name: LabelName.TAG, value: "some" },
{ name: LabelName.TAG, value: "other" },
{ name: LabelName.TAG, value: "other" },
{ name: LabelName.TAG, value: "tags" },
]),
}),
]);
Expand Down
Loading