AleG94 / mocha-suppress-logs

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

TypeError in afterEach when test has no output at all #12

Closed tripodsan closed 5 months ago

tripodsan commented 8 months ago

problem I have a test with no output, then I get the following error:

TypeError: Cannot read properties of undefined (reading 'stream')
    at Context.afterEach (node_modules/mocha-suppress-logs/index.js:14:29)
    at process.processImmediate (node:internal/timers:476:21)

workaround add process.stdout.write('')

note I'm running the tests within webstorm, and they set their own reporter:

--reporter /Users/shared/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-0/232.10203.14/WebStorm.app/Contents/plugins/nodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js

I assume they don't write anything to stdout.

tripodsan commented 8 months ago

here a debugging session:

image

dominique-pfister commented 8 months ago

Can also be reproduced by using the min builtin mocha reporter for some test that produces no output.

drew-mobiquity commented 8 months ago

I have also noticed it to be an issue when using mocha-junit-reporter (no problems with 0.3.1) same error as above gets written to the junit output file

tripodsan commented 8 months ago

workaround add a setup hook:

package.json

....
  "mocha": {
    "require": [
      "test/setup-env.js",
    ],
  },
...

test/setup-env.js

export const mochaHooks = {
  beforeEach() {
    process.stderr.write('');
  },
};