Skip to content

Inconsistent event output in browser with json-stream reporter #3521

@rla

Description

@rla

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 avoiding the use of globally installed Mocha.

Description

There is inconsistent output in browser with json-stream reporter. The start/pass/fail events are printed to stdout as JSON messages but the end event has string 'stdout' prepended to it. I believe that such inconsistency is not necessary.

The inconsistency comes from this line:

process.stdout.write(JSON.stringify(['end', self.stats]));

The end event uses process.stdout.write instead of console.log to print its output. browser-entry module uses the package browser-stdout which optionally prepends a label to console messages. In this case it prepends 'stdout:'.

Steps to Reproduce

  1. Configure Mocha to use json-stream reported in the browser.
  2. Run a trivial test case in browser.
  3. Inspect console output using the page debugger.

Expected behavior: [What you expect to happen]

Events are printed to console as JSON messages.

Actual behavior: [What actually happens]

All events except the end event is printed as JSON messages.

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

All the time.

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version:
mocha --version
bash: mocha: command not found

node node_modules/.bin/mocha --version
5.2.0
  • The output of node --version:
node --version
v10.5.0
  • The version and architecture of your operating system: Debian Stretch amd64
  • Your shell (bash, zsh, PowerShell, cmd, etc.): bash
  • Your browser and version (if running browser tests): Puppeteer 1.9.0, Chromium 594312, Chrome 67.0.3396.99
  • Any other third party Mocha related modules (with versions): none
  • The code transpiler being used: none

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: browserbrowser-specificarea: reportersinvolving a specific reportertype: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions