Allure Mocha reference
These are the functions that you can use to integrate your Mocha tests with Allure.
Metadata
Assign a test's description, links and other metadata.
Description
allure.description(markdown: string)
Set the test's description. Markdown formatting is allowed. Any HTML formatting, if present, will be stripped for security purposes.
JavaScriptconst { allure } = require("allure-mocha/runtime");
it("description", () => {
allure.description("This test attempts to create a label with specified title.");
// ...
});
Owner
allure.owner(owner: string)
Set the test's owner.
JavaScriptconst { allure } = require("allure-mocha/runtime");
it("owner", () => {
allure.owner("John Doe");
// ...
});
Tag
allure.tag(tag: string)
Set the test's tags.
JavaScriptconst { allure } = require("allure-mocha/runtime");
it("tag", () => {
allure.tag("UI");
allure.tag("Labels");
// ...
});
Severity
allure.severity(severity: string)
Set the test's severity.
Allowed values are: “trivial”, “minor”, “normal”, “critical”, and “blocker”.
JavaScriptconst { allure } = require("allure-mocha/runtime");
it("severity", () => {
allure.severity("critical");
// ...
});
Label
allure.label(name: string, value: string)
Set an arbitrary label for the test. This is the underlying implementation for a lot of Allure's other functions.
The first argument of the function is the label name. It can be any string.
You can call label()
multiple times to create an array of values under the given name.
JavaScriptconst { allure } = require("allure-mocha/runtime");
it("label", () => {
allure.label("MyLabel", "value");
// ...
});
ID
allure.id(allureId: string)
Set the test's ID.
JavaScriptconst { allure } = require("allure-mocha/runtime");
it("id", () => {
allure.id("123");
// ...
});
Link
allure.link(url: string, name?: string, type?: string)
allure.issue(name: string, url: string)
allure.tms(name: string, url: string)
Add a link related to the test.
The name
will be used as the link's text. If it is omitted, the full URL will be used instead.
The type
affects the icon that is displayed next to the link in the test report. For convenience, Allure provides two shorthand functions with pre-selected link types: issue
and tms
.
JavaScriptconst { allure } = require("allure-mocha/runtime");
it("link", () => {
allure.link("https://dev.example.com/", "Website");
allure.issue("AUTH-123", "https://issues.example.com/AUTH-123");
allure.tms("TMS-456", "https://tms.example.com/TMS-456");
// ...
});
Behavior-based hierarchy
allure.epic(epic: string)
allure.feature(feature: string)
allure.story(story: string)
Assign names of epics, features or user stories for a test, as part of Allure's behavior-based hierarchy.
JavaScriptconst { allure } = require("allure-mocha/runtime");
it("behavior", () => {
allure.epic("Web interface");
allure.feature("Essential features");
allure.story("Labels");
// ...
});
Suite-based hierarchy
allure.parentSuite(name: string)
allure.suite(name: string)
allure.subSuite(name: string)
Assign the name of suite, as part of Allure's suite-based hierarchy.
JavaScriptconst { allure } = require("allure-mocha/runtime");
it("behavior", () => {
allure.parentSuite("Web interface");
allure.suite("Essential features");
allure.subSuite("Labels");
// ...
});
Test steps
allure.step(name: string, body: (step?: AllureCommandStepExecutable) => void): Promise<void>
Define a test sub-step with the given name
.
JavaScriptconst { allure } = require("allure-mocha/runtime");
it("steps", () => {
allure.step("Step 1", () => {
allure.step("Sub-step 1", () => {
// ...
});
allure.step("Sub-step 2", () => {
// ...
});
});
allure.step("Step 2", () => {
// ...
});
});
Parametrized tests
allure.parameter(name: string, value: any, options?: ParameterOptions)
Specify a name
and value
of a parameter that was used during this test. See Parametrized tests for more details.
The options
argument, if given, must be an object with two optional properties excluded
and mode
.
If
excluded
is set to true, Allure will not use the parameter when comparing the current test result with previous one in the history. This argument is only used by Allure TestOps.The
mode
affects how the parameter will be displayed in the report. Available options are:"default"
(same as not specifying any mode) — the parameter and its value will be shown in a table along with other parameters."masked"
— the parameter will be shown in the table, but its value will be hidden. Use this mode for passwords, tokens and other sensitive parameters."hidden"
— the parameter and its value will not be shown in the test report. Note, however, that it is still possible to extract the value from theallure_results
directory if you publish it.
JavaScriptconst { allure } = require("allure-mocha/runtime");
for (const login of ["johndoe", "[email protected]"]) {
it(`Test authenticate as ${login}`, () => {
allure.parameter("login", login);
allure.parameter("time", new Date().toUTCString(), { excluded: true });
// ...
});
}
Attachments
allure.attach(content: string | Buffer, type: string)
Add content
as an attachment to the test result. The content can be a text string or a base64-encoded Buffer
.
You can use data produced by any function, not necessarily read from an actual file.
To ensure that the reader's web browser will display attachments correctly, it is recommended to specify each attachment's type. To do so, pass the MIME type of the content as type
.
JavaScriptconst { allure } = require("allure-mocha/runtime");
const fs = require("fs");
it("attachment", () => {
allure.attachment("image.png", fs.readFileSync("/path/to/image.png"), "image/png");
// ...
});