By Suite
This is perhaps the most common way to group test results, and it makes the most sense for projects using Jest.
The suite hierarchy consists of up to four levels: parent suite, suite, sub-suite and test case.
Glossary
- Parent Suite
- The highest level of the hierarchy used to group test results by package (e.g.,
client
,server
), test directory (e.g.,e2e
,unit
,integration
), or any other relevant criteria. It is not configured by default, but you can easily add it to your reports. - Suite
- Serves as the primary grouping level, typically based on test file paths. However, you can choose alternative criteria such as feature or component directories (
LoginScreen
,ProfileScreen
,core
,utils
), or top-level describe block names, if preferred. - Subsuite
- Helpful when dealing with a large number of test cases within a single suite. By default, test cases are grouped per top-level describe block. However, if there are numerous nested describe blocks (or, vice versa โ lots of files and directories), you can look for alternative configurations.
- Test Case
- Represents the actual test. By default, it displays the test name, including the inner describe block names. You have the flexibility to choose a test name format that best suits your needs โ see a few examples below in this article.
Below we'll explore a few examples of how to configure the grouping by suite.
Default presetโ
By default, jest-allure2-reporter
provides 3 levels of grouping: suite, sub-suite, and test case:
- The suite level is based on the test file path.
- The sub-suite level is based on the top-level describe block.
- The test case level is based on the test name (including the inner describe block names).
- Preview
- Structure
- Config
โโ client/auth/LoginScreen.test.js
โ โโ Login screen
โ โโ when loaded should display login form
โ โโ when loaded and typed should validate e-mail
โ โโ when loaded and typed should validate password
โโ client/auth/ForgotPasswordScreen.test.js
โ โโ Forgot password screen
โ โโ when loaded should display forgot password form
โ โโ when loaded and typed should validate e-mail
โโ server/controllers/login.test.js
| โโ Login controller
| โโ should return 401 if user is not found
| โโ should return 401 if password is incorrect
โโ server/controllers/forgotPassword.test.js
โโ Forgot password controller
โโ should return 401 if user is not found
โโ should return 401 if password is incorrect
jest.config.js
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
testEnvironment: 'jest-allure2-reporter/environment-node',
reporters: [
'default',
'jest-allure2-reporter',
// You don't need to configure anything special
// to get this structure.
],
};
File-oriented exampleโ
This example might be useful for projects with many test files and relatively few test cases per file.
- Preview
- Structure
- Config
โโ client
โ โโ auth
โ โโ LoginScreen.test.js
โ โ โโ Login screen when loaded should display login form
โ โ โโ Login screen when loaded and typed should validate e-mail
โ โ โโ Login screen when loaded and typed should validate password
โ โโ ForgotPasswordScreen.test.js
โ โโ Forgot password screen when loaded should display forgot password form
โ โโ Forgot password screen when loaded and typed should validate e-mail
โโ server
โโ controllers
โโ login.test.js
โ โโ Login controller should return 401 if user is not found
โ โโ Login controller should return 401 if password is incorrect
โโ ForgotPasswordScreen.test.js
โโ Forgot password controller should return 401 if user is not found
โโ Forgot password controller should return 401 if password is incorrect
jest.config.js
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
testEnvironment: 'jest-allure2-reporter/environment-node',
reporters: [
'default',
['jest-allure2-reporter',
/** @type {import('jest-allure2-reporter').ReporterOptions}*/
{
testCase: {
name: ({ testCase }) => [
...testCase.ancestorTitles,
testCase.title
].join(' ยป '),
labels: {
parentSuite: ({ filePath }) => filePath[0],
suite: ({ filePath }) => filePath[1],
subSuite: ({ filePath }) => filePath.slice(2).join('/'),
},
},
},
],
],
};
Test-oriented exampleโ
This example should fit projects with a smaller number of test files and numerous test cases per file.
- Preview
- Structure
- Config
โโ client/auth/LoginScreen.test.js
โ โโ Login screen
โ โ โโ when loaded
โ โ โ โโ should display login form
โ โ โโ when loaded and typed
โ โ โโ should validate e-mail
โ โ โโ should validate password
โ โโ Forgot password screen
โ โโ when loaded
โ โ โโ should display forgot password form
โ โโ when loaded and typed
โ โโ should validate e-mail
โโ server/controllers/login.test.js
โโ Login controller
โ โโ should return 401 if user is not found
โ โโ should return 401 if password is incorrect
โโ Forgot password controller
โโ should return 401 if user is not found
โโ should return 401 if password is incorrect
jest.config.js
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
testEnvironment: 'jest-allure2-reporter/environment-node',
reporters: [
'default',
['jest-allure2-reporter', /** @type {import('jest-allure2-reporter').ReporterOptions}*/ {
labels: {
parentSuite: ({ filePath }) => filePath.join('/'),
suite: ({ testCase }) => testCase.ancestorTitles[0],
subSuite: ({ testCase }) => testCase.ancestorTitles.slice(1).join(' ') || undefined,
test: ({ testCase }) => testCase.title,
},
}],
],
};