Skip to content

test_runner API doc example invalid #47312

Closed

Description

@ForbiddenEra

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.

Activity

  1. added
    docIssues and PRs related to Node.js documentation.
    on Mar 30, 2023
  2. added
    test_runnerIssues and PRs related to the test runner subsystem.
    on Mar 30, 2023
  3. MoLow commented on Mar 30, 2023

    @MoLow
    Member

    Duplicate of #47231

  4. ForbiddenEra commented on Mar 30, 2023

    @ForbiddenEra
    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.

  5. MoLow commented on Mar 30, 2023

    @MoLow
    Member

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions