Skip to content

Commit

Permalink
add jest circus integration (fixes #282, via #752)
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw authored Aug 25, 2023
1 parent 1a4d4b5 commit b28b9c3
Show file tree
Hide file tree
Showing 45 changed files with 2,587 additions and 146 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ This project aggregates Allure Javascript commons and reporters.

[Read more](/packages/allure-cucumberjs/README.md)

### Jasmine
### Jest (`jest@>=27.x.x`)

![npm](https://img.shields.io/npm/dm/allure-jasmine.svg) ![npm](https://img.shields.io/npm/v/allure-jasmine.svg)
![npm](https://img.shields.io/npm/dm/allure-jest.svg) ![npm](https://img.shields.io/npm/v/allure-jest.svg)

[Read more](/packages/allure-jasmine/README.md)
[Read more](/packages/allure-jest/README.md)

### Jest (Jasmine)
### Jasmine and Jest (`jest@<27.x.x`)

Currently, we don't have official solution for circus test runner. Consider using [this community plugin](https://github.com/ryparker/jest-circus-allure-environment) instead.
![npm](https://img.shields.io/npm/dm/allure-jasmine.svg) ![npm](https://img.shields.io/npm/v/allure-jasmine.svg)

[Read more](/packages/allure-jest/README.md)
[Read more](/packages/allure-jasmine/README.md)

### Mocha

Expand Down Expand Up @@ -52,7 +52,6 @@ Currently, we don't have official solution for circus test runner. Consider usin

[Read more](/packages/allure-hermione/README.md)


### CodeceptJS

![npm](https://img.shields.io/npm/dm/allure-codeceptjs.svg) ![npm](https://img.shields.io/npm/v/allure-codeceptjs.svg)
Expand Down
1 change: 1 addition & 0 deletions packages/allure-cucumberjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"chai-things": "^0.2.0",
"glob": "^8.0.0",
"mocha": "^9.1.1",
"mocha-multi-reporters": "^1.5.1",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"sinon": "^14.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/allure-hermione/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@types/selenium-standalone": "^7.0.1",
"chai": "^4.2.0",
"codecov": "^3.6.5",
"dotenv": "^10.0.0",
"fs-jetpack": "^4.1.0",
"glob": "^7.1.7",
"hermione": "^6.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-hermione/test/runner.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// custom runner for mocha that allows to include a custom reporter
// which is not packed into an npm module
import path from "path";
import { TestResult } from "allure-js-commons";
import glob from "glob";
import Mocha from "mocha";
import selenium from "selenium-standalone";
import "source-map-support/register";
import { TestResult } from "allure-js-commons";

export const getTestResultByName = (results: TestResult[], name: string) =>
results.find((result) => result.name === name)!;
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-hermione/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "../../tsconfig.json",
"include": ["./src/**/*", "./index.ts"],
"include": ["./src/**/*"],
"compilerOptions": {
"types": ["node", "chai"],
"lib": ["dom"],
Expand Down
39 changes: 39 additions & 0 deletions packages/allure-jasmine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,42 @@
Allure integration Jasmine framework

For usage example see `test/Setup.ts`

## Usage with Jest (`jest@<27`)

Use your favorite node package manager to install required packages:

```bash
npm add -D jest-jasmine2 allure-jasmine allure-js-commons @types/jasmine
```

Create `allure-setup.ts` file:

```ts
import { JasmineAllureReporter } from "allure-jasmine";
import { JasmineAllureInterface } from "allure-jasmine/dist/src/JasmineAllureReporter";

const reporter = new JasmineAllureReporter({ resultsDir: "allure-results" });

jasmine.getEnv().addReporter(reporter);
// @ts-expect-error
global.allure = reporter.getInterface();

declare global {
const allure: JasmineAllureInterface;
}
```

Change your `jest.config.js` file:

```js
module.exports = {
preset: "ts-jest",
+ testRunner: "jest-jasmine2",
+ setupFilesAfterEnv: ["./allure-setup.ts"],
};
```

You can find example setup and usage in this [repo](https://github.com/vovsemenv/allure-jest-example)

[allure-jest]: https://github.com/allure-framework/allure-js/tree/master/packages/allure-jest
16 changes: 5 additions & 11 deletions packages/allure-jest/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
module.exports = {
extends: ["../../.eslintrc.js"],
globals: {
__PATH_PREFIX__: true,
allure: true,
},
env: {
browser: true,
node: true,
es6: true,
jasmine: true,
jest: true
},
extends: [
"../../.eslintrc.js",
],
};
jest: true,
}
}
64 changes: 31 additions & 33 deletions packages/allure-jest/README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
# Allure integration for jest framework
# allure-jest

> **Warning**
> This integration doesn't work with default runner since jest 27+.
> To use this integration after jest 27 you need to change default runner to `Jasmine`.
> If you are using `jest@<27.0.0` use [`allure-jasmine` package][allure-jasmine]
> or consider to use `jest-circus` as a test runner with this package.
>
> The integration doesn't work with custom runners. If you want to use the
> integration use `jest-circus` as a test runner.
## Examples
## Installation

You can find example setup and usage in this [repo](https://github.com/vovsemenv/allure-jest-example)
Use your favorite node package manager to install required packages:

## Circus test runner (default for jest@^27)

Currently, we don't have official solution for circus test runner. Consider using this [community plugin](https://github.com/ryparker/jest-circus-allure-environment) instead
```shell
npm add -D allure-jest allure-js-commons
```

## Jasmine test runner (default for jest@<27)
Then, add following line to your `jest.config.js` file:

### Install dependencies
```diff
/** @type {import('jest').Config} */
const config = {
+ testEnvironment: "allure-jest",
}

```bash
npm i -D jest-jasmine2@INSTALLED_JEST_VERSION allure-jasmine allure-js-commons @types/jasmine
module.exports = config
```

Create `allure-setup.ts` file:

```typescript
import { JasmineAllureReporter } from "allure-jasmine";
import { JasmineAllureInterface } from "allure-jasmine/dist/src/JasmineAllureReporter";
## Use Allure runtime Api

const reporter = new JasmineAllureReporter({ resultsDir: "allure-results" });
jasmine.getEnv().addReporter(reporter);
// @ts-expect-error
global.allure = reporter.getInterface();
The plugin provides custom global commands which allow to add additional info
inside your tests:

declare global {
const allure: JasmineAllureInterface;
}
```javascript
it("my test", () => {
allure.attachment(currentTest.id(), screenshot, "image/png");
allure.epic(currentTest.id(), "my_epic");
allure.parameter(currentTest.id(), "parameter_name", "parameter_value", {
mode: "hidden",
excluded: false,
});
});
```

### Change jest.config.js

```js
module.exports = {
testRunner: "jest-jasmine2",
preset: "ts-jest",
setupFilesAfterEnv: ["./allure-setup.ts"],
};
```
[allure-jasmine]: https://github.com/allure-framework/allure-js/tree/master/packages/allure-jasmine
75 changes: 64 additions & 11 deletions packages/allure-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,92 @@
{
"private": true,
"name": "allure-jest",
"version": "2.5.0",
"description": "Allure Jest integration",
"license": "Apache-2.0",
"packageManager": "[email protected]",
"author": {
"name": "Qameta Software",
"email": "[email protected]",
"url": "https://qameta.io/"
},
"keywords": [
"jest",
"circus",
"typescript",
"allure"
],
"repository": {
"type": "git",
"url": "https://github.com/allure-framework/allure-js.git",
"directory": "packages/allure-jest"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"clean": "rimraf ./dist ./out",
"lint": "eslint ./test --ext .ts",
"lint:fix": "eslint ./test --ext .ts --fix",
"compile": "tsc",
"generate-report": "allure generate ./out/allure-results -o ./out/allure-report --clean",
"jasmineTest": "jest --config ./test/default-runner/jest.config.js",
"test": "rimraf ./out; yarn run jasmineTest"
"test": "nyc tsx --tsconfig ./tsconfig.json ./test/runner.ts",
"coverage": "codecov",
"lint": "eslint ./src --ext .ts",
"lint:fix": "eslint ./src --ext .ts --fix"
},
"nyc": {
"check-coverage": false,
"lines": 80,
"statements": 80,
"functions": 75,
"branches": 70,
"extension": [
".ts"
],
"exclude": [
"test/**/*.*",
"**/*.d.ts"
],
"reporter": [
"lcov",
"text"
],
"all": true,
"report-dir": "./out/coverage",
"temp-dir": "./out/.nyc"
},
"devDependencies": {
"@jest/core": "^29.6.2",
"@jest/environment": "^29.6.2",
"@jest/types": "^29.6.1",
"@types/chai": "^4.3.5",
"@types/chai-like": "^1.1.1",
"@types/chai-things": "^0.0.35",
"@types/glob": "^8.1.0",
"@types/jasmine": "^3.3.12",
"@types/jest": "^26.0.10",
"allure-jasmine": "workspace:*",
"jest": "^26.4.2",
"@types/jest": "^29.5.3",
"@types/mocha": "^10.0.1",
"@types/node": "^16.7.8",
"@types/sinon": "^10.0.16",
"@types/source-map-support": "^0",
"chai": "^4.3.7",
"chai-like": "^1.1.1",
"chai-things": "^0.2.0",
"codecov": "^3.8.3",
"glob": "^7.1.7",
"jest-cli": "^29.6.2",
"mocha": "^10.2.0",
"mocha-multi-reporters": "^1.5.1",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"typescript": "^4.4.2"
"sinon": "^15.2.0",
"source-map-support": "^0.5.21",
"tsx": "^3.12.7",
"typescript": "^5.1.3"
},
"dependencies": {
"allure-js-commons": "workspace:*"
"@jest/expect": "^29.6.2",
"allure-js-commons": "workspace:*",
"jest-circus": "^29.6.2",
"jest-environment-node": "^29.6.2"
}
}
Loading

0 comments on commit b28b9c3

Please sign in to comment.