Skip to main content

Attachments

Attachments are a powerful feature of Allure reports that can help make your tests much more informative. You can attach text logs, screenshots, configuration details, CSV files, and much more to your tests. These attachments can help you diagnose and debug failing tests.

There are several ways to add attachments to a test:

  • Using the allure.attachment function
  • Using the allure.createAttachment function
  • Using the @Attachment decorator

Built-in attachment types

The simplest way to start with attachments is to use the built-in ones:

import { allure } from 'jest-allure2-reporter/api';

test('Sample test', async () => {
await allure.attachment('My attachment', 'This is a simple text attachment', 'text/plain');
});

The allure.attachment function takes three arguments: name of the attachment, content, and the content type. The content type must be a valid MIME type.

TODO: add screenshot

Custom attachments

For advanced use cases, you may want to create your own custom attachments:

Using allure.attachment function is the most straightforward way to add a custom attachment:

import { allure } from 'jest-allure2-reporter/api';

test('Sample test', async () => {
const myData = JSON.stringify({a: 1, b: 2});
await allure.attachment('My JSON attachment', myData, 'application/json');
});

The disadvantage of this approach is that it is less flexible and more verbose for complex data.

Attachments allow you to enrich your test reports with additional context, which can be very useful when diagnosing and debugging failing tests.

TODO: add screenshot