Allure JS Parser

raw JSON →
0.1.0 verified Tue Apr 21 auth: no javascript

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.

error Error: ENOENT: no such file or directory, scandir '/path/to/non-existent-allure-results'
cause The directory path provided to `parseAllure` does not exist on the file system.
fix
Verify that the path provided to parseAllure is correct and the directory exists. Ensure your test runner has generated Allure results in the specified location.
error SyntaxError: Unexpected token 'X', "..." is not valid JSON
cause One or more of the files within the `allure-results` directory are malformed JSON.
fix
Inspect the JSON files in your allure-results directory for syntax errors. This often indicates an issue during the Allure result generation process by your test framework.
error TypeError: parseAllure is not a function
cause This typically occurs when trying to import `parseAllure` using CommonJS `require()` syntax in an environment where the package is compiled for ESM, or vice-versa, or due to a typo in the import.
fix
Ensure you are using import { parseAllure } from 'allure-js-parser'; for ESM projects. For CommonJS, if support is available, ensure correct destructuring, though ESM is preferred.
gotcha The package is currently in a 0.x.x version range. While actively developed, this implies that the API may not be fully stable and could introduce breaking changes in minor versions without adhering strictly to semantic versioning until a 1.0.0 release.
fix Always pin to exact versions (e.g., `"allure-js-parser": "0.1.0"`) or use caret ranges carefully, and review changelogs for each update.
gotcha The `parseAllure` function expects a path to a directory containing the raw Allure JSON files. Providing a path to an individual file or a non-existent directory will result in errors.
fix Ensure the path passed to `parseAllure` is a valid, existing directory that contains the `allure-results` JSON files.
breaking Version 0.1.0 introduced an option to `not log error when empty results` via a minor change. While not a direct breaking API change for existing calls, it signifies a new configurable behavior around error handling for empty results that users might want to be aware of and potentially configure.
fix Review the latest documentation for `parseAllure` options if you need to suppress or customize error logging for scenarios where the results directory is empty or contains no valid Allure files.
npm install allure-js-parser
yarn add allure-js-parser
pnpm add allure-js-parser

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 });
}