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

mochajs / mocha / 5477
94%
main: 94%

Build:
Build:
LAST BUILD BRANCH: v11.x
DEFAULT BRANCH: main
Ran 28 Jan 2019 07:11PM UTC
Jobs 1
Files 46
Run time 22min
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
5477

push

travis-ci

boneskull
Fix Hook Test Names (#3573); closes #1638, closes #3291, closes #2134

### Description of bug
Mocha shows an incorrect test-title if a nested `before` hook fails. For `after` hooks the second part of the message is completely missing.
```js
describe('Top-level describe', () => {
  it('Top-level it', () => { });       // the failing before-hook is pointing to this test
  describe('Nested describe', () => {
    before(() => {
      throw new Error();
    });
    it('Nested it', () => { });        // but it should point to this test
  });
});
```
```
Top-level describe
    ✓ Top-level it
    Nested describe
      1) "before all" hook for "Top-level it"       <<<incorrect
```
Root problem: see [#1638](https://github.com/mochajs/mocha/issues/1638). `hook.ctx.currentTest` is set incorrectly in the hook before emitting the hook event:
- `before` hook: currentTest is undefined or points to the outer test already past successfully.
The runner hasn't reached the next test to come yet, so it's too early to derive currentTest from the runner. Instead the first test of hook's parent is used.
- `after` hook: currentTest is undefined.
The runner has already completed the latest test and runner.currentTest is deleted. Instead the last test of hook's parent is used.

### Description of the Change
#### 1. Setting currentTest correctly
- `before` hook: hook.ctx.currentTest is set to the first test of the parent suite
- `after hook`: hook.ctx.currentTest is set to the last test of the parent suite
- for nested suites just the current suite is searched for tests to come. When no tests can be found, currentTest remains undefined.

#### 2. Creating title in hook failure message
A correct `hook.ctx.currentTest` renders a correct title. 
When no currentTest can be found, the title of the parent suite is used for the hook failure message.

### Alternate Designs
PR [#3333](https://github.com/mochajs/mocha/pull/3333)

### Benefits

This is... (continued)

948 of 1145 branches covered (82.79%)

10 of 10 new or added lines in 1 file covered. (100.0%)

2449 of 2688 relevant lines covered (91.11%)

544.15 hits per line

Jobs
ID Job ID Ran Files Coverage
7 5477.7 28 Jan 2019 07:11PM UTC 0
91.11
Travis Job 5477.7
Source Files on build 5477
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #5477
  • 1f36ec54 on github
  • Prev Build on master (#5471)
  • Next Build on master (#5501)
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