allure-js
allure-js copied to clipboard
[Vitest] add Reporter
I think we need reporter for https://github.com/vitest-dev/vitest
(Paused till this issue open https://github.com/vitest-dev/vitest/issues/616 )
@vovsemenv looks like https://github.com/vitest-dev/vitest/issues/616 merged on Feb 1st?
Actually vitest plugin system don't ready. Right now I can easily implement only basic results reporting.
Hello
I was wondering if there were still plans on creating a reporter for vitest. My team recently switched from jest to vitest and would be keen to see an allure reporter for vitest.
Thanks
Hello @markgerra, allure-js is Open-Source, so PR is welcome. We have plans to support it, but without ETA. If your company urgently needs this feature and can sponsor it, then just email us allure at qameta.io.
@markgerra Creating fully-features reporter for vitest is really tricky without decent plugin system. So i created simple reporter just to report failed/done tests and their suites for now and you can generate basic reports. Once vitest team provide way to send metadata i will pack it to production ready package.
"reporter.ts"
import {
AllureConfig,
AllureGroup,
AllureRuntime,
LabelName,
Status
} from "allure-js-commons";
import { File, Reporter, Task, Vitest } from "vitest";
export class AllureReporter implements Reporter {
private vitestInstance: Vitest | null;
private allureRuntime: AllureRuntime | null;
constructor(config?: Partial<AllureConfig>){
this.allureRuntime = new AllureRuntime({
resultsDir: "allure-results",
...config,
});
}
onInit(ctx: Vitest) {
this.vitestInstance = ctx;
}
onFinished(files?: File[]) {
if (!this.allureRuntime) {
return;
}
const rootSuite = this.allureRuntime.startGroup(undefined);
for (const file of files || []) {
const group = rootSuite.startGroup(file.name);
group.name = file.name;
for (const task of file.tasks) {
this.handleTask(group, task);
}
group.endGroup();
}
rootSuite.endGroup();
}
handleTask(parent: AllureGroup, task: Task) {
if (task.type === "suite") {
const group = parent.startGroup(task.name);
group.name = task.name;
for (const innerTask of task.tasks) {
this.handleTask(group, innerTask);
}
group.endGroup();
} else {
const test = parent.startTest(task.name, 0);
test.name = task.name;
test.fullName = `${task.file?.name}#${task.name}`;
switch (task.result?.state) {
case "fail": {
test.detailsMessage = task.result.error?.message;
test.detailsTrace = task.result.error?.stackStr;
test.status = Status.FAILED;
break;
}
case "pass": {
test.status = Status.PASSED;
break;
}
case "skip": {
test.status = Status.SKIPPED;
break;
}
}
test.addLabel(LabelName.SUITE, parent.name);
if (task.suite.suite?.name) {
test.addLabel(LabelName.PARENT_SUITE, task.suite.suite.name);
}
test.historyId = task.id;
test.endTest(task.result?.duration);
}
}
}
"vite.config.ts"
import { defineConfig } from "vite";
import { AllureReporter } from "./reporter";
export default defineConfig({
test: {
reporters: [new AllureReporter({}), "default"],
watch: false,
},
});
https://github.com/vitest-dev/vitest/issues/1951
@vovsemenv thank you so much for this!
Happy new year! It seems like upstream issues were resolved and building a reporter is possible now.
I build a poc version here: https://github.com/just-boris/vitest-allure
Let me know if you are interested merging this into the core
@just-boris thank you! Could you please open PR to the repository to merge the reporter?
sure, I can, but it may take some time as I am busy with other tasks. If somebody wants to take it over, please do this
Will transfer the repo by myself 👍