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

Example Custom Reporter Provides No Output at All When There's a Warning #48894

Closed
machineghost opened this issue Jul 23, 2023 · 1 comment · Fixed by #48903
Closed

Example Custom Reporter Provides No Output at All When There's a Warning #48894

machineghost opened this issue Jul 23, 2023 · 1 comment · Fixed by #48903
Labels
doc Issues and PRs related to the documentations. test_runner Issues and PRs related to the test runner subsystem.

Comments

@machineghost
Copy link

Version

20.3.0

Platform

Linux mycomputer 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

test

What steps will reproduce the bug?

  1. Create a copy of the sample custom test reporter (https://nodejs.org/api/test.html#custom-reporters)
  2. Add --test-reporter=./test/testReporter.js to node test testFile.js
  3. (Also add some other argument that causes a warning, eg. --experimental-loader ./loader.js)
  4. Run tests

How often does it reproduce? Is there a required condition?

100% reproducible (for me at least)

What is the expected behavior? Why is that the expected behavior?

You see some (customized) test output.

What do you see instead?

You see nothing:

$ npm t

> test-app@0.1.0 test
> > node --experimental-loader ./loader.js  --test-reporter=./test/testReporter.js --test test.js

Additional information

First off, let me just say the built-in Node test runner is great (or at least a really great start), and I very much appreciate this feature! No more mocha/jest/ava/other annoying dependencies!

As for the issue, this is happening because the example test reporter has a switch/case statement, and it doesn't include a case for when event.type === 'test:stderr'. If you add:

default:
        console.log(event);

to the custom reporter's switch, you instead see:

(node:578700) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
{
  type: 'test:stderr',
  data: [Object: null prototype] {
    file: '/home/me/myproject/test/test.js',
    message: '(node:578712) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time\n'
  }
}

As someone new to custom reporters, it was very confusing to add the example one and get absolutely no output whatsoever. It seems to me that the sample test reporter should either:

A) If unexpected events (eg. warnings) are "errors", the sample test runner should treat them as such:

default:
    throw new Error('Unexpected event' + event.type)

B) if warnings and other events are expected (as it seems they should be), but they shouldn't output, that should instead be:

default:
  callback(null);

C) If warnings are expected, and should output (I think this is correct) it should be:

case 'test:warning':
  callback(null, 'test:warning');

However, if you go with C), it seems some sort of default (like A or B) should be included also, to handle any other unexpected events in some way (besides silently swallowing them).

@koshic
Copy link

koshic commented Jul 23, 2023

@machineghost the root cause is that we must invoke callback in transform handler to get next available chunk. So, example code is wrong due to incorrect stream usage.

+1 to provide default case to the switch statement or change logic by introducing intermediate variable to store message and always invoke callback(null, message) at function end.

@atlowChemi atlowChemi added doc Issues and PRs related to the documentations. test_runner Issues and PRs related to the test runner subsystem. labels Jul 24, 2023
atlowChemi added a commit to atlowChemi/node that referenced this issue Jul 24, 2023
atlowChemi added a commit to atlowChemi/node that referenced this issue Jul 25, 2023
nodejs-github-bot pushed a commit that referenced this issue Jul 26, 2023
Fixes: #48894
PR-URL: #48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Ceres6 pushed a commit to Ceres6/node that referenced this issue Jul 27, 2023
Fixes: nodejs#48894
PR-URL: nodejs#48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
pluris pushed a commit to pluris/node that referenced this issue Aug 6, 2023
Fixes: nodejs#48894
PR-URL: nodejs#48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
pluris pushed a commit to pluris/node that referenced this issue Aug 7, 2023
Fixes: nodejs#48894
PR-URL: nodejs#48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Ceres6 pushed a commit to Ceres6/node that referenced this issue Aug 14, 2023
Fixes: nodejs#48894
PR-URL: nodejs#48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Ceres6 pushed a commit to Ceres6/node that referenced this issue Aug 14, 2023
Fixes: nodejs#48894
PR-URL: nodejs#48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
UlisesGascon pushed a commit to UlisesGascon/node that referenced this issue Aug 14, 2023
Fixes: nodejs#48894
PR-URL: nodejs#48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
RafaelGSS pushed a commit that referenced this issue Aug 15, 2023
Fixes: #48894
PR-URL: #48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
RafaelGSS pushed a commit that referenced this issue Aug 17, 2023
Fixes: #48894
PR-URL: #48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this issue Oct 28, 2023
Fixes: #48894
PR-URL: #48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
sercher added a commit to sercher/graaljs that referenced this issue Apr 25, 2024
Fixes: nodejs/node#48894
PR-URL: nodejs/node#48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
sercher added a commit to sercher/graaljs that referenced this issue Apr 25, 2024
Fixes: nodejs/node#48894
PR-URL: nodejs/node#48903
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants