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 0acc9c9

Browse filesBrowse files
authored
add support for beforeAll and afterAll vitest fixtures (via #993)
1 parent d890042 commit 0acc9c9
Copy full SHA for 0acc9c9
Expand file treeCollapse file tree

16 files changed

+126
-287
lines changed

‎.pnp.cjs

Copy file name to clipboardExpand all lines: .pnp.cjs
+14-132Lines changed: 14 additions & 132 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

‎packages/allure-vitest/.eslintrc.cjs

Copy file name to clipboardExpand all lines: packages/allure-vitest/.eslintrc.cjs
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
extends: ["../../.eslintrc.cjs"],
3+
ignorePatterns: ["test/fixtures/**"],
34
globals: {
45
allure: true,
56
},

‎packages/allure-vitest/package.json

Copy file name to clipboardExpand all lines: packages/allure-vitest/package.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@types/node": "^20.6.3",
5252
"@typescript-eslint/eslint-plugin": "^7.0.0",
5353
"@typescript-eslint/parser": "^7.0.0",
54+
"@vitest/runner": "^1.6.0",
5455
"eslint": "^8.57.0",
5556
"eslint-config-prettier": "^9.0.0",
5657
"eslint-plugin-import": "^2.28.1",
@@ -62,6 +63,6 @@
6263
"rimraf": "^5.0.1",
6364
"typescript": "^5.2.2",
6465
"vite": "^5.0.11",
65-
"vitest": "^1.1.3"
66+
"vitest": "^1.6.0"
6667
}
6768
}
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { getCurrentSuite, getCurrentTest } from "@vitest/runner";
2+
import type { SuiteCollector, Task, TaskMeta } from "vitest";
3+
import type { RuntimeMessage } from "allure-js-commons/sdk";
4+
import { MessageTestRuntime } from "allure-js-commons/sdk/runtime";
5+
6+
export class VitestTestRuntime extends MessageTestRuntime {
7+
sendMessage(message: RuntimeMessage): Promise<void> {
8+
const currentTest = getCurrentTest();
9+
if (currentTest) {
10+
addMessage(currentTest.meta, message);
11+
return Promise.resolve();
12+
}
13+
const currentSuite = getCurrentSuite();
14+
if (currentSuite) {
15+
currentSuite.tasks.forEach((task) => processTask(task, message));
16+
}
17+
return Promise.resolve();
18+
}
19+
}
20+
21+
const processTask = (task: Task | SuiteCollector, message: RuntimeMessage) => {
22+
switch (task.type) {
23+
case "collector":
24+
case "suite":
25+
task.tasks.forEach((sub) => processTask(sub, message));
26+
break;
27+
case "test":
28+
addMessage(task.meta, message);
29+
break;
30+
default:
31+
break;
32+
}
33+
};
34+
35+
const addMessage = (meta: TaskMeta, message: RuntimeMessage) => {
36+
// @ts-ignore
37+
if (!meta.allureRuntimeMessages) {
38+
// @ts-ignore
39+
meta.allureRuntimeMessages = [];
40+
}
41+
// @ts-ignore
42+
meta.allureRuntimeMessages.push(message);
43+
};

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

Copy file name to clipboardExpand all lines: packages/allure-vitest/src/reporter.ts
+7-11Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { File, Reporter, Task } from "vitest";
44
import { LabelName, Stage, Status } from "allure-js-commons";
55
import type { RuntimeMessage } from "allure-js-commons/sdk";
66
import { extractMetadataFromString } from "allure-js-commons/sdk";
7-
import { ALLURE_SKIPPED_BY_TEST_PLAN_LABEL } from "allure-js-commons/sdk/reporter";
87
import type { Config } from "allure-js-commons/sdk/reporter";
98
import {
109
FileSystemWriter,
@@ -65,21 +64,18 @@ export default class AllureVitestReporter implements Reporter {
6564
return;
6665
}
6766

68-
const { allureRuntimeMessages = [], VITEST_POOL_ID } = task.meta as {
67+
const {
68+
allureRuntimeMessages = [],
69+
VITEST_POOL_ID,
70+
allureSkip = false,
71+
} = task.meta as {
6972
allureRuntimeMessages: RuntimeMessage[];
7073
VITEST_POOL_ID: string;
74+
allureSkip?: boolean;
7175
};
72-
// TODO: maybe make part of core utils?
73-
const skippedByTestPlan = allureRuntimeMessages.some((message) => {
74-
if (message.type === "metadata") {
75-
return (message.data?.labels || []).some(({ name }) => name === ALLURE_SKIPPED_BY_TEST_PLAN_LABEL);
76-
}
77-
78-
return false;
79-
});
8076

8177
// do not report tests skipped by test plan
82-
if (skippedByTestPlan) {
78+
if (allureSkip) {
8379
return;
8480
}
8581

0 commit comments

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