Skip to main content

Configuration

The jest-allure2-reporter can be configured using the reporter options in your Jest configuration file. This reference outlines the available options and their usage.

Basic Configuration

To use jest-allure2-reporter, add it to your Jest configuration:

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
reporters: [
'default',
['jest-allure2-reporter', {
// Reporter options go here
}],
],
// Other Jest configurations...
};

Reporter Options

overwrite

  • Type: boolean
  • Default: true

Determines whether to overwrite the existing results directory.

overwrite: false

resultsDir

  • Type: string
  • Default: 'allure-results'

Specifies the directory where test result files will be output.

resultsDir: 'custom-allure-results'

injectGlobals

  • Type: boolean
  • Default: true

Controls whether Allure's global variables are injected into the test environment.

injectGlobals: false

attachments

  • Type: object

Configures how external attachments are attached to the report.

attachments: {
subDir: 'attachments',
fileHandler: 'copy',
contentHandler: 'write'
}

attachments.subDir

  • Type: string
  • Default: 'attachments'

Defines a subdirectory within the resultsDir where attachments will be stored.

attachments.fileHandler

  • Type: 'copy' | 'move' | 'ref' | string
  • Default: 'ref'

Specifies the default strategy for attaching files to the report by their path.

attachments.contentHandler

  • Type: 'write' | string
  • Default: 'write'

Specifies the default strategy for attaching dynamic content to the report.

sourceCode

  • Type: object

Configures how source code and docblocks are extracted from test files.

sourceCode: {
enabled: true,
plugins: {
// Plugin configurations
}
}

categories

  • Type: function

Configures the defect categories for the report.

categories: ({ $ }) => [
{
name: 'Timeouts',
matchedStatuses: ['broken'],
messageRegex: /.*Exceeded timeout of.*/
}
]

environment

  • Type: function

Configures the environment information that will be reported.

environment: async ({ $ }) => ({
'Node.js Version': process.version,
'Package Version': await $.manifest(['name'], 'N/A'),
})

executor

  • Type: function

Configures the executor information that will be reported.

executor: ({ value }) => ({
name: 'Jenkins',
type: 'jenkins',
url: process.env.BUILD_URL,
buildOrder: process.env.BUILD_NUMBER
})

helpers

  • Type: function

Customizes extractor helpers object to use later in the customizers.

helpers: ({ $ }) => ({
...$.helpers,
customHelper: () => { /* ... */ }
})

testRun

  • Type: object

Customizes how to report test runs (sessions) as pseudo-test cases.

testRun: {
uuid: ({ aggregatedResult }) => aggregatedResult.testResults[0].testFilePath,
name: 'Custom Test Run Name'
}

testFile

  • Type: object

Customizes how to report test files as pseudo-test cases.

testFile: {
name: ({ filePath }) => filePath.join('/'),
fullName: ({ filePath }) => filePath.join('.')
}

testCase

  • Type: object

Customizes how test cases are reported.

testCase: {
name: ({ testCase }) => testCase.title,
fullName: ({ testCase }) => testCase.fullName,
labels: {
severity: 'normal',
tag: ['unit', 'integration']
},
links: {
issue: 'https://jira.company.com/browse/{{name}}'
}
}

testStep

  • Type: object

Customizes how individual test steps are reported.

testStep: {
name: ({ value }) => `Step: ${value}`,
status: ({ value }) => value === 'broken' ? 'failed' : value
}

writer

  • Type: string | Function | object | [string | Function, any]

Customizes how test results are written to the filesystem. You can provide:

  • A path to a custom writer implementation
  • A writer class/constructor
  • A writer instance
  • An array with writer implementation and its options
// Using a custom writer class
writer: MyCustomWriter

// Using a writer instance
writer: new MyCustomWriter({ url: 'mongodb://...' })

// Using a path to writer implementation
writer: './my-writer.js'

// Using a writer with options
writer: [MyCustomWriter, { batchSize: 100 }]

By default, uses FileAllureWriter from allure-store package with the following configuration:

writer: new FileAllureWriter({
overwrite: true,
resultsDirectory: 'allure-results'
})

You can implement custom writers for various use cases like sending results via HTTP, storing in a database, or integrating with other systems. To do this, create a class implementing the AllureWriter interface from allure-store:

import { AllureWriter } from 'allure-store';

class MyCustomWriter implements AllureWriter {
async writeResult(result: AllureResult): Promise<void> {
await fetch('https://api.example.com/results', {
method: 'POST',
body: JSON.stringify(result)
});
}
// Implement other required methods...
}