• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mochajs / mocha / 7452
94%
main: 94%

Build:
Build:
LAST BUILD BRANCH: v11.x
DEFAULT BRANCH: main
Ran 19 May 2020 12:07AM UTC
Jobs 1
Files 49
Run time 5s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
7452

push

travis-ci

boneskull
add Root Hook Plugins

(documentation will be in another PR)

Adds "root hook plugins", a system to define root hooks via files loaded with `--require`.

This enables root hooks to work in parallel mode.  Because parallel mode runs files in a non-deterministic order, and files do not share a `Mocha` instance, it is not possible to share these hooks with other test files.  This change also works well with third-party libraries for Mocha which need the behavior; these can now be trivially consumed by adding `--require` or `require: 'some-library'` in Mocha's config file.

The way it works is:

1. When a file is loaded via `--require`, we check to see if that file exports a property named `mochaHooks` (can be multiple files).
1. If it does, we save a reference to the property.
1. After Yargs' validation phase, we use async middleware to execute root hook plugin functions--or if they are objects, just collect them--and we flatten all hooks found into four buckets corresponding to the four hook types.
1. Once `Mocha` is instantiated, if it is given a `rootHooks` option, those hooks are applied to the root suite.

This works with parallel tests because we can save a reference to the flattened hooks in each worker process, and a new `Mocha` instance is created with them for each test file.

* * *

Tangential:

- Because a root hook plugin can be defined as an `async` function, I noticed that `utils.type()` does not return `function` for async functions; it returns `asyncfunction`.  I've added a (Node-specific, for now) test for this.

- `handleRequires` is now `async`, since it will need to be anyway to support ESM and calls to `import()`.

- fixed incorrect call to `fs.existsSync()`

Ref: #4198

1066 of 1236 branches covered (86.25%)

45 of 45 new or added lines in 3 files covered. (100.0%)

2857 of 3063 relevant lines covered (93.27%)

553.16 hits per line

Jobs
ID Job ID Ran Files Coverage
6 7452.6 19 May 2020 12:07AM UTC 0
93.27
Travis Job 7452.6
Source Files on build 7452
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #7452
  • 722ce012 on github
  • Prev Build on master (#7449)
  • Next Build on master (#7467)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc