AleG94 / mocha-suppress-logs

Suppress console output of successful mocha tests
MIT License
13 stars 3 forks source link

Bring back optional context based suppress #7

Closed nopeless closed 3 years ago

nopeless commented 3 years ago

I don't want global suppression of console.logs

The feature that was in v2.0 was removed

const suppressLogs = require('mocha-suppress-logs');

describe('Something', () => {
  suppressLogs();

  it('should do something', () => {
    // test code
  });
});

I don't see why this functionality was not compatible with v3.0

Please consider bringing it back

nopeless commented 3 years ago

tried to edit the code myself only to find myself struggling with this context

vassudanagunta commented 3 years ago

@nopeless

I don't see why this functionality was not compatible with v3.0

Essentially that functionality became impossible when converting mocha-suppress-logs to use Root Hook Plugins, which is the proper way it "you may want a hook before (or after) every test in every file". This change decoupled mocha-suppress-logs from the Mocha BDD interface; Now it should work with any interface, even custom ones.

See the discussion starting at this comment.

If you can figure out a way to bring that back within a Root Hook Plugin, I'm sure it would be welcome.

nopeless commented 3 years ago

I ended up creating a temporary wrapper that replaces console[level] variants to a log class (similar to what you did) your code gave me some inspiration

I think I should wait until mocha gives a mock function api like jest (might be wrong)

anyway it was because my specific library has a console.error instead of throw because it listens for file writes.