jest-allure
Version:
Allure Reports for jest
151 lines (111 loc) • 5.18 kB
Markdown
//cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/jest-community/awesome-jest)
[](https://opensource.org/licenses/MIT)
[](http://makeapullrequest.com)
[](https://github.com/zaqqaz)
[](https://github.com/zaqqaz/jest-allure/stargazers)
[](https://github.com/zaqqaz/jest-allure/watchers)
- [Report example](https://103-170502579-gh.circle-artifacts.com/0/Report/Allure/index.html)
- [Visual unit tests with allure report. Demo project](https://github.com/zaqqaz/visual-unit-tests)
- [Simple integration test](https://github.com/zaqqaz/jest-allure/blob/master/examples/__tests__/test1.js)
<hr>

[ ](https://github.com/allure-framework/allure2) is a flexible lightweight multi-language test report tool that not only
shows a very concise representation of what have been tested in a neat web report form,
but allows everyone participating in the development process to extract maximum of useful
information from everyday execution of tests.
```
yarn add -D jest-allure
```
or
```
npm install --save-dev jest-allure
```
Then add `jest-allure/dist/setup` to `setupFilesAfterEnv` section of your config.
```
setupFilesAfterEnv: ["jest-allure/dist/setup"]
```
```
reporters: ["default", "jest-allure"],
```
Run your tests and enjoy 🥤🚀
---
You need to install the [CLI](https://github.com/allure-framework/allure2#download) in order to obtain a report.
To see a report in browser, run in console
```
allure serve
```
If you want to generate html version, run in console
```
allure generate
```
You can add description, screenshots, steps, severity and lots of other
fancy stuff to your reports.
Global variable `reporter` available in your tests with such methods:
```
description(description: string): this;
severity(severity: Severity): this;
epic(epic: string): this;
feature(feature: string): this;
story(story: string): this;
startStep(name: string): this;
endStep(status?: Status): this;
addArgument(name: string): this;
addEnvironment(name: string, value: string): this;
addAttachment(name: string, buffer: any, type: string): this;
addLabel(name: string, value: string): this;
addParameter(paramName: string, name: string, value: string): this;
```
**Example**
```
import { Severity } from "jest-allure/dist/Reporter";
import { Feature } from "somwhere in your project";
describe("Fancy test", () => {
...
it("Test your amazing feature", async () => {
reporter
.description("Feature should work cool")
.severity(Severity.Critical)
.feature(Feature.Betting)
.story("BOND-007");
reporter.startStep("Check it's fancy");
// expect that it's fancy
reporter.endStep();
reporter.startStep("Check it's cool");
// expect that it's cool
reporter.endStep();
const screenshotBuffer = await page.screenshot();
reporter.addAttachment("Screenshot", screenshotBuffer, "image/png");
});
...
}
);
```
- [x] Generate report from Jest results
- [x] Add steps support
- [x] Add labels support
- [x] Add attachments support
- [x] Add more examples
---
[ ](https://github.com/zaqqaz/visual-unit-tests)
[ ](https://github.com/zaqqaz/jest-allure-image-snapshot)
``jest-allure`` reporter dynamically configure "setupTestFrameworkScriptFile" option in Jest configuration.
**If you have your own setupTestFrameworkScriptFile file**, you need to manually register allure reporter, for it you need to import jest-allure/dist/setup.
```typescript
import "jest-allure/dist/setup";
```
In case if you have jest version > 24 just add `jest-allure/dist/setup` to `setupFilesAfterEnv` section of your config.
| [<img src="https://avatars3.githubusercontent.com/u/2823336?s=460&v=4" width="100px;"/><br/><sub><b>Denis Artyuhovich</b></sub>](https://denis.by) | [<img src="https://avatars1.githubusercontent.com/u/7804416?s=460&v=4" width="100px;"/><br/><sub><b>Dmitry Bogomya</b></sub>](https://github.com/bogomya) |
| --- | --- |
[![Awesome](https: