Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add error notification when user try to use mocha reporter in paralle… #620

Merged
merged 4 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/allure-mocha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This project implements Allure integration with Mocha framework.

**Allure API doesn't work in parallel mode**! If you want to use the functionality, please switch back to single thread mode!

## Installation

```bash
Expand Down Expand Up @@ -48,7 +50,7 @@ it("is a test", () => {
### Parameters usage

```ts
import { allure } from "allure-mocha/runtime";
import allureMocha from "allure-mocha/runtime";

it("is a test", () => {
allureMocha.allure.parameter("parameterName", "parameterValue");
Expand All @@ -61,7 +63,7 @@ Also addParameter takes an third optional parameter with the hidden and excluded
`excluded: true` - excludes parameter from the history

```ts
import { allure } from "allure-mocha/runtime";
import allureMocha from "allure-mocha/runtime";

it("is a test", () => {
allureMocha.allure.parameter("parameterName", "parameterValue", {
Expand Down
2 changes: 2 additions & 0 deletions packages/allure-mocha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@types/glob": "^8.0.0",
"@types/mocha": "^9.0.0",
"@types/node": "^16.7.8",
"@types/sinon": "^10.0.13",
"chai": "^4.2.0",
"codecov": "^3.6.5",
"fs-jetpack": "^4.1.0",
Expand All @@ -45,6 +46,7 @@
"mocha-multi-reporters": "^1.5.1",
"nyc": "^15.0.1",
"rimraf": "^3.0.2",
"sinon": "^15.0.1",
"source-map-support": "^0.5.19",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
Expand Down
7 changes: 5 additions & 2 deletions packages/allure-mocha/src/MochaAllureReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AllureConfig, AllureRuntime } from "allure-js-commons";
import * as Mocha from "mocha";
import { AllureReporter } from "./AllureReporter";
import { MochaAllure } from "./MochaAllure";
import Base = Mocha.reporters.Base;
import { ParallelMochaAllure } from "./ParallelMochaAllure";

const {
EVENT_SUITE_BEGIN,
Expand All @@ -16,7 +16,9 @@ const {
EVENT_HOOK_END,
} = Mocha.Runner.constants;

export let allure: MochaAllure;
// eslint-disable-next-line
// @ts-ignore
export let allure: MochaAllure = new ParallelMochaAllure();

type ParallelRunner = Mocha.Runner & {
linkPartialObjects?: (val: boolean) => ParallelRunner;
Expand All @@ -35,6 +37,7 @@ export class MochaAllureReporter extends Mocha.reporters.Base {
};

this.coreReporter = new AllureReporter(new AllureRuntime(allureConfig));

allure = this.coreReporter.getImplementation();

if (runner.linkPartialObjects) {
Expand Down
43 changes: 43 additions & 0 deletions packages/allure-mocha/src/ParallelMochaAllure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export class ParallelMochaAllure {
constructor() {
const methods = [
"epic",
"feature",
"story",
"suite",
"parentSuite",
"subSuite",
"label",
"parameter",
"link",
"issue",
"ims",
"description",
"descriptionHtml",
"owner",
"severity",
"layer",
"id",
"tag",
"writeEnvironmentInfo",
"writeCategoriesDefinitions",
"attachment",
"logStep",
"step",
];

methods.forEach((method) => {
// eslint-disable-next-line
// @ts-ignore
this[method] = this.stubMethod(method);
});
}

private stubMethod(methodName: string) {
return () =>
// eslint-disable-next-line
console.error(
`MochaAllure: "${methodName}" can't be used in parallel mode! To use Allure Runtime API, please, switch back to single thread mode.`,
);
}
}
1 change: 0 additions & 1 deletion packages/allure-mocha/test/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const mocha = new Mocha({
reporter: "mocha-multi-reporters",
reporterOptions: {
reporterEnabled: "list, ../allure-mocha",
parallel: true,
allureMochaReporterOptions: {
resultsDir: path.resolve(__dirname, "../out/allure-results"),
},
Expand Down
67 changes: 67 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,24 @@ __metadata:
languageName: node
linkType: hard

"@sinonjs/commons@npm:^2.0.0":
version: 2.0.0
resolution: "@sinonjs/commons@npm:2.0.0"
dependencies:
type-detect: 4.0.8
checksum: 5023ba17edf2b85ed58262313b8e9b59e23c6860681a9af0200f239fe939e2b79736d04a260e8270ddd57196851dde3ba754d7230be5c5234e777ae2ca8af137
languageName: node
linkType: hard

"@sinonjs/fake-timers@npm:10.0.2, @sinonjs/fake-timers@npm:^10.0.2":
version: 10.0.2
resolution: "@sinonjs/fake-timers@npm:10.0.2"
dependencies:
"@sinonjs/commons": ^2.0.0
checksum: c62aa98e7cefda8dedc101ce227abc888dc46b8ff9706c5f0a8dfd9c3ada97d0a5611384738d9ba0b26b59f99c2ba24efece8e779bb08329e9e87358fa309824
languageName: node
linkType: hard

"@sinonjs/fake-timers@npm:>=5, @sinonjs/fake-timers@npm:^9.1.2":
version: 9.1.2
resolution: "@sinonjs/fake-timers@npm:9.1.2"
Expand Down Expand Up @@ -1164,6 +1182,17 @@ __metadata:
languageName: node
linkType: hard

"@sinonjs/samsam@npm:^7.0.1":
version: 7.0.1
resolution: "@sinonjs/samsam@npm:7.0.1"
dependencies:
"@sinonjs/commons": ^2.0.0
lodash.get: ^4.4.2
type-detect: ^4.0.8
checksum: 291efb158d54c67dee23ddabcb28873d22063449b692aaa3b2a4f1826d2f79d38695574063c92e9c17573cc805cd6acbf0ab0c66c9f3aed7afd0f12a2b905615
languageName: node
linkType: hard

"@sinonjs/text-encoding@npm:^0.7.1":
version: 0.7.1
resolution: "@sinonjs/text-encoding@npm:0.7.1"
Expand Down Expand Up @@ -1584,6 +1613,15 @@ __metadata:
languageName: node
linkType: hard

"@types/sinon@npm:^10.0.13":
version: 10.0.13
resolution: "@types/sinon@npm:10.0.13"
dependencies:
"@types/sinonjs__fake-timers": "*"
checksum: 46a14c888db50f0098ec53d451877e0111d878ec4a653b9e9ed7f8e54de386d6beb0e528ddc3e95cd3361a8ab9ad54e4cca33cd88d45b9227b83e9fc8fb6688a
languageName: node
linkType: hard

"@types/sinonjs__fake-timers@npm:*":
version: 8.1.2
resolution: "@types/sinonjs__fake-timers@npm:8.1.2"
Expand Down Expand Up @@ -2207,6 +2245,7 @@ __metadata:
"@types/glob": ^8.0.0
"@types/mocha": ^9.0.0
"@types/node": ^16.7.8
"@types/sinon": ^10.0.13
allure-js-commons: "workspace:*"
chai: ^4.2.0
codecov: ^3.6.5
Expand All @@ -2216,6 +2255,7 @@ __metadata:
mocha-multi-reporters: ^1.5.1
nyc: ^15.0.1
rimraf: ^3.0.2
sinon: ^15.0.1
source-map-support: ^0.5.19
ts-node: ^10.2.1
typescript: ^4.4.2
Expand Down Expand Up @@ -9343,6 +9383,19 @@ __metadata:
languageName: node
linkType: hard

"nise@npm:^5.1.2":
version: 5.1.4
resolution: "nise@npm:5.1.4"
dependencies:
"@sinonjs/commons": ^2.0.0
"@sinonjs/fake-timers": ^10.0.2
"@sinonjs/text-encoding": ^0.7.1
just-extend: ^4.0.2
path-to-regexp: ^1.7.0
checksum: bc57c10eaec28a6a7ddfb2e1e9b21d5e1fe22710e514f8858ae477cf9c7e9c891475674d5241519193403db43d16c3675f4207bc094a7a27b7e4f56584a78c1b
languageName: node
linkType: hard

"no-case@npm:^3.0.4":
version: 3.0.4
resolution: "no-case@npm:3.0.4"
Expand Down Expand Up @@ -11526,6 +11579,20 @@ __metadata:
languageName: node
linkType: hard

"sinon@npm:^15.0.1":
version: 15.0.1
resolution: "sinon@npm:15.0.1"
dependencies:
"@sinonjs/commons": ^2.0.0
"@sinonjs/fake-timers": 10.0.2
"@sinonjs/samsam": ^7.0.1
diff: ^5.0.0
nise: ^5.1.2
supports-color: ^7.2.0
checksum: 4b5acff291b4650cf736bf45fc9eceed44dceca63b663cbd55926dd688fe8e9baa4b4629e296ee5d5b64245aedec5c540fea0416b8bb35bccfb98ca9e9ed87f3
languageName: node
linkType: hard

"sisteransi@npm:^1.0.5":
version: 1.0.5
resolution: "sisteransi@npm:1.0.5"
Expand Down