Skip to content

console.log in node:test ? #44372

Description

@masx200

What is the problem this feature will solve?

import test from "node:test";
test("hello world", () => {
    console.log("hello world");

});
{"type":"module"}
 node --test
TAP version 13
# Subtest: D:\\Documents\\test\\test.js
ok 1 - D:\\Documents\\test\\test.js
  ---
  duration_ms: 0.1560414
  ...
1..1
# tests 1
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 0.2308918

What is the feature you are proposing to solve the problem?

The log of the console in the test should print

What alternatives have you considered?

No response

Activity

  1. masx200 commented on Aug 24, 2022

    @masx200
    ContributorAuthor
  2. added
    test_runnerIssues and PRs related to the test runner subsystem.
    on Aug 24, 2022
  3. MoLow commented on Aug 24, 2022

    @MoLow
    Member

    Refs: #43034
    Refs: #43344

  4. moved this to Pending Triage in Node.js feature requestson Oct 22, 2022
  5. MoLow commented on Nov 22, 2022

    @MoLow
    Member

    completed via #43525

  6. lucgagan commented on Jun 2, 2023

    @lucgagan

    What's the resolution?

    I am still not able to get output of console.log :-(

    https://stackoverflow.com/questions/76391424/how-to-get-output-of-console-log-when-using-nodetest

  7. cjihrig commented on Jun 3, 2023

    @cjihrig
    Contributor

    @lucgagan try with the latest version of Node (v20.2.0). Your issue was fixed recently.

  8. lcswillems commented on Jul 8, 2023

    @lcswillems

    Has it been added to 18.x.x?

  9. FossPrime commented on Sep 27, 2023

    @FossPrime

    Has it been added to 18.x.x?

    Workaround:

    import {createWriteStream} from 'fs'
    
    console.log = async (message: any) => {
      const tty = createWriteStream('/dev/tty')
      const msg = typeof message === 'string' ? message : JSON.stringify(message, null, 2)
      return tty.write(msg + '\n')
    }
    
  10. moved this from Awaiting Triage to Done in Node.js feature requestson Jun 29, 2024
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

    feature requestIssues requesting new Node.js features.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