allure-notifications

repository·master·Indexed 20 days ago

https://github.com/qa-guru/allure-notifications

A tool for sending visually rich test-run summaries and statistical collages from Allure reports to messaging platforms. It includes a CLI for dispatching notifications, a web-based config.json builder, and an Allure 3 plugin for integration into the report generation process. The system uses @napi-rs/canvas for high-performance PNG generation and supports various analytics-driven panels and canvas presets.

Tokens
37.9K
Snippets
119
Records
175
Agent score
67%

What's inside allure-notifications

  1. Overview of Allure notifications

    master

    Allure notifications is a tool that generates beautiful test-run notifications for messengers. It creates a collage PNG containing various test statistics and a caption with environment details, counters, and links.

    To use it, you build a config.json file using the Config builder and send it via the TypeScript CLI (current version 6.0.12).

    Notification Components:

    • Collage: A 7-panel image showing current status, status dynamics, pyramid, durations, success rate, duration dynamics, and status transitions.
    • Text: Includes environment, comment, duration, and counters for passed, failed, broken, and skipped tests.
    • Links: Provides clickable links to report, dashboard, testops, and build (configured via base.links).
  2. Overview of allure-notifications packages

    master

    The allure-notifications project is a TypeScript workspace organized into several specialized packages. Depending on your needs, you might use the CLI for direct execution, the core package for report processing, or the plugin for Allure 3 integration.

    Package Roles

    • allure-notifications (CLI): The primary npm package. It provides the send binary for executing notifications in dry-run, mock, or live modes.
    • @allure-notifications/core: Handles the transformation of reports into native PNG images using @napi-rs/canvas.
    • @allure-notifications/config: Provides Zod schemas, PANEL_CATALOG, DEFAULT_ITEMS, and canvas presets.
    • @allure-notifications/pyramid: Serves as the Single Source of Truth (SSOT) for palette and rounded-tier geometry.
    • @allure-notifications/plugin: An optional, thin Allure 3 plugin built on top of @allure-notifications/core.
    • @allure-notifications/builder: (Included in monorepo) Build utilities.
    • @allure-notifications/test-meta: (Included in monorepo) Test metadata utilities.
  3. Use @allure-notifications/config for schema validation and presets

    master

    The @allure-notifications/config package provides the shared config.json schema and various presets used for generating Allure notifications. It is primarily used to ensure configuration files follow the correct structure and to quickly apply layout presets.

    Key capabilities include:

    • Validation: Use ConfigSchema and parseConfig (powered by zod) to validate configuration objects, supporting free layouts and specific 'chrome' knobs.
    • Panel Management: Access PANEL_CATALOG and resolvePanelMeta to manage the 17 available palette slots.
    • Presets: Utilize CANVAS_PRESETS and createDefaultConfig to apply standard layouts (e.g., 870, 1080, or 1410 presets) or the DEFAULT_ITEMS (CB-870 default + 4-tile items).
    • Chrome Defaults: When using builder SQ-1080, the default values are headerHeight: 22, cardGap: 14, and tilePad: 6.
  4. How Allure notifications works

    master

    Allure notifications works by consuming a summary.json file generated in the allure-report/widgets directory after automated tests finish executing. This file contains general test statistics (passed, failed, broken, etc.) and timing data. The library uses this data to construct a notification containing both a visual chart and descriptive text, which is then sent to your chosen messaging platform.

    If the Allure Summary plugin is connected, a suites.json file will also be generated, and its data will be included in the statistics.

    Workflow:

    1. Automated tests run.
    2. summary.json is generated in allure-report/widgets.
    3. Allure Notifications reads summary.json.
    4. A notification (chart + text) is created.
    5. The notification is sent to the configured messenger.
    {
      "reportName" : "Allure Report",
      "testRuns" : [ ],
      "statistic" : {
        "failed" : 182,
        "broken" : 70,
        "skipped" : 118,
        "passed" : 439,
        "unknown" : 42,
        "total" : 851
      },
      "time" : {
        "start" : 1590795193703,
        "stop" : 1590932641296,
        "duration" : 11311,
        "minDuration" : 7901,
        "maxDuration" : 109870,
        "sumDuration" : 150125
      }
    }
  5. How Allure 2 vs Allure 3 report detection works

    master

    The library automatically detects whether you are using Allure 2 or Allure 3 by looking for specific summary files in the allureFolder:

    • Allure 2: Looks for <allureFolder>/widgets/summary.json and checks for the statistic key.
    • Allure 3: Looks for <allureFolder>/summary.json and checks for the stats key.

    If neither path is found at the top level, the library performs a recursive search (up to 5 levels deep) for summary.json.

    Note for Allure 3 users: With version 5.0+, you no longer need to manually copy summary.json to a widgets/ folder; simply point allureFolder to your report root.

  6. How history data is sourced for Allure 3

    master

    The engine derives historical trends (transitions, growth, coverage, etc.) from Allure 3 history.jsonl files.

    • Discovery: It looks for history.jsonl via the chart.historyPath configuration or auto-discovers it next to report/results files.
    • Data Requirements: Typical lines should include status, duration/start/stop, environment, and labels.
    • Minimal History: If only id and status are present, the engine can still drive transitions, growth, and age metrics. However, duration and environment-based metrics will fall back to empty captions.
    • Fallbacks:
      • If no history is found, panels display "No history data".
      • stabilityDistribution can fall back to current *-result.json labels.
      • pyramidFallback: "suites" ensures a real SuitesPanel is shown when no known layers are detected.
  7. Configure Chart modes: Pie vs Collage

    master

    The base.enableChart flag acts as the master switch. When true, you can choose between two modes via base.chart.mode:

    1. pie (Default): Renders a single status pie chart. This is compatible with 4.x behavior and requires no configuration changes if enableChart is true.
    2. collage (New in 5.0): Renders a 1000×600 PNG containing three panels: a status pie chart, a testing pyramid (or suites bar), and a duration histogram.

    Note: To use collage mode, you must set base.allureResultsFolder so the library can access raw *-result.json files for analytics.

    {
      "base": {
        "enableChart": true,
        "allureResultsFolder": "build/allure-results/",
        "chart": {
          "mode": "collage"
        }
      }
    }
  8. Choose a messenger delivery mode (dry-run, mock, or live)

    master

    The mode option determines whether the plugin actually sends notifications over the network. By default, the plugin is safe and does not perform network requests.

    • dry-run (Default): Renders the collage PNG and lists the messengers that would have sent a notification. No network activity occurs.
    • mock: Renders the collage PNG and records mock deliveries. No network activity occurs.
    • live: Performs actual delivery (e.g., Telegram sendPhoto). This requires environment variables like TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID, and TELEGRAM_TOPIC_ID to be set.
  9. Best practices and anti-patterns for Allure metadata

    master

    To maintain a reliable Single Source of Truth (SSOT) for test metadata, follow these guidelines:

    Do:

    • Use declareSuite or bindSuiteMeta as the primary source of truth.

    Don't:

    • Do not include @allure.label.epic=... inside test title strings.
    • Do not use beforeEach to copy-paste metadata into every it() block.
    • Do not rely on post-hoc enrichment (like the deprecated scripts/enrich-allure-layers.mjs) as your primary metadata source.
    • Do not use allure-node-test/setup on Node 24 (this requires Node ≥ 26.1).
  10. Understand the Allure Notifications Versioning and Stack

    master

    The project has transitioned from a Java-based MVP to a TypeScript-based product. It is critical to use the correct stack based on your requirements:

    Version LineAllure VersionStackStatus
    4.ewAllure 2JavaHistorical
    5.ewAllure 3Java (Gradle fat jar 5.0.8)Historical MVP (under legacy/java/) - Bugfixes/Security only
    6.ewAllure 3TypeScript / CLI / Builder / PluginCurrent Product (on master)

    Key 6.0. Components:*

    • Standalone CLI and Web Builder.
    • Allure 3 plugin (a thin wrapper over core).
    • AI features (incremental).
    • Native collage PNG generation (using @napi-rs/canvas, not Playwright).
  11. How the Allure 3 notification plugin works

    master

    The Allure 3 plugin executes its Plugin.done hook during the allure generate process.

    Important Lifecycle Note: Allure 3 calls Plugin.done before report files (such as summary.json) are fully flushed to disk. Because the notifications plugin relies on reading these files from disk to render collages and send messages, a single-step generation might fail to find the necessary data.

    To ensure reliability, the recommended pattern is:

    1. Generate the report without the plugin so files land on disk.
    2. Generate again with the plugin configuration (e.g., allure generate --config allurerc.mjs). The plugin will then read the files from step 1 to render the collage and send notifications.