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

console.log in node:test ? #44372

Closed
masx200 opened this issue Aug 24, 2022 · 7 comments
Closed

console.log in node:test ? #44372

masx200 opened this issue Aug 24, 2022 · 7 comments
Labels
feature request Issues that request new features to be added to Node.js. test_runner

Comments

@masx200
Copy link
Contributor

masx200 commented Aug 24, 2022

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

@masx200 masx200 added the feature request Issues that request new features to be added to Node.js. label Aug 24, 2022
@masx200
Copy link
Contributor Author

masx200 commented Aug 24, 2022

#43574

@MoLow
Copy link
Member

MoLow commented Aug 24, 2022

Refs: #43034
Refs: #43344

@MoLow
Copy link
Member

MoLow commented Nov 22, 2022

completed via #43525

@MoLow MoLow closed this as completed Nov 22, 2022
@lucgagan
Copy link

lucgagan commented Jun 2, 2023

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

@cjihrig
Copy link
Contributor

cjihrig commented Jun 3, 2023

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

@lcswillems
Copy link

Has it been added to 18.x.x?

@FossPrime
Copy link

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')
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. test_runner
Projects
Status: Pending Triage
Development

No branches or pull requests

6 participants