Allure JS Parser
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
-
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.fixVerify that the path provided to `parseAllure` is correct and the directory exists. Ensure your test runner has generated Allure results in the specified location. -
SyntaxError: Unexpected token 'X', "..." is not valid JSON
cause One or more of the files within the `allure-results` directory are malformed JSON.fixInspect 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. -
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.fixEnsure 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.
Warnings
- 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.
- 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.
- 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.
Install
-
npm install allure-js-parser -
yarn add allure-js-parser -
pnpm add allure-js-parser
Imports
- parseAllure
const { parseAllure } = require('allure-js-parser');import { parseAllure } from 'allure-js-parser'; - AllureTestResult
import type { AllureTestResult } from 'allure-js-parser'; - AllureResult
import type { AllureResult } from 'allure-js-parser';
Quickstart
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 });
}