Skip to content

reporters should be immune to interference with STDOUT #3604

@boneskull

Description

@boneskull

Potentially related: #2943

If a reporter uses console.log(), it should retain the function like we do with timers.

This will theoretically allow users to stub out console.log() in their own tests without affecting reporter output.

Since console.log() expects this to be console, it likely needs to take a form of:

const log = console.log.bind(console);

process.stdout.write() may need to be consumed in a similar manner.

To reproduce the problem:

// yuck.spec.js
it('should do, but it do not', function() {
  // user wants to hide output generated by console.log calls in fn 'foo'
  console.log = function() {};
  foo();
});

Another approach would be to instantiate our own Console object (docs) which would bypass the global console entirely. We could consider subclassing Console in order to provide a nice abstraction for reporters consuming process.stdout directly (or other streams).

A workaround (for the user) would be to use something like proxyquire, rewiremock, etc. in lieu of replacing the method outright, like one would with Sinon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: accepting prsMocha can use your help with this one!type: 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