Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 35bc17e

Browse filesBrowse files
committed
make extract metadata from string common
add title metadata support for vitest fix problem with stucked fixtures
1 parent 406cd34 commit 35bc17e
Copy full SHA for 35bc17e

File tree

Expand file treeCollapse file tree

9 files changed

+66
-38
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+66
-38
lines changed

‎packages/allure-js-commons/index.ts

Copy file name to clipboardExpand all lines: packages/allure-js-commons/index.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export {
5959
md5,
6060
readImageAsBase64,
6161
serialize,
62-
stripAscii
62+
stripAscii,
63+
extractMetadataFromString
6364
} from "./src/utils";
6465

6566
export { AllureRuntimeApiInterface } from "./src/framework";

‎packages/allure-js-commons/src/utils.ts

Copy file name to clipboardExpand all lines: packages/allure-js-commons/src/utils.ts
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,26 @@ export const serialize = (val: unknown): string => {
142142

143143
return (val as any).toString();
144144
};
145+
146+
export const extractMetadataFromString = (title: string): { labels: Label[]; cleanTitle: string } => {
147+
const labels = [] as Label[];
148+
149+
title.split(" ").forEach((val) => {
150+
const idValue = val.match(allureIdRegexp)?.groups?.id;
151+
152+
if (idValue) {
153+
labels.push({ name: LabelName.ALLURE_ID, value: idValue });
154+
}
155+
156+
const labelMatch = val.match(allureLabelRegexp);
157+
const { name, value } = labelMatch?.groups || {};
158+
159+
if (name && value) {
160+
labels?.push({ name, value });
161+
}
162+
});
163+
164+
const cleanTitle = title.replace(allureLabelRegexpGlobal, "").replace(allureIdRegexpGlobal, "").trim();
165+
166+
return { labels, cleanTitle };
167+
};

‎packages/allure-playwright/src/index.ts

Copy file name to clipboardExpand all lines: packages/allure-playwright/src/index.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ import {
3333
Status,
3434
StatusDetails,
3535
allureReportFolder,
36+
extractMetadataFromString,
3637
md5,
3738
readImageAsBase64,
3839
stripAscii,
3940
} from "allure-js-commons";
4041
import { ALLURE_IMAGEDIFF_CONTENT_TYPE, ALLURE_METADATA_CONTENT_TYPE } from "allure-js-commons/internal";
41-
import { extractMetadataFromString } from "./utils";
4242

4343
const diffEndRegexp = /-((expected)|(diff)|(actual))\.png$/;
4444
const stepAttachRegexp = /^allureattach_(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})_/i;

‎packages/allure-playwright/src/utils.ts

Copy file name to clipboardExpand all lines: packages/allure-playwright/src/utils.ts
-28Lines changed: 0 additions & 28 deletions
This file was deleted.

‎packages/allure-vitest/src/reporter.ts

Copy file name to clipboardExpand all lines: packages/allure-vitest/src/reporter.ts
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { File, Reporter, Task, Vitest } from "vitest";
44
import {
55
AllureGroup,
66
AllureRuntime,
7+
Label,
78
LabelName,
89
Link,
910
MessageAllureWriter,
1011
MetadataMessage,
1112
Stage,
1213
Status,
14+
extractMetadataFromString,
1315
} from "allure-js-commons";
1416
import { ALLURE_SKIPPED_BY_TEST_PLAN_LABEL } from "allure-js-commons/internal";
1517

@@ -104,18 +106,21 @@ export default class AllureReporter implements Reporter {
104106
return;
105107
}
106108

109+
const titleMetadata = extractMetadataFromString(task.name);
110+
const testDisplayName = currentTest.displayName || titleMetadata.cleanTitle;
107111
const links = currentTest.links ? this.processMetadataLinks(currentTest.links) : [];
108-
const test = parent.startTest(task.name, 0);
112+
const labels: Label[] = [].concat(currentTest.labels || []).concat(titleMetadata.labels );
113+
const test = parent.startTest(testDisplayName );
109114
const normalizedTestPath = normalize(task.file.filepath.replace(this.rootDir, ""))
110115
.replace(/^\//, "")
111116
.split("/")
112117
.filter((item: string) => item !== basename(task.file.filepath));
113118

114-
test.name = task.name;
115119
test.fullName = `${task.file.name}#${task.name}`;
116120

117121
test.applyMetadata({
118122
...currentTest,
123+
labels,
119124
links,
120125
});
121126
test.addLabel(LabelName.SUITE, parent.name);

‎packages/allure-vitest/src/setup.ts

Copy file name to clipboardExpand all lines: packages/allure-vitest/src/setup.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ const existsInTestPlan = (ctx: TaskContext, testPlan?: TestPlanV1) => {
1515

1616
return testPlan.tests.some(({ selector }) => {
1717
const splittedSelector = selector.split("#");
18+
const selectorMatched = splittedSelector[0] === testFileName && splittedSelector[1] === testName;
1819

19-
return splittedSelector[0] === testFileName && splittedSelector[1] === testName;
20+
return selectorMatched;
2021
});
2122
};
2223

‎packages/allure-vitest/test/spec/setup/testPlan.test.ts

Copy file name to clipboardExpand all lines: packages/allure-vitest/test/spec/setup/testPlan.test.ts
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ it("supports test plan", async () => {
1111
test("foo", () => {});
1212
1313
test("bar", () => {});
14+
15+
test("baz @allure.id=2", () => {});
1416
`,
1517
undefined,
1618
async (testDir) => {
@@ -21,8 +23,13 @@ it("supports test plan", async () => {
2123
JSON.stringify({
2224
tests: [
2325
{
26+
id: 1,
2427
selector: "sample.test.ts#foo",
2528
},
29+
{
30+
id: 2,
31+
selector: "sample.test.ts#baz @allure.id=2",
32+
},
2633
],
2734
}),
2835
);
@@ -31,6 +38,7 @@ it("supports test plan", async () => {
3138
},
3239
);
3340

34-
expect(tests).toHaveLength(1);
35-
expect(tests[0].name).toBe("foo");
41+
expect(tests).toHaveLength(2);
42+
expect(tests).toContainEqual(expect.objectContaining({ name: "foo", fullName: "sample.test.ts#foo" }));
43+
expect(tests).toContainEqual(expect.objectContaining({ name: "baz", fullName: "sample.test.ts#baz @allure.id=2" }));
3644
});
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect, it } from "vitest";
2+
import { LabelName } from "allure-js-commons";
3+
import { runVitestInlineTest } from "../utils.js";
4+
5+
it("handles title metadata", async () => {
6+
const { tests } = await runVitestInlineTest(
7+
`
8+
import { test } from "vitest";
9+
10+
test("foo @allure.id=1 @allure.label.foo=2", () => {});
11+
`,
12+
undefined,
13+
);
14+
15+
expect(tests).toHaveLength(1);
16+
expect(tests[0].labels).toContainEqual(expect.objectContaining({ name: LabelName.ALLURE_ID, value: "1" }));
17+
expect(tests[0].labels).toContainEqual(expect.objectContaining({ name: "foo", value: "2" }));
18+
});

‎packages/allure-vitest/test/utils.ts

Copy file name to clipboardExpand all lines: packages/allure-vitest/test/utils.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { fork } from "node:child_process";
22
import { randomUUID } from "node:crypto";
3-
import { mkdir, rm, rmdir, writeFile } from "node:fs/promises";
3+
import { mkdir, rm, writeFile } from "node:fs/promises";
44
import { dirname, join } from "node:path";
55
import { fileURLToPath } from "url";
66
import type { AllureResults, TestResult, TestResultContainer } from "allure-js-commons";
@@ -96,8 +96,8 @@ export const runVitestInlineTest = async (
9696
});
9797

9898
return new Promise((resolve, reject) => {
99-
testProcess.on("close", async () => {
100-
await rmdir(testDir, { recursive: true });
99+
testProcess.on("exit", async () => {
100+
await rm(testDir, { recursive: true });
101101

102102
return resolve(res);
103103
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.