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

test_runner API doc example invalid #47312

Closed
ForbiddenEra opened this issue Mar 30, 2023 · 3 comments
Closed

test_runner API doc example invalid #47312

ForbiddenEra opened this issue Mar 30, 2023 · 3 comments
Labels
doc Issues and PRs related to the documentations. test_runner Issues and PRs related to the test runner subsystem.

Comments

@ForbiddenEra
Copy link

Affected URL(s)

https://nodejs.org/api/test.html

Description of the problem

This might also include some buggy behavior, though that could be down to a bad/deprecated example in the docs.

When attempting to run a test with the given example:

run({ files: [path.resolve('./tests/test.js')] })
  .pipe(process.stdout);

If there's any error in the calling file or the test, you get:

node:internal/streams/writable:315
      throw new ERR_INVALID_ARG_TYPE(
      ^

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object
    at new NodeError (node:internal/errors:399:5)
    at _write (node:internal/streams/writable:315:13)
    at Writable.write (node:internal/streams/writable:337:10)
    at TestsStream.ondata (node:internal/streams/readable:766:22)
    at TestsStream.emit (node:events:512:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at #tryPush (node:internal/test_runner/tests_stream:69:28)
    at #emit (node:internal/test_runner/tests_stream:64:18) {
  code: 'ERR_INVALID_ARG_TYPE'
}

If there's no errors, then it just hangs with no output.

The same test runs fine with node --test.

Observing the returned TestsStream for the listed events in the docs (['test:start', 'test:pass', 'test:fail', 'test:diagnostic', 'test:coverage']) and printing the resulting objects shows the test running fine.

Also, using a TransformStream and printing the objects also shows the test running fine.

The error that's shown only when there's an actual error in the file (eg. passing a non-existent file to files for run) hints that TestsStream is now Object Mode which I guess can't be piped directly to stdout without transformation of some sort.

However, this error doesn't appear when the tests would run in the other aforementioned cases and node seems to just stop and sit there, it will print a console.log message placed before and after the run call and then just sit there indefinitely, even with a timeout set, a timeout verified working with the other methods.

@ForbiddenEra ForbiddenEra added the doc Issues and PRs related to the documentations. label Mar 30, 2023
@MoLow MoLow added the test_runner Issues and PRs related to the test runner subsystem. label Mar 30, 2023
@MoLow
Copy link
Member

MoLow commented Mar 30, 2023

Duplicate of #47231

@MoLow MoLow marked this as a duplicate of #47231 Mar 30, 2023
@MoLow MoLow closed this as completed Mar 30, 2023
@ForbiddenEra
Copy link
Author

Hi, maybe partially a duplicate but the linked issue doesn't reference the separate issue I pointed out where it simply hangs, it only references when it has an exception.

Also, that issue is a bug report (which perhaps should be made regarding the hanging) while this is a docs issue; while the docs issue was referenced in the other issue, it's also presently closed (by bot, due to another related commit) without the docs fixed.

@MoLow
Copy link
Member

MoLow commented Mar 30, 2023

@ForbiddenEra see the pr that closed that issue - it also fixed the documentation

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

No branches or pull requests

2 participants