Allure framework integration for Vitest framework
- Learn more about Allure Report at https://allurereport.org
- 📚 Documentation – discover official documentation for Allure Report
- ❓ Questions and Support – get help from the team and community
- 📢 Official annoucements – be in touch with the latest updates
- 💬 General Discussion – engage in casual conversations, share insights and ideas with the community
npm i -D vitest allure-vitest
or via yarn:
yarn add -D vitest allure-vitest
Add instance of the reporter to the reporters
section of your Vitest config:
import AllureReporter from "allure-vitest/reporter";
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
// add setup file to be able to use Allure API via `this.allure` in your tests and to get test plan support
setupFiles: ["allure-vitest/setup"],
reporters: [
// do not forget to keep the "default" if you want to see something in the console
"default",
new AllureReporter({
links: [
{
type: "issue",
urlTemplate: "https://example.org/issue/%s",
},
{
type: "tms",
urlTemplate: "https://example.org/task/%s",
},
],
resultsDir: "./allure-results",
}),
],
},
});
Some reporter settings can set by following options:
Option | Description | Default |
---|---|---|
resultsDir | Path to results folder | ./allure-results |
links | Links templates to make runtime methods calls simpler | undefined |
If you use setup file shipped by the integration, use this.allure
to get access
to Allure Runtime API:
import { test } from "vitest";
test("sample test", async () => {
await allure.label("foo", "bar");
});
Additionally, you can call Allure Runtime API methods directly passing the context argument to the method:
import { test } from "vitest";
import * as allure from "allure-vitest";
test("sample test", async (context) => {
await allure.label(context, "foo", "bar");
});
Allure allow you to execute only a subset of tests. This is useful when you want to run only a specific test or a group of tests.
It works out of the box if you add allure-vitest/setup
to your setupFiles
config option.
Allure will read ALLURE_TESTPLAN_PATH
environment variable and read testplan
from the specified file.
You also can pass allure metadata from test title.
This is useful when you need to set allureId for the tests with failing before hooks. Just add @allure.id={idValue}
for the allureId or @allure.label.{labelName}={labelValue}
for other types of labels.
import { test } from "vitest";
test("test with allureId @allure.id=256", () => {});
test("tst with severity @allure.label.severity=critical", () => {});
test("test with epic @allure.label.epic=login", () => {});
test("test with strangeLabel @allure.label.strangeLabel=strangeValue", () => {});
Warning Note that changing title can cause creating new testcases in history. To fix this please add
@allure.id={yourTestCaseId}
to the test name if you passing allure metadata from test title