Skip to content

Latest commit

 

History

History
157 lines (121 loc) · 5.03 KB

README.md

File metadata and controls

157 lines (121 loc) · 5.03 KB

vitest-allure

Allure framework integration for Vitest framework

Allure Report logo


Installation

Use your favorite node package manager to install the package:

npm i -D allure-vitest

Configuration

Add instance of the reporter to the reporters section of your Vitest config:

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    // add setup file to be able to use Allure API via `global.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",
      ["allure-vitest/reporter", { resultsDir: "./out/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

Runtime API

Use functions provided by allure-js-commons package to call Allure Runtime API methods:

import { test } from "vitest";
import * as allure from "allure-js-commons";

test("sample test", async (context) => {
  await allure.label(context, "foo", "bar");
  await allure.attachment("Attachment name", "Attachment content", "text/plain");
  await allure.step("my step", async () => {
    await allure.step("another step", async () => {
      await allure.label("foo", "bar");
    });
  });
});

Links usage

import { it } from "vitest";
import { link, issue } from "allure-js-commons";

it("basic test", async () => {
  await link("https://allurereport.org", "Allure Report"); // link with name
  await issue("https:/allure-framework/allure-js/issues/352", "Issue Name");
});

You can also configure links formatters to make usage much more convenient. %s in urlTemplate parameter will be replaced by given value.

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    setupFiles: ["allure-vitest/setup"],
    reporters: [
      "default",
      ["allure-vitest/reporter", {
        resultsDir: "./allure-results",
+       links: [
+         {
+           type: "issue",
+           urlTemplate: "https://example.org/issues/%s",
+           nameTemplate: "Issue: %s",
+         },
+         {
+           type: "tms",
+           urlTemplate: "https://example.org/tasks/%s"
+         },
+         {
+           type: "custom",
+           urlTemplate: "https://example.org/custom/%s"
+         },
+       ]
      }],
    ],
  },
});

Then you can assign link using shorter notation:

import { it } from "vitest";
import { issue, tms, link } from "allure-js-commons";

it("basic test", async () => {
  await issue("352", "Issue Name");
  await tms("352", "Task Name");
  await link("352", "Link name", "custom");
});

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