Allure JavaScript Integrations

repository·main·Indexed 42 days ago

https://github.com/allure-framework/allure-js

Official Allure Framework adapters for JavaScript testing tools (Jest, Vitest, Playwright, AVA, Bun, Cucumber.js, Cypress, CodeceptJS) and API tools (Axios, Fetch). It enables rich, metadata-heavy test reporting by generating standard allure-results files using the allure-js-commons runtime API.

Tokens
49.5K
Snippets
167
Records
228
Agent score
54%

What's inside Allure JS

  1. Automatic action steps in Allure

    main

    By default, the reporter automatically captures common TestCafe actions and assertions as Allure steps. This includes:

    • t.click(...)
    • t.typeText(...)
    • t.pressKey(...)
    • t.navigateTo(...)
    • t.request(...)
    • t.takeScreenshot(...)
    • t.expect(...).eql(...)
    • t.expect(...).ok()

    If you prefer to only show explicit steps created via the allure-js-commons runtime API, you can disable this behavior in the reporter configuration:

    createAllureTestCafeReporter({
      captureActionsAsSteps: false,
    });
  2. Filter tests using an Allure Test Plan

    main

    The integration supports Allure TestOps test-plan filtering. By setting the ALLURE_TESTPLAN_PATH environment variable to point to a TestOps test-plan JSON file, the integration will deselect AVA tests that do not match the plan before execution.

    Matching occurs via:

    1. Allure ID: Found in the test title metadata using @allure.id=....
    2. Selector: Using the path/to/file.test.js#test title format. Note that selector titles use the cleaned AVA title (Allure title metadata is stripped before matching).
  3. How Allure test plans work with TestCafe

    main

    Allure test plans allow you to control test selection via a JSON file. To use them, you must:

    1. Create a test plan JSON file (e.g., testplan.json):
    {
      "version": "1.0",
      "tests": [
        {
          "selector": "tests/auth.test.js#Authentication#sign in"
        },
        {
          "id": "42"
        }
      ]
    }
    1. Set the ALLURE_TESTPLAN_PATH environment variable to point to your file.

    2. Ensure your TestCafe configuration (JS/CJS) or Runner API includes the createAllureTestPlanFilter() helper:

    In Config File:

    const { createAllureTestPlanFilter } = require("testcafe-reporter-allure/testplan");
    
    module.exports = {
      filter: createAllureTestPlanFilter(),
      // ... other config
    };

    In Runner API:

    const { createAllureTestPlanFilter } = require("testcafe-reporter-allure/testplan");
    
    await runner
      .src(["tests/**/*.test.js"])
      .filter(createAllureTestPlanFilter())
      .run();
  4. What Allure Javascript Integrations provide

    main

    Allure adds a consistent reporting layer on top of your JavaScript test runs by generating allure-results files. Key features include:

    • Rich steps: Nested structures for test execution.
    • Attachments: Support for screenshots, logs, traces, and API payloads.
    • Metadata: Inclusion of owners, severity, tags, links, epics, stories, and test case IDs.
    • Advanced Analysis: History-aware results, retries, flaky analysis, categories, and environment details.
    • Unified API: A shared runtime API via allure-js-commons to maintain a consistent reporting model across different frameworks.
  5. How Body Capture works in Allure Axios

    main

    Allure Axios captures request bodies after Axios has applied any request transforms.

    • Text bodies: Stored as UTF-8 strings.
    • Binary bodies: Stored as base64.
    • Size Limit: Captured bodies are bounded by maxBodySize, which defaults to 64 KiB.
    • Streams/Multipart: Stream and multipart payloads are summarized in the report rather than being fully consumed/captured.
  6. How body capture works in Allure Fetch

    main

    Allure Fetch captures request and response bodies by cloning the Request and Response objects. This ensures that the original response remains readable by your test code.

    • Storage Format: Text bodies are stored as UTF-8 strings; binary bodies are stored as base64.
    • Size Limits: Captured bodies are bounded by maxBodySize, which defaults to 64 KiB.
  7. Limitations and compatibility notes for allure-bun

    main

    When using allure-bun, be aware of the following constraints:

    • Not a Jest environment: allure-bun/setup uses Bun's native preload mechanism.
    • No Concurrent Execution: Concurrent Bun execution is not supported. Using test.concurrent, test.concurrent.each, or the --concurrent flag will cause a fast-fail error.
    • No Randomized Execution: Using bun test --randomize is not supported because Bun does not expose the current test identity to beforeEach hooks.
    • Test-plan selection: While excluded test bodies are not invoked, top-level module code and describe(...) registration callbacks will still run during registration.
  8. Reporter SDK building blocks

    main

    The allure-js-commons/sdk entry points provide low-level components for building integrations:

    • sdk/runtime: Handles runtime message transport and global runtime registration.
    • sdk/reporter: Provides ReporterRuntime, writers, result factories, categories, environment info, and utilities.
    • sdk: Contains shared types, runtime message definitions, serialization helpers, and metadata parsing helpers.

    Key Utilities:

    • ReporterRuntime: Manages creation and writing of tests, fixtures, steps, attachments, categories, and environment info.
    • createDefaultWriter(): Writes to ./allure-results during normal runs and switches to a message writer in test mode.
    • setGlobalTestRuntime(): Connects the high-level facade API to the active framework runtime.
    • MessageTestRuntime & MessageHolderTestRuntime: Ready-made runtime message implementations for adapters.
    • createTestResult(), createStepResult(), createFixtureResult(), createTestResultContainer(): Factories for manual result construction.
  9. Compatibility Warning: Jest Test Runner

    main

    This package requires the jest-circus test runner.

    • Jest >= 27.0.0: jest-circus is the default; no extra configuration is needed.
    • Jest < 27.0.0: You must install jest-circus manually and set the testRunner option in your Jest configuration to "jest-circus/runner".

    If you are using jest-jasmine2, you should switch to jest-circus or use allure-jasmine instead.

  10. Install allure-playwright

    main

    Install the allure-playwright package as a development dependency to integrate Allure reporting with Playwright Test.

    Note: You must also install Allure Report separately to render the generated results.

    • For Allure Report 2: Follow the official installation guide to use the allure CLI.
    • For Allure Report 3: Install via npm install -D allure to use npx allure.
    npm install -D allure-playwright