Skip to main content

By Category

Defect categories

One of the most important things when your builds start failing is to understand what exactly is broken.

By defining test result categories, you can easily distinguish between different types of errors and failures.

There are two built-in categories for test results:

🔴  Product defect
A failed Jest assertion, e.g. expect(countOfPosts).toBe(1).
🟡  Test defect
A broken test, e.g. TypeError: Cannot read property 'foo' of undefined, timeout or syntax errors.

This doesn't mean that you can't have categories for 🟢 passed or ⚪ skipped tests, but usually it makes more sense to develop a comprehensive taxonomy for various failure types.

For example, you can also distinguish between Snapshot mismatches, Timeouts and as many others as you need.

jest.config.js
const { Status } = require('jest-allure2-reporter');

/**
* @type {import('@jest/types').Config.InitialOptions}
*/
module.exports = {
// ... your jest config
reporters: [
'default',
['jest-allure2-reporter',
/** @type {import('jest-allure2-reporter').JestAllure2ReporterOptions} */
{
categories: [
{
name: 'Snapshot mismatches',
matchedStatuses: [Status.FAILED],
messageRegex: /.*\btoMatch(?:[A-Za-z]+)?Snapshot\b.*/,
},
{
name: 'Timeouts',
matchedStatuses: [Status.BROKEN],
messageRegex: /.*Exceeded timeout of.*/,
},
],
}
],
],
};
tip

If you need to overwrite the default categories, use a function customizer instead of an array:

jest.config.js
module.exports = {
// ... your jest config
reporters: [
'default',
['jest-allure2-reporter',
/** @type {import('jest-allure2-reporter').JestAllure2ReporterOptions} */
{
categories: () => [/* ... */],
}
],
],
};