This makes sure that errors that shut down the application are
inspected with `util.inspect()`. That makes sure that all extra
properties on the error will be visible and also that the stack trace
is highlighted (Node.js internal frames will be grey and node modules
are underlined).
PR-URL: https://github.com/nodejs/node/pull/27243
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This makes sure that the error message is more appropriate than
before by checking closer what operator is used and which is not.
It also increases the total number of lines printed to the user.
PR-URL: https://github.com/nodejs/node/pull/27525
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Using `util.inspect` on errors is going to highlight userland and
node_module stack frames from now on. This is done by marking Node.js
core frames grey and frames that contain `node_modules` in their path
yellow.
That way it's easy to grasp what frames belong to what code.
PR-URL: https://github.com/nodejs/node/pull/27052
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
When TERM=dumb and .isTTY=true don't use ANSI escape codes
and ignore all keys, except 'escape', 'return' and 'ctrl-c'.
PR-URL: https://github.com/nodejs/node/pull/26261
Fixes: https://github.com/nodejs/node/issues/26187
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This adds support to enforce a specific color depth by checking the
`FORCE_COLOR` environment variable similar to `chalk`.
On top of that we also add support for the `NO_COLOR` environment
variable as suggested by https://no-color.org/.
PR-URL: https://github.com/nodejs/node/pull/26485
Refs: https://github.com/nodejs/node/pull/26248
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This adds a small wrapper around the `getColorDepth` function to check
if the stream supports at least a specific amount of colors. This is
convenient as the other API is not as straight forward and most use
cases likely only want to know if a specific amount of colors is
supported or not.
PR-URL: https://github.com/nodejs/node/pull/26247
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1) Using `process.env.TERM = 'dumb'` should never return any colors.
2) `process.env.TERM = 'terminator'` supports 24 bit colors.
3) Add support for `process.env.TERM = 'rxvt-unicode-24bit'`
4) `Hyper` does not support true colors anymore. It should fall back
to the xterm settings in regular cases.
5) `process.env.COLORTERM = 'truecolor'` should return 24 bit colors.
PR-URL: https://github.com/nodejs/node/pull/26264
Refs: https://github.com/nodejs/node/pull/26261
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This test adds coverage for a ternary in assertion_error.js that checks
if stderr is a TTY.
PR-URL: https://github.com/nodejs/node/pull/26024
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
This patch:
- Refactors the Console constructor: moves the property binding code
into and the writable streams binding code into two methods defined
on the Console.prototype with symbols.
- Refactors the global console creation: we only need to share the
property binding code from the Console constructor. To bind the
streams we can lazy load `process.stdio` and `process.stderr`
so that we don't create these streams when they are not used.
This significantly reduces the number of modules loaded during
bootstrap. Also, by calling the refactored-out method directly
we can skip the unnecessary typechecks when creating the global
console and there is no need to create a temporary Console
anymore.
- Refactors the error handler creation and the `write` method:
use a `kUseStdout` symbol to tell the internals which stream
should be loaded from the console instance. Also put the
`write` method on the Console prototype so it just loads
other properties directly off the console instance which simplifies
the call sites.
Also leaves a few TODOs for further refactoring of the console
bootstrap.
PR-URL: https://github.com/nodejs/node/pull/24534
Reviewed-By: Gus Caplan <me@gus.host>
PR-URL: https://github.com/nodejs/node/pull/24485
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: https://github.com/nodejs/node/pull/24181
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
* Hoist common code to base class
(`GetTestStatus`, and the `section` property to `TestConfiguration`)
* Replace ListSet with the built in set
* Remove ClassifiedTest
* Inline PrintReport
* How cases_to_run are filtered
PR-URL: https://github.com/nodejs/node/pull/23251
Reviewed-By: Rich Trott <rtrott@gmail.com>
Make sure that `process.stdin.write()`, and in particular
ending the stream, works.
PR-URL: https://github.com/nodejs/node/pull/23053
Reviewed-By: James M Snell <jasnell@gmail.com>
Allow reading from stdio streams that are conventionally
associated with process output, since this is only convention.
This involves disabling the oddness around closing stdio
streams. Its purpose is to prevent the file descriptors
0 through 2 from being closed, since doing so can lead
to information leaks when new file descriptors are being
opened; instead, not doing anything seems like a more
reasonable choice.
Fixes: https://github.com/nodejs/node/issues/21203
PR-URL: https://github.com/nodejs/node/pull/23053
Reviewed-By: James M Snell <jasnell@gmail.com>
Since faking TTY input is not otherwise fake-able, we need
support in the test runner for it.
PR-URL: https://github.com/nodejs/node/pull/23053
Reviewed-By: James M Snell <jasnell@gmail.com>
It’s not necessary to assert that the internal `hasRef()`
method exists, since it is always called directly afterwards
in these tests. Furthermore, the test is overly specific,
in that it expects them on a specific position in the prototype
chain.
PR-URL: https://github.com/nodejs/node/pull/23040
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit makes the async_wrap builtin an internal builtin, and
changes usage of the builtin from using process.binding('async_wrap')
to use internalBinding instead.
Refs: https://github.com/nodejs/node/issues/22160
PR-URL: https://github.com/nodejs/node/pull/22469
Refs: https://github.com/nodejs/node/issues/22160
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This change avoid an 'read ENOTCONN' error introduced by libuv 1.20.0
when trying to read from a TTY WriteStream. Instead, we are throwing
a more actionable ERR_TTY_WRITABLE_NOT_READABLE.
Fixes: https://github.com/nodejs/node/issues/21203
PR-URL: https://github.com/nodejs/node/pull/21654
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Avoid trying to emit 'readable' due to the fact that
state.length is always >= state.highWaterMark if highWaterMark is 0.
Therefore upon .read(0) call (through .on('readable')) stream assumed
that it has enough data to emit 'readable' even though
state.length === 0 instead of issuing _read(). Which led to the TTY
not recognizing that someone is waiting for the input.
Fixes: https://github.com/nodejs/node/issues/20503
Refs: https://github.com/nodejs/node/pull/18372
PR-URL: https://github.com/nodejs/node/pull/21690
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1) Switched + / - and red / green in diffs. It seems like that style
is more natural to most people.
2) Short primitives do not use the diff anymore. Especially short
numbers can be read well like 1 !== 2. Cases that can not be
displayed like that (e.g., -0 and +0) use the regular diff output.
3) Improved error descriptions. It was not always clear what the
messages stood for. That should now be resolved.
4) Added a position indicator for single lines in case a tty is used
and the line is shorter than the visual columns.
5) Color detection is now done by checking stderr instead of stdout.
PR-URL: https://github.com/nodejs/node/pull/21628
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Removes a couple of unused/empty functions inside of `tools/test.py`
PR-URL: https://github.com/nodejs/node/pull/22010
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
This was originally introduced in 3446ff417b, in order to fix
a hard crash. However, since the libuv 1.18.0 update, that hard
crash is gone, and since f2b9805f85 we do not throw an
error in JS land anymore either, rendering the flag unnecessary.
Also, the original test that checked this condition was added
to `test/parallel/`. Since that typically runs without a TTY stdin,
a duplicate test is being added to the pseudo-tty test suite
in this commit.
Refs: 3446ff417b
Refs: f2b9805f85
Refs: 0e2814179c
PR-URL: https://github.com/nodejs/node/pull/20388
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
If lines gets skipped, they are marked with three dots. This makes
sure they are better visualized to distinguish them from everything
else.
PR-URL: https://github.com/nodejs/node/pull/20315
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
This improves the error messages for:
- assert.notDeepStrictEqual
- assert.deepStrictEqual
- assert.notStrictEqual
- assert.strictEqual
Those will now always use the same error message as used in the
strict mode.
PR-URL: https://github.com/nodejs/node/pull/19467
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This makes Node pretty-print objects with color by default
when `console.log()`-ing them.
PR-URL: https://github.com/nodejs/node/pull/19372
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
The color output was broken at some point and that was not detected
because it was not tested for properly so far. This makes sure the
colors work again and it adds a regression test as well.
PR-URL: https://github.com/nodejs/node/pull/19464
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
TTY tests should almost never be placed in `/parallel/`. Skipping TTY
tests there due to missing tty fds just means they will never be run,
ever, on any system.
This moves the tty-get-color-depth test to `/pseudo-tty/` where the test
runner will actually make a pty fd.
Refs: https://github.com/nodejs/node/pull/17615
PR-URL: https://github.com/nodejs/node/pull/18800
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
It's not wholly clear what commit introduced the regression but between
v8.4.0 and v8.5.0 the 'resize' event stopped getting emitted when the
tty was resized.
The SIGWINCH event listener apparently was being installed before the
support code for `process.on('SIGWINCH', ...)` was. Fix that by moving
said support code to real early in the bootstrap process.
This commit also seems to fix a Windows-only "write EINVAL" error for
reasons even less well-understood...
Fixes: https://github.com/nodejs/node/issues/16141
Fixes: https://github.com/nodejs/node/issues/16194
PR-URL: https://github.com/nodejs/node/pull/16225
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
PR-URL: https://github.com/nodejs/node/pull/16959
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Previously, various inputs other than non-negative integers would
produce incorrect results.
Added type-checking on input, returning false for anything other than
non-negative integers.
Also clarified in docs.
PR-URL: https://github.com/nodejs/node/pull/15567
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
ESLint 4.x has stricter linting than previous versions. We are currently
using the legacy indentation rules in the test directory. This commit
changes the indentation of files to comply with the stricter 4.x linting
and enable stricter linting in the test directory.
PR-URL: https://github.com/nodejs/node/pull/14431
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>