Getting started with Allure AVA
Generate beautiful HTML reports using Allure Report and your AVA tests.
Setting up
1. Prepare your project
Make sure Node.js is installed.
Allure AVA requires AVA 8 or later. AVA 8 requires Node.js
^22.20,^24.12, or>=26.Open a terminal and go to the project directory. For example:
bashcd /home/user/myprojectMake sure Allure Report is installed. If it's not, follow the installation instructions. Note that Allure Report requires Java.
Install the Allure AVA integration:
bashnpm install --save-dev allure-ava avabashyarn add --dev allure-ava avabashpnpm add -D allure-ava avaCall
installAllure()from your AVA configuration file.For an ESM config (
ava.config.mjs):js// ava.config.mjs import { installAllure } from "allure-ava"; await installAllure({ resultsDir: "allure-results", }); export default {};If your project does not use
"type": "module"in itspackage.json, keep the configuration in CommonJS — name the fileava.config.jsand export an async factory:js// ava.config.js module.exports = async () => { const { installAllure } = await import("allure-ava"); await installAllure({ resultsDir: "allure-results", }); return {}; };Note that AVA only reads
ava.config.jsandava.config.mjs; a file namedava.config.cjsis silently ignored.Your test files themselves do not need any changes. Optionally, specify
resultsDirand other options. See Allure AVA configuration for more details.TIP
If the tests run but the results directory is not created and the console prints
no test runtime is found, AVA did not load your configuration file — check its name and location.
2. Run tests
Run your AVA tests the same way you would run them usually:
npx avaThis will save the necessary data into allure-results or another directory, according to the configuration. If the directory already exists, new files will be added to the existing ones so that a future report will be based on them all.
Tests declared with test.skip() or test.todo(), as well as tests excluded by test.skipIf() and test.runIf() conditions, appear in the report with the Skipped status.
Tests declared with test.failing() follow AVA's own semantics: when such a test fails as expected, it counts as successful and appears in the report with the Passed status; if it unexpectedly passes, it is reported as Broken with AVA's "Test was expected to fail, but succeeded" error.
If an AVA worker process crashes, times out, or exits unexpectedly, the tests affected by it appear in the report with the Broken status.
You can still pass regular AVA CLI arguments:
npx ava test/**/*.test.js --match "signing in"3. Generate a report
Finally, convert the test results into an HTML report. This can be done by one of two commands:
allure generateprocesses the test results and saves an HTML report into theallure-reportdirectory. To view the report, use theallure opencommand.allure servecreates the same report asallure generate, then automatically opens the main page of the report in a web browser.
Writing tests
The Allure AVA integration extends the standard reporting features of AVA by providing additional capabilities for crafting more informative and structured tests. This section highlights key enhancements that can be utilized:
- Metadata Annotation: Enhance test reports with descriptions, links, and other metadata.
- Test Organization: Structure your tests into clear hierarchies for better readability and organization, see organize tests.
- Step Division: Break down tests into smaller test steps for easier understanding and maintenance.
- Parametrized Tests: Clearly describe the parameters for parametrized tests to specify different scenarios.
- Set labels globally: Use environment variables to set metadata and other labels.
- Attachments: Capture files and other content during test execution.
- Test Selection: Use a test plan file to select which tests to run, allowing for flexible test execution.
- Environment Details: Include comprehensive environment information to accompany the test report.
In most cases, Allure AVA provides two different ways to use a feature: the Runtime API and the Metadata API.
Runtime API: use Allure's functions to add certain data to the test result during its execution. This approach allows for constructing the data dynamically.
Note that it is recommended to call Allure's functions as close to the beginning of the test as possible. This way, the data will be added even if the test fails early.
Metadata API: add a metadata tag (beginning with
@allure.) into the test name. Allure AVA will extract it and update the test result's data accordingly. When using this approach, the data is guaranteed to be added regardless of how the test itself runs.
Add metadata
Allure allows you to enrich your reports with a variety of metadata. This additional information provides context and details for each test, enhancing the report's usefulness. Refer to the metadata reference section for an exhaustive list of what can be added.
import * as allure from "allure-js-commons";
import test from "ava";
test("Test Authentication", async (t) => {
await allure.displayName("Test Authentication");
await allure.owner("John Doe");
await allure.tags("Web interface", "Authentication");
await allure.severity("critical");
// ...
t.pass();
});import test from "ava";
test(
"Test Authentication" +
" @allure.label.owner:JohnDoe" +
" @allure.label.tag:WebInterface" +
" @allure.label.tag:Authentication" +
" @allure.label.severity:critical",
(t) => {
// ...
t.pass();
},
);Organize tests
As described in Improving navigation in your test report, Allure supports multiple ways to organize tests into hierarchical structures.
To specify a test's location in the behavior-based hierarchy:
import * as allure from "allure-js-commons";
import test from "ava";
test("Test Authentication", async (t) => {
await allure.epic("Web interface");
await allure.feature("Essential features");
await allure.story("Authentication");
// ...
t.pass();
});import test from "ava";
test(
"Test Authentication" +
" @allure.label.epic:WebInterface" +
" @allure.label.feature:EssentialFeatures" +
" @allure.label.story:Authentication",
(t) => {
// ...
t.pass();
},
);To specify a test's location in the suite-based hierarchy:
import * as allure from "allure-js-commons";
import test from "ava";
test("Test Authentication", async (t) => {
await allure.parentSuite("Tests for web interface");
await allure.suite("Tests for essential features");
await allure.subSuite("Tests for authentication");
// ...
t.pass();
});import test from "ava";
test(
"Test Authentication" +
" @allure.label.parentSuite:TestsForWebInterface" +
" @allure.label.suite:TestsForEssentialFeatures" +
" @allure.label.subSuite:TestsForAuthentication",
(t) => {
// ...
t.pass();
},
);Divide a test into steps
To create steps and sub-steps, you can use the step() function, see the reference.
import * as allure from "allure-js-commons";
import { Status } from "allure-js-commons";
import test from "ava";
test("Test Authentication", async (t) => {
await allure.step("Step 1", async () => {
await allure.step("Sub-step 1", async (ctx) => {
await ctx.parameter("foo", "1");
// ...
});
await allure.step("Sub-step 2", async (ctx) => {
await ctx.parameter("foo", "2");
// ...
});
});
await allure.logStep("Step 2", Status.SKIPPED);
t.pass();
});Describe parametrized tests
To implement the parametrized tests pattern in AVA, write the test inside a loop and use the variable parameters in both the title and the body. Each iteration is treated as a separate test run by Allure Report.
To display a parameter value in the test report, pass it to the parameter() function.
import * as allure from "allure-js-commons";
import test from "ava";
for (const login of ["johndoe", "[email protected]"]) {
test(`Test Authentication as ${login}`, async (t) => {
await allure.parameter("login", login);
await allure.parameter("time", new Date().toUTCString(), { excluded: true });
// ...
t.pass();
});
}Set labels globally
Any labels, including custom ones, can be set via environment variables in your operating system. Here's an example:
export ALLURE_LABEL_epic=WebInterface
npx ava$Env:ALLURE_LABEL_epic = "WebInterface"
npx avaAttach files
In Allure reports, you have the ability to attach various types of files, which can greatly enhance the comprehensibility of the report. Additionally, any messages logged with AVA's built-in t.log() are automatically added to the test result (or to the corresponding fixture, when logged in a hook) as a text attachment named "AVA logs".
For detailed instructions on how to implement attachments, refer to the attachments section in the Allure AVA reference.
import * as allure from "allure-js-commons";
import { ContentType } from "allure-js-commons";
import test from "ava";
test("Test Authentication", async (t) => {
// ...
await allure.attachment("Text file", "This is the file content.", ContentType.TEXT);
await allure.attachmentPath("Screenshot", "/path/to/image.png", {
contentType: ContentType.PNG,
fileExtension: "png",
});
t.pass();
});Select tests via a test plan file
If the ALLURE_TESTPLAN_PATH environment variable is defined and points to an existing file, AVA will only run tests listed in this file.
Tests can be matched in two ways:
- By selector — using the
path/to/file.test.js#test titleformat. The path is relative to the project root (the closest directory with apackage.json), and the title is the test name with any@allure.*metadata tags stripped out. - By Allure ID — using the
@allure.id:⟨VALUE⟩metadata tag in the test name.
Here's an example of running tests according to a file named testplan.json:
export ALLURE_TESTPLAN_PATH=testplan.json
npx ava$Env:ALLURE_TESTPLAN_PATH = "testplan.json"
npx avaEnvironment information
For the main page of the report, you can collect various information about the environment in which the tests were executed. To do so, edit the environmentInfo object in the configuration.
For example, it is a good idea to record the OS version and the Node.js version. This may help the future reader investigate bugs that are reproducible only in some environments.
// ava.config.mjs
import { installAllure } from "allure-ava";
import * as os from "node:os";
await installAllure({
environmentInfo: {
os_platform: os.platform(),
os_release: os.release(),
os_version: os.version(),
node_version: process.version,
},
});
export default {};