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

Hook only renamed when it fails, not when it begins and ends successfully #4348

Closed
4 tasks done
cspotcode opened this issue Jun 25, 2020 · 1 comment · Fixed by #4383
Closed
4 tasks done

Hook only renamed when it fails, not when it begins and ends successfully #4348

cspotcode opened this issue Jun 25, 2020 · 1 comment · Fixed by #4383
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer

Comments

@cspotcode
Copy link
Contributor

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

A hook's title is only rewritten to include the test's name when it fails. This means the name is inconsistent between hook start and hook failure, which is messing up the logging of a custom reporter. Additionally, the hook name is incomplete when it starts, because it does not include the name of the associated test.

Rewriting is done here: https://github.com/mochajs/mocha/blob/master/lib/runner.js#L419-L432

'hook' event: title = "before each" hook
'fail' event: title = "before each" hook for "name of test case", originalTitle = "before each" hook

Steps to Reproduce

Run this reproduction: https://github.com/cspotcode/repros/tree/mocha-hook-title-discrepancy

Expected behavior: [What you expect to happen]

Hook's title includes the from "name of test case" for all events.

Actual behavior: [What actually happens]

Hook title does not include from "name of test case" suffix in 'hook' event and never includes if it succeeds.

Reproduces how often: [What percentage of the time does it reproduce?]

all the time

Versions

  • mocha --version: N/A, not installed
  • node node_modules/.bin/mocha --version: 8.0.1
  • The output of node --version: v14.2.0
  • Your operating system
    • name and version: Windows 10, WSL2, running Ubuntu 16.04.6 LTS
    • architecture (32 or 64-bit): 64bit
  • Your shell (e.g., bash, zsh, PowerShell, cmd): bash
  • Your browser and version (if running browser tests): N/A
  • Any third-party Mocha-related modules (and their versions): custom reporter which listens to hook, hook end, and fail events
  • Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): none

Additional Information

@boneskull boneskull added type: bug a defect, confirmed by a maintainer status: accepting prs Mocha can use your help with this one! and removed unconfirmed-bug labels Jun 26, 2020
@boneskull
Copy link
Member

I haven't actually confirmed this, but it's certainly plausible. Would hopefully be a pretty straightforward fix

cspotcode added a commit to cspotcode/mocha that referenced this issue Jul 26, 2020
@cspotcode cspotcode mentioned this issue Jul 26, 2020
@boneskull boneskull linked a pull request Jul 29, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants