Allure framework integration for Bun test
- Learn more about Allure Report at https://allurereport.org
- Documentation is available at https://allurereport.org/docs/
- Questions and support are available at https://github.com/orgs/allure-framework/discussions/categories/questions-support
Install allure-bun using a package manager of your choice. For example:
npm install -D allure-bun allure-js-commonsKeep allure-bun and allure-js-commons on the same version.
Bun support is provided through Bun's documented preload hook. Keep your test imports unchanged and preload allure-bun/setup from bunfig.toml:
[test]
preload = ["allure-bun/setup"]Example:
import { describe, expect, it } from "bun:test";
import { label, step } from "allure-js-commons";
describe("signing in", () => {
it("works", async () => {
await label("severity", "critical");
await step("submit form", async () => {});
expect(1 + 1).toBe(2);
});
});When your Bun test uses synchronous helpers or matcher integrations, you can use the sync facade from allure-js-commons/sync.
import * as allure from "allure-js-commons/sync";
allure.step("check result", () => {
allure.parameter("mode", "sync");
});The sync facade is strict-sync only: allure.step() must finish synchronously and must not return a Promise.
When the test run completes, the result files will be generated in the ./allure-results directory.
allure-bun/setup accepts the common Allure reporter configuration through globalThis.allureBunConfig or the ALLURE_BUN_CONFIG environment variable. Use a custom preload when you need values that JSON can't represent, such as listener functions or link-template functions:
import type { ReporterConfig } from "allure-js-commons/sdk/reporter";
globalThis.allureBunConfig = {
resultsDir: "allure-results",
environmentInfo: {
bun: Bun.version,
},
globalLabels: {
layer: "api",
},
links: {
issue: {
urlTemplate: "https://issues.example/%s",
},
},
} satisfies ReporterConfig;
await import("allure-bun/setup");allure-bun/setupuses Bun preload and is not a Jest environment.- Keep using Bun's regular test API in test files, including hooks,
.each, and supported non-concurrent modifiers. - Concurrent Bun execution is not supported.
test.concurrent,test.concurrent.each, andbun test --concurrentfail fast with a descriptive error. - Randomized Bun execution is not supported.
bun test --randomizefails fast because Bun doesn't expose the current test identity tobeforeEachhooks. - Test-plan selection is handled while Bun tests are registered. Excluded test and hook bodies are not invoked, but top-level module code and
describe(...)registration callbacks still run.
Use Allure Report 2:
allure generate ./allure-results -o ./allure-report
allure open ./allure-reportOr use Allure Report 3:
npx allure generate ./allure-results
npx allure open ./allure-report