Allure JS Parser

0.1.0 · active · verified Tue Apr 21

allure-js-parser is a utility library designed to programmatically parse raw `allure-results` JSON files, typically generated by test frameworks that integrate with Allure Report. It converts these raw files into a structured, strongly typed JavaScript object, providing developers with a flexible foundation to analyze test outcomes, generate custom reports, calculate statistics, or integrate Allure data into other systems. The package is currently at version 0.1.0, indicating it's in its initial development phase, and has seen frequent patch and minor updates, reflecting active maintenance. Its primary differentiator is offering direct, typed programmatic access to Allure data for custom processing workflows, as opposed to relying solely on the standard Allure CLI for static report generation.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse Allure result files from a specified directory, filter tests by labels, and extract basic statistics. It creates temporary Allure JSON files for a runnable example.

import { parseAllure } from 'allure-js-parser';
import * as path from 'path';
import * as fs from 'fs';

// Create a dummy 'allure-results' directory for demonstration
const resultsDir = path.join(__dirname, 'temp-allure-results');
if (!fs.existsSync(resultsDir)) {
  fs.mkdirSync(resultsDir);
}

// Create a dummy Allure test result file
fs.writeFileSync(
  path.join(resultsDir, 'test-result-123.json'),
  JSON.stringify({
    uuid: 'test-result-123',
    name: 'Example Test',
    status: 'passed',
    labels: [{ name: 'tag', value: 'regression' }],
    start: Date.now() - 1000,
    stop: Date.now()
  })
);

fs.writeFileSync(
  path.join(resultsDir, 'test-result-456.json'),
  JSON.stringify({
    uuid: 'test-result-456',
    name: 'Another Test',
    status: 'failed',
    labels: [{ name: 'tag', value: 'smoke' }],
    start: Date.now() - 2000,
    stop: Date.now() - 500
  })
);

try {
  const tests = parseAllure(resultsDir);
  console.log(`Parsed ${tests.length} tests.`);

  // Filter tests with the 'regression' tag
  const regressionTests = tests.filter(t => t.labels.some(label => label.name === 'tag' && label.value === 'regression'));
  console.log(`Found ${regressionTests.length} regression tests: ${regressionTests.map(t => t.name).join(', ')}`);

  // Basic statistics
  const passedTests = tests.filter(t => t.status === 'passed').length;
  const failedTests = tests.filter(t => t.status === 'failed').length;
  console.log(`Total Passed: ${passedTests}, Total Failed: ${failedTests}`);
} catch (error) {
  console.error('Error parsing Allure results:', error);
} finally {
  // Clean up the dummy directory
  fs.rmSync(resultsDir, { recursive: true, force: true });
}

view raw JSON →