Skip to content

Latest commit

 

History

History
121 lines (90 loc) · 3.94 KB

README.md

File metadata and controls

121 lines (90 loc) · 3.94 KB

vitest-allure

Allure framework integration for Vitest framework

Allure Report logo


Installation

npm i -D vitest allure-vitest

or via yarn:

yarn add -D vitest allure-vitest

Configuration

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",
      }),
    ],
  },
});

Reporter options

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

API

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");
});

Selective test execution

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.

Passing metadata from test title

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