Getting started with Allure Fetch
Capture fetch HTTP requests and responses as attachments in your Allure Report test reports.
Allure Fetch is compatible with any Allure JS framework integration, including Allure Vitest, Allure Jest, Allure Playwright, Allure Mocha, and others.
To enable the integration in your project:
Make sure you have an Allure integration set up for the test framework you use.
See the instructions in the integration's documentation in Frameworks.
Install
allure-fetch.bashnpm install --save-dev allure-fetchbashyarn add --dev allure-fetchbashpnpm install --dev allure-fetchWrap your
fetchimplementation withwithAllure()to start capturing requests.The example below shows usage in a Vitest test suite.
tsimport { withAllure } from "allure-fetch"; import { describe, expect, it } from "vitest"; const client = withAllure(fetch); describe("Orders API", () => { it("creates an order", async () => { const response = await client("https://api.example.com/orders", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ item: "book", qty: 1 }), }); expect(response.status).toBe(201); }); });Every HTTP request made through
clientwill be added to the test result as an attachment, wrapped in a step of the same name. The attachment captures the full exchange in one place: the request method, URL, headers, query parameters, cookies, and body; the response status, headers, cookies (including attributes such asPath,Domain,Expires,Secure,HttpOnly, andSameSite), and body; the exchange start and stop timestamps; and, when the request fails, the error name and message.If your tests call the global
fetchdirectly, useinstrumentGlobalFetch()instead. It replacesglobalThis.fetchwith an instrumented version and returns a restore function. Call the restore function when you no longer want requests captured — typically inafterEachorafterAll:tsimport { instrumentGlobalFetch } from "allure-fetch"; import { afterEach, beforeEach, describe, expect, it } from "vitest"; describe("Orders API", () => { let restore: () => void; beforeEach(() => { restore = instrumentGlobalFetch(); }); afterEach(() => { restore(); }); it("creates an order", async () => { const response = await fetch("https://api.example.com/orders", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ item: "book", qty: 1 }), }); expect(response.status).toBe(201); }); });INFO
To prevent secrets from leaking into reports, certain values are redacted by default — all cookies, any header or query parameter whose name suggests it contains a credential, and any URL-encoded form field whose name does the same. See Allure Fetch configuration for the full list of defaults and how to customize the redaction rules.
Run your tests and generate a test report the same way as you would normally.