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

Compatibility with Mocha's parallel mode #967

Merged
merged 6 commits into from
May 23, 2024
Merged

Compatibility with Mocha's parallel mode #967

merged 6 commits into from
May 23, 2024

Conversation

delatrie
Copy link
Collaborator

@delatrie delatrie commented May 22, 2024

Context

The PR allows Allure Mocha to be used with Mocha's --parallel mode. It does so by hooking into Mocha's ParallelBuffered reporter's createListeners in a worker thread. Not perfect, but, you know, lesser of two evils.

The patch is set up by introducing a new module into the list of modules Mocha requires at runtime (via Mocha.MochaOptions.require). The module only affects worker processes.

Extra changes

New ways to pass a writer into the runtime

A writer can now be provided as a string or an array. That makes it easier to pass the config options across process boundaries.

Now, the following ways are supported:

  1. An instance (previously, that was the only way).
  2. A string containing a well-known class name or the full path to a module.
  3. An array of one or more items. The first one must be a well-known class name or the full path to a module, while the rest are the arguments to the constructor of the class.

The list of well-known classes is as follows:

  • AllureInMemoryAllureWriter (all environments)
  • FileSystemAllureWriter (node.js only)
  • AllureInMemoryWriter (node.js only)
  • MessageAllureWriter (node.js only)

The module must export either a writer class or an instance.

Currently, only CJS modules are supported. To support ESM modules, an async extension point is required somewhere in allure-js-commons. Since that's primarily a mechanism to test Allure integrations, we might not urgently need it.

Fixes #619.

Checklist

@github-actions github-actions bot added theme:api Javascript API related issue theme:mocha Mocha related issue labels May 22, 2024
@delatrie delatrie added the type:new feature New feature or request label May 22, 2024
@delatrie delatrie changed the title Mocha parallel fix Compatibility with Mocha in the parallel mode May 22, 2024
@delatrie delatrie changed the title Compatibility with Mocha in the parallel mode Compatibility with Mocha in parallel mode May 22, 2024
@delatrie delatrie changed the title Compatibility with Mocha in parallel mode Compatibility with Mocha's parallel mode May 22, 2024
  - String: the name of a well-known writer or the full path of a module exporting a class or instnce
  - Object with two keys: cls - the same as the above; args: arguments for class ctor
@delatrie delatrie marked this pull request as ready for review May 22, 2024 09:44
Copy link
Member

@epszaw epszaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not able to compile the module due the following error:

λ yarn compile

src/index.ts → dist/index.mjs...
src/setupAllureMochaParallel.ts:3:45 - error TS7016: Could not find a declaration file for module 'mocha/lib/nodejs/reporters/parallel-buffered.js'. '/Users/epszaw/Code/Work/qameta/allure-js/.yarn/cache/mocha-npm-10.3.0-2a85896b70-8b30b3fdb3.zip/node_modules/mocha/lib/nodejs/reporters/parallel-buffered.js' implicitly has an 'any' type.
  If the 'mocha' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mocha'

3 import { default as ParallelBuffered } from "mocha/lib/nodejs/reporters/parallel-buffered.js";
                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error in src/setupAllureMochaParallel.ts:3

ERROR: "compile:types" exited with 2.

packages/allure-mocha/rollup.config.mjs Show resolved Hide resolved
packages/allure-mocha/src/utils.ts Show resolved Hide resolved
packages/allure-js-commons/src/sdk/utils.ts Outdated Show resolved Hide resolved
@delatrie delatrie requested a review from epszaw May 23, 2024 09:13
@delatrie delatrie merged commit 7c66920 into main May 23, 2024
8 checks passed
@delatrie delatrie deleted the mocha-parallel-fix branch May 23, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme:api Javascript API related issue theme:mocha Mocha related issue type:new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mocha parallel mode and Allure API
2 participants