4242
4343Takes ` whitelist ` and concats that with predefined ` knownGlobals ` .
4444
45- ### arrayStream
46- A stream to push an array into a REPL
47-
4845### busyLoop(time)
4946* ` time ` [ < ; number>]
5047
@@ -180,24 +177,6 @@ Indicates whether `IPv6` is supported on this platform.
180177
181178Indicates if there are multiple localhosts available.
182179
183- ### hijackStderr(listener)
184- * ` listener ` [ < ; Function>] : a listener with a single parameter
185- called ` data ` .
186-
187- Eavesdrop to ` process.stderr.write ` calls. Once ` process.stderr.write ` is
188- called, ` listener ` will also be called and the ` data ` of ` write ` function will
189- be passed to ` listener ` . What's more, ` process.stderr.writeTimes ` is a count of
190- the number of calls.
191-
192- ### hijackStdout(listener)
193- * ` listener ` [ < ; Function>] : a listener with a single parameter
194- called ` data ` .
195-
196- Eavesdrop to ` process.stdout.write ` calls. Once ` process.stdout.write ` is
197- called, ` listener ` will also be called and the ` data ` of ` write ` function will
198- be passed to ` listener ` . What's more, ` process.stdout.writeTimes ` is a count of
199- the number of calls.
200-
201180### inFreeBSDJail
202181* [ < ; boolean>]
203182
@@ -249,11 +228,6 @@ Platform check for Windows.
249228
250229Platform check for Windows 32-bit on Windows 64-bit.
251230
252- ### isCPPSymbolsNotMapped
253- * [ < ; boolean>]
254-
255- Platform check for C++ symbols are mapped or not.
256-
257231### leakedGlobals()
258232* return [ < ; Array>]
259233
@@ -321,21 +295,6 @@ otherwise.
321295### noWarnCode
322296See ` common.expectWarning() ` for usage.
323297
324- ### onGC(target, listener)
325- * ` target ` [ < ; Object>]
326- * ` listener ` [ < ; Object>]
327- * ` ongc ` [ < ; Function>]
328-
329- Installs a GC listener for the collection of ` target ` .
330-
331- This uses ` async_hooks ` for GC tracking. This means that it enables
332- ` async_hooks ` tracking, which may affect the test functionality. It also
333- means that between a ` global.gc() ` call and the listener being invoked
334- a full ` setImmediate() ` invocation passes.
335-
336- ` listener ` is an object to make it easier to use a closure; the target object
337- should not be in scope when ` listener.ongc() ` is created.
338-
339298### opensslCli
340299* [ < ; boolean>]
341300
@@ -362,15 +321,16 @@ A port number for tests to use if one is needed.
362321
363322Logs '1..0 # Skipped: ' + ` msg `
364323
365- ### restoreStderr()
366-
367- Restore the original ` process.stderr.write ` . Used to restore ` stderr ` to its
368- original state after calling [ ` common.hijackStdErr() ` ] [ ] .
324+ ### pwdCommand
325+ * [ < ; array>] First two argument for the ` spawn ` /` exec ` functions.
369326
370- ### restoreStdout()
327+ Platform normalized ` pwd ` command options. Usage example:
328+ ``` js
329+ const common = require (' ../common' );
330+ const { spawn } = require (' child_process' );
371331
372- Restore the original ` process.stdout.write ` . Used to restore ` stdout ` to its
373- original state after calling [ ` common.hijackStdOut() ` ] [ ] .
332+ spawn ( ... common . pwdCommand , { stdio : [ ' pipe ' ] });
333+ ```
374334
375335### rootDir
376336* [ < ; string>]
@@ -405,17 +365,19 @@ was disabled at compile time.
405365Skip the rest of the tests in the current file when the Node.js executable
406366was compiled with a pointer size smaller than 64 bits.
407367
408- ### spawnPwd(options)
409- * ` options ` [ < ; Object>]
410- * return [ < ; Object>]
368+ ## ArrayStream Module
411369
412- Platform normalizes the ` pwd ` command.
370+ The ` ArrayStream ` module provides a simple ` Stream ` that pushes elements from
371+ a given array.
413372
414- ### spawnSyncPwd(options)
415- * ` options ` [ < ; Object>]
416- * return [ < ; Object>]
373+ <!-- eslint-disable no-undef, node-core/required-modules -->
374+ ``` js
375+ const ArrayStream = require (' ../common/arraystream' );
376+ const stream = new ArrayStream ();
377+ stream .run ([' a' , ' b' , ' c' ]);
378+ ```
417379
418- Synchronous version of ` spawnPwd ` .
380+ It can be used within tests as a simple mock stream .
419381
420382## Countdown Module
421383
@@ -589,6 +551,52 @@ validateSnapshotNodes('TLSWRAP', [
589551]);
590552```
591553
554+ ## hijackstdio Module
555+
556+ The ` hijackstdio ` module provides utility functions for temporarily redirecting
557+ ` stdout ` and ` stderr ` output.
558+
559+ <!-- eslint-disable no-undef, node-core/required-modules -->
560+ ``` js
561+ const { hijackStdout , restoreStdout } = require (' ../common/hijackstdio' );
562+
563+ hijackStdout ((data ) => {
564+ /* Do something with data */
565+ restoreStdout ();
566+ });
567+
568+ console .log (' this is sent to the hijacked listener' );
569+ ```
570+
571+ ### hijackStderr(listener)
572+ * ` listener ` [ < ; Function>] : a listener with a single parameter
573+ called ` data ` .
574+
575+ Eavesdrop to ` process.stderr.write() ` calls. Once ` process.stderr.write() ` is
576+ called, ` listener ` will also be called and the ` data ` of ` write ` function will
577+ be passed to ` listener ` . What's more, ` process.stderr.writeTimes ` is a count of
578+ the number of calls.
579+
580+ ### hijackStdout(listener)
581+ * ` listener ` [ < ; Function>] : a listener with a single parameter
582+ called ` data ` .
583+
584+ Eavesdrop to ` process.stdout.write() ` calls. Once ` process.stdout.write() ` is
585+ called, ` listener ` will also be called and the ` data ` of ` write ` function will
586+ be passed to ` listener ` . What's more, ` process.stdout.writeTimes ` is a count of
587+ the number of calls.
588+
589+ ### restoreStderr()
590+
591+ Restore the original ` process.stderr.write() ` . Used to restore ` stderr ` to its
592+ original state after calling [ ` hijackstdio.hijackStdErr() ` ] [ ] .
593+
594+ ### restoreStdout()
595+
596+ Restore the original ` process.stdout.write() ` . Used to restore ` stdout ` to its
597+ original state after calling [ ` hijackstdio.hijackStdOut() ` ] [ ] .
598+
599+
592600## HTTP/2 Module
593601
594602The http2.js module provides a handful of utilities for creating mock HTTP/2
@@ -734,6 +742,34 @@ via `NODE_TEST_*` environment variables. For example, to configure
734742` internet.addresses.INET_HOST ` , set the environment
735743variable ` NODE_TEST_INET_HOST ` to a specified host.
736744
745+ ## ongc Module
746+
747+ The ` ongc ` module allows a garbage collection listener to be installed. The
748+ module exports a single ` onGC() ` function.
749+
750+ ``` js
751+ require (' ../common' );
752+ const onGC = require (' ../common/ongc' );
753+
754+ onGC ({}, { ongc () { console .log (' collected' ); } });
755+ ```
756+
757+ ### onGC(target, listener)
758+ * ` target ` [ < ; Object>]
759+ * ` listener ` [ < ; Object>]
760+ * ` ongc ` [ < ; Function>]
761+
762+ Installs a GC listener for the collection of ` target ` .
763+
764+ This uses ` async_hooks ` for GC tracking. This means that it enables
765+ ` async_hooks ` tracking, which may affect the test functionality. It also
766+ means that between a ` global.gc() ` call and the listener being invoked
767+ a full ` setImmediate() ` invocation passes.
768+
769+ ` listener ` is an object to make it easier to use a closure; the target object
770+ should not be in scope when ` listener.ongc() ` is created.
771+
772+
737773## tmpdir Module
738774
739775The ` tmpdir ` module supports the use of a temporary directory for testing.
@@ -766,8 +802,8 @@ implementation with tests from
766802[ < ; boolean>] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type
767803[ < ; number>] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type
768804[ < ; string>] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type
769- [ `common .hijackStdErr()` ] : #hijackstderrlistener
770- [ `common .hijackStdOut()` ] : #hijackstdoutlistener
805+ [ `hijackstdio .hijackStdErr()` ] : #hijackstderrlistener
806+ [ `hijackstdio .hijackStdOut()` ] : #hijackstdoutlistener
771807[ internationalization ] : https://github.com/nodejs/node/wiki/Intl
772808
773809function forEach (xs, f) {
0 commit comments