1# Node.js Core Test Common Modules 2 3This directory contains modules used to test the Node.js implementation. 4 5## Table of Contents 6 7* [ArrayStream module](#arraystream-module) 8* [Benchmark module](#benchmark-module) 9* [Common module API](#common-module-api) 10* [Countdown module](#countdown-module) 11* [CPU Profiler module](#cpu-profiler-module) 12* [DNS module](#dns-module) 13* [Duplex pair helper](#duplex-pair-helper) 14* [Environment variables](#environment-variables) 15* [Fixtures module](#fixtures-module) 16* [Heap dump checker module](#heap-dump-checker-module) 17* [hijackstdio module](#hijackstdio-module) 18* [HTTP2 module](#http2-module) 19* [Internet module](#internet-module) 20* [ongc module](#ongc-module) 21* [Report module](#report-module) 22* [tick module](#tick-module) 23* [tmpdir module](#tmpdir-module) 24* [WPT module](#wpt-module) 25 26## Benchmark Module 27 28The `benchmark` module is used by tests to run benchmarks. 29 30### `runBenchmark(name, args, env)` 31 32* `name` [<string>][] Name of benchmark suite to be run. 33* `args` [<Array>][] Array of environment variable key/value pairs (ex: 34 `n=1`) to be applied via `--set`. 35* `env` [<Object>][] Environment variables to be applied during the run. 36 37## Common Module API 38 39The `common` module is used by tests for consistency across repeated 40tasks. 41 42### `allowGlobals(...whitelist)` 43 44* `whitelist` [<Array>][] Array of Globals 45* return [<Array>][] 46 47Takes `whitelist` and concats that with predefined `knownGlobals`. 48 49### `canCreateSymLink()` 50 51* return [<boolean>][] 52 53Checks whether the current running process can create symlinks. On Windows, this 54returns `false` if the process running doesn't have privileges to create 55symlinks 56([SeCreateSymbolicLinkPrivilege](https://msdn.microsoft.com/en-us/library/windows/desktop/bb530716(v=vs.85).aspx)). 57On non-Windows platforms, this always returns `true`. 58 59### `createZeroFilledFile(filename)` 60 61Creates a 10 MB file of all null characters. 62 63### `disableCrashOnUnhandledRejection()` 64 65Removes the `process.on('unhandledRejection')` handler that crashes the process 66after a tick. The handler is useful for tests that use Promises and need to make 67sure no unexpected rejections occur, because currently they result in silent 68failures. However, it is useful in some rare cases to disable it, for example if 69the `unhandledRejection` hook is directly used by the test. 70 71### `enoughTestCpu` 72 73* [<boolean>][] 74 75Indicates if there is more than 1 CPU or that the single CPU has a speed of at 76least 1 GHz. 77 78### `enoughTestMem` 79 80* [<boolean>][] 81 82Indicates if there is more than 1gb of total memory. 83 84### expectsError(validator\[, exact\]) 85* `validator` [<Object>][] | [<RegExp>][] | [<Function>][] | 86 [<Error>][] The validator behaves identical to 87 `assert.throws(fn, validator)`. 88* `exact` [<number>][] default = 1 89* return [<Function>][] A callback function that expects an error. 90 91A function suitable as callback to validate callback based errors. The error is 92validated using `assert.throws(() => { throw error; }, validator)`. If the 93returned function has not been called exactly `exact` number of times when the 94test is complete, then the test will fail. 95 96### `expectWarning(name[, expected[, code]])` 97 98* `name` [<string>][] | [<Object>][] 99* `expected` [<string>][] | [<Array>][] | [<Object>][] 100* `code` [<string>][] 101 102Tests whether `name`, `expected`, and `code` are part of a raised warning. 103 104The code is required in case the name is set to `'DeprecationWarning'`. 105 106Examples: 107 108```js 109const { expectWarning } = require('../common'); 110 111expectWarning('Warning', 'Foobar is really bad'); 112 113expectWarning('DeprecationWarning', 'Foobar is deprecated', 'DEP0XXX'); 114 115expectWarning('DeprecationWarning', [ 116 'Foobar is deprecated', 'DEP0XXX' 117]); 118 119expectWarning('DeprecationWarning', [ 120 ['Foobar is deprecated', 'DEP0XXX'], 121 ['Baz is also deprecated', 'DEP0XX2'] 122]); 123 124expectWarning('DeprecationWarning', { 125 DEP0XXX: 'Foobar is deprecated', 126 DEP0XX2: 'Baz is also deprecated' 127}); 128 129expectWarning({ 130 DeprecationWarning: { 131 DEP0XXX: 'Foobar is deprecated', 132 DEP0XX1: 'Baz is also deprecated' 133 }, 134 Warning: [ 135 ['Multiple array entries are fine', 'SpecialWarningCode'], 136 ['No code is also fine'] 137 ], 138 SingleEntry: ['This will also work', 'WarningCode'], 139 SingleString: 'Single string entries without code will also work' 140}); 141``` 142 143### `getArrayBufferViews(buf)` 144 145* `buf` [<Buffer>][] 146* return [<ArrayBufferView>][]\[\] 147 148Returns an instance of all possible `ArrayBufferView`s of the provided Buffer. 149 150### `getBufferSources(buf)` 151 152* `buf` [<Buffer>][] 153* return [<BufferSource>][]\[\] 154 155Returns an instance of all possible `BufferSource`s of the provided Buffer, 156consisting of all `ArrayBufferView` and an `ArrayBuffer`. 157 158### `getCallSite(func)` 159 160* `func` [<Function>][] 161* return [<string>][] 162 163Returns the file name and line number for the provided Function. 164 165### `getTTYfd()` 166 167Attempts to get a valid TTY file descriptor. Returns `-1` if it fails. 168 169The TTY file descriptor is assumed to be capable of being writable. 170 171### `hasCrypto` 172 173* [<boolean>][] 174 175Indicates whether OpenSSL is available. 176 177### `hasFipsCrypto` 178 179* [<boolean>][] 180 181Indicates that Node.js has been linked with a FIPS compatible OpenSSL library, 182and that FIPS as been enabled using `--enable-fips`. 183 184To only detect if the OpenSSL library is FIPS compatible, regardless if it has 185been enabled or not, then `process.config.variables.openssl_is_fips` can be 186used to determine that situation. 187 188### `hasIntl` 189 190* [<boolean>][] 191 192Indicates if [internationalization][] is supported. 193 194### `hasIPv6` 195 196* [<boolean>][] 197 198Indicates whether `IPv6` is supported on this platform. 199 200### `hasMultiLocalhost` 201 202* [<boolean>][] 203 204Indicates if there are multiple localhosts available. 205 206### `inFreeBSDJail` 207 208* [<boolean>][] 209 210Checks whether free BSD Jail is true or false. 211 212### `isAIX` 213 214* [<boolean>][] 215 216Platform check for Advanced Interactive eXecutive (AIX). 217 218### `isAlive(pid)` 219 220* `pid` [<number>][] 221* return [<boolean>][] 222 223Attempts to 'kill' `pid` 224 225### `isDumbTerminal` 226 227* [<boolean>][] 228 229### `isFreeBSD` 230 231* [<boolean>][] 232 233Platform check for Free BSD. 234 235### `isIBMi` 236 237* [<boolean>][] 238 239Platform check for IBMi. 240 241### `isLinux` 242 243* [<boolean>][] 244 245Platform check for Linux. 246 247### `isLinuxPPCBE` 248 249* [<boolean>][] 250 251Platform check for Linux on PowerPC. 252 253### `isOSX` 254 255* [<boolean>][] 256 257Platform check for macOS. 258 259### `isSunOS` 260 261* [<boolean>][] 262 263Platform check for SunOS. 264 265### `isWindows` 266 267* [<boolean>][] 268 269Platform check for Windows. 270 271### `localhostIPv4` 272 273* [<string>][] 274 275IP of `localhost`. 276 277### `localIPv6Hosts` 278 279* [<Array>][] 280 281Array of IPV6 representations for `localhost`. 282 283### `mustCall([fn][, exact])` 284 285* `fn` [<Function>][] default = () => {} 286* `exact` [<number>][] default = 1 287* return [<Function>][] 288 289Returns a function that calls `fn`. If the returned function has not been called 290exactly `exact` number of times when the test is complete, then the test will 291fail. 292 293If `fn` is not provided, an empty function will be used. 294 295### `mustCallAtLeast([fn][, minimum])` 296 297* `fn` [<Function>][] default = () => {} 298* `minimum` [<number>][] default = 1 299* return [<Function>][] 300 301Returns a function that calls `fn`. If the returned function has not been called 302at least `minimum` number of times when the test is complete, then the test will 303fail. 304 305If `fn` is not provided, an empty function will be used. 306 307### `mustNotCall([msg])` 308 309* `msg` [<string>][] default = 'function should not have been called' 310* return [<Function>][] 311 312Returns a function that triggers an `AssertionError` if it is invoked. `msg` is 313used as the error message for the `AssertionError`. 314 315### `nodeProcessAborted(exitCode, signal)` 316 317* `exitCode` [<number>][] 318* `signal` [<string>][] 319* return [<boolean>][] 320 321Returns `true` if the exit code `exitCode` and/or signal name `signal` represent 322the exit code and/or signal name of a node process that aborted, `false` 323otherwise. 324 325### `opensslCli` 326 327* [<boolean>][] 328 329Indicates whether 'opensslCli' is supported. 330 331### `platformTimeout(ms)` 332 333* `ms` [<number>][] | [<bigint>][] 334* return [<number>][] | [<bigint>][] 335 336Returns a timeout value based on detected conditions. For example, a debug build 337may need extra time so the returned value will be larger than on a release 338build. 339 340### `PIPE` 341 342* [<string>][] 343 344Path to the test socket. 345 346### `PORT` 347 348* [<number>][] 349 350A port number for tests to use if one is needed. 351 352### `printSkipMessage(msg)` 353 354* `msg` [<string>][] 355 356Logs '1..0 # Skipped: ' + `msg` 357 358### `pwdCommand` 359 360* [<array>][] First two argument for the `spawn`/`exec` functions. 361 362Platform normalized `pwd` command options. Usage example: 363```js 364const common = require('../common'); 365const { spawn } = require('child_process'); 366 367spawn(...common.pwdCommand, { stdio: ['pipe'] }); 368``` 369 370### `runWithInvalidFD(func)` 371 372* `func` [<Function>][] 373 374Runs `func` with an invalid file descriptor that is an unsigned integer and 375can be used to trigger `EBADF` as the first argument. If no such file 376descriptor could be generated, a skip message will be printed and the `func` 377will not be run. 378 379### `skip(msg)` 380 381* `msg` [<string>][] 382 383Logs '1..0 # Skipped: ' + `msg` and exits with exit code `0`. 384 385### `skipIfDumbTerminal()` 386 387Skip the rest of the tests if the current terminal is a dumb terminal 388 389### `skipIfEslintMissing()` 390 391Skip the rest of the tests in the current file when `ESLint` is not available 392at `tools/node_modules/eslint` 393 394### `skipIfInspectorDisabled()` 395 396Skip the rest of the tests in the current file when the Inspector 397was disabled at compile time. 398 399### `skipIf32Bits()` 400 401Skip the rest of the tests in the current file when the Node.js executable 402was compiled with a pointer size smaller than 64 bits. 403 404### `skipIfWorker()` 405 406Skip the rest of the tests in the current file when not running on a main 407thread. 408 409## ArrayStream Module 410 411The `ArrayStream` module provides a simple `Stream` that pushes elements from 412a given array. 413 414<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 415```js 416const ArrayStream = require('../common/arraystream'); 417const stream = new ArrayStream(); 418stream.run(['a', 'b', 'c']); 419``` 420 421It can be used within tests as a simple mock stream. 422 423## Countdown Module 424 425The `Countdown` module provides a simple countdown mechanism for tests that 426require a particular action to be taken after a given number of completed 427tasks (for instance, shutting down an HTTP server after a specific number of 428requests). The Countdown will fail the test if the remainder did not reach 0. 429 430<!-- eslint-disable strict, node-core/require-common-first, node-core/required-modules --> 431```js 432const Countdown = require('../common/countdown'); 433 434function doSomething() { 435 console.log('.'); 436} 437 438const countdown = new Countdown(2, doSomething); 439countdown.dec(); 440countdown.dec(); 441``` 442 443### `new Countdown(limit, callback)` 444 445* `limit` {number} 446* `callback` {function} 447 448Creates a new `Countdown` instance. 449 450### `Countdown.prototype.dec()` 451 452Decrements the `Countdown` counter. 453 454### `Countdown.prototype.remaining` 455 456Specifies the remaining number of times `Countdown.prototype.dec()` must be 457called before the callback is invoked. 458 459## CPU Profiler module 460 461The `cpu-prof` module provides utilities related to CPU profiling tests. 462 463### `env` 464 465* Default: { ...process.env, NODE_DEBUG_NATIVE: 'INSPECTOR_PROFILER' } 466 467Environment variables used in profiled processes. 468 469### `getCpuProfiles(dir)` 470 471* `dir` {string} The directory containing the CPU profile files. 472* return [<string>][] 473 474Returns an array of all `.cpuprofile` files found in `dir`. 475 476### `getFrames(file, suffix)` 477 478* `file` {string} Path to a `.cpuprofile` file. 479* `suffix` {string} Suffix of the URL of call frames to retrieve. 480* returns { frames: [<Object>][], nodes: [<Object>][] } 481 482Returns an object containing an array of the relevant call frames and an array 483of all the profile nodes. 484 485### `kCpuProfInterval` 486 487Sampling interval in microseconds. 488 489### `verifyFrames(output, file, suffix)` 490 491* `output` {string} 492* `file` {string} 493* `suffix` {string} 494 495Throws an `AssertionError` if there are no call frames with the expected 496`suffix` in the profiling data contained in `file`. 497 498## `DNS` Module 499 500The `DNS` module provides utilities related to the `dns` built-in module. 501 502### `errorLookupMock(code, syscall)` 503 504* `code` [<string>][] Defaults to `dns.mockedErrorCode`. 505* `syscall` [<string>][] Defaults to `dns.mockedSysCall`. 506* return [<Function>][] 507 508A mock for the `lookup` option of `net.connect()` that would result in an error 509with the `code` and the `syscall` specified. Returns a function that has the 510same signature as `dns.lookup()`. 511 512### `mockedErrorCode` 513 514The default `code` of errors generated by `errorLookupMock`. 515 516### `mockedSysCall` 517 518The default `syscall` of errors generated by `errorLookupMock`. 519 520### `readDomainFromPacket(buffer, offset)` 521 522* `buffer` [<Buffer>][] 523* `offset` [<number>][] 524* return [<Object>][] 525 526Reads the domain string from a packet and returns an object containing the 527number of bytes read and the domain. 528 529### `parseDNSPacket(buffer)` 530 531* `buffer` [<Buffer>][] 532* return [<Object>][] 533 534Parses a DNS packet. Returns an object with the values of the various flags of 535the packet depending on the type of packet. 536 537### `writeIPv6(ip)` 538 539* `ip` [<string>][] 540* return [<Buffer>][] 541 542Reads an IPv6 String and returns a Buffer containing the parts. 543 544### `writeDomainName(domain)` 545 546* `domain` [<string>][] 547* return [<Buffer>][] 548 549Reads a Domain String and returns a Buffer containing the domain. 550 551### `writeDNSPacket(parsed)` 552 553* `parsed` [<Object>][] 554* return [<Buffer>][] 555 556Takes in a parsed Object and writes its fields to a DNS packet as a Buffer 557object. 558 559## Duplex pair helper 560 561The `common/duplexpair` module exports a single function `makeDuplexPair`, 562which returns an object `{ clientSide, serverSide }` where each side is a 563`Duplex` stream connected to the other side. 564 565There is no difference between client or server side beyond their names. 566 567## Environment variables 568 569The behavior of the Node.js test suite can be altered using the following 570environment variables. 571 572### `NODE_COMMON_PORT` 573 574If set, `NODE_COMMON_PORT`'s value overrides the `common.PORT` default value of 57512346. 576 577### `NODE_SKIP_FLAG_CHECK` 578 579If set, command line arguments passed to individual tests are not validated. 580 581### `NODE_SKIP_CRYPTO` 582 583If set, crypto tests are skipped. 584 585### `NODE_TEST_KNOWN_GLOBALS` 586 587A comma-separated list of variables names that are appended to the global 588variable whitelist. Alternatively, if `NODE_TEST_KNOWN_GLOBALS` is set to `'0'`, 589global leak detection is disabled. 590 591## Fixtures Module 592 593The `common/fixtures` module provides convenience methods for working with 594files in the `test/fixtures` directory. 595 596### `fixtures.fixturesDir` 597 598* [<string>][] 599 600The absolute path to the `test/fixtures/` directory. 601 602### `fixtures.path(...args)` 603 604* `...args` [<string>][] 605 606Returns the result of `path.join(fixtures.fixturesDir, ...args)`. 607 608### `fixtures.readSync(args[, enc])` 609 610* `args` [<string>][] | [<Array>][] 611 612Returns the result of 613`fs.readFileSync(path.join(fixtures.fixturesDir, ...args), 'enc')`. 614 615### `fixtures.readKey(arg[, enc])` 616 617* `arg` [<string>][] 618 619Returns the result of 620`fs.readFileSync(path.join(fixtures.fixturesDir, 'keys', arg), 'enc')`. 621 622## Heap dump checker module 623 624This provides utilities for checking the validity of heap dumps. 625This requires the usage of `--expose-internals`. 626 627### `heap.recordState()` 628 629Create a heap dump and an embedder graph copy for inspection. 630The returned object has a `validateSnapshotNodes` function similar to the 631one listed below. (`heap.validateSnapshotNodes(...)` is a shortcut for 632`heap.recordState().validateSnapshotNodes(...)`.) 633 634### `heap.validateSnapshotNodes(name, expected, options)` 635 636* `name` [<string>][] Look for this string as the name of heap dump nodes. 637* `expected` [<Array>][] A list of objects, possibly with an `children` 638 property that points to expected other adjacent nodes. 639* `options` [<Array>][] 640 * `loose` [<boolean>][] Do not expect an exact listing of occurrences 641 of nodes with name `name` in `expected`. 642 643Create a heap dump and an embedder graph copy and validate occurrences. 644 645<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 646```js 647validateSnapshotNodes('TLSWRAP', [ 648 { 649 children: [ 650 { name: 'enc_out' }, 651 { name: 'enc_in' }, 652 { name: 'TLSWrap' } 653 ] 654 } 655]); 656``` 657 658## hijackstdio Module 659 660The `hijackstdio` module provides utility functions for temporarily redirecting 661`stdout` and `stderr` output. 662 663<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 664```js 665const { hijackStdout, restoreStdout } = require('../common/hijackstdio'); 666 667hijackStdout((data) => { 668 /* Do something with data */ 669 restoreStdout(); 670}); 671 672console.log('this is sent to the hijacked listener'); 673``` 674 675### `hijackStderr(listener)` 676 677* `listener` [<Function>][]: a listener with a single parameter 678 called `data`. 679 680Eavesdrop to `process.stderr.write()` calls. Once `process.stderr.write()` is 681called, `listener` will also be called and the `data` of `write` function will 682be passed to `listener`. What's more, `process.stderr.writeTimes` is a count of 683the number of calls. 684 685### `hijackStdout(listener)` 686 687* `listener` [<Function>][]: a listener with a single parameter 688 called `data`. 689 690Eavesdrop to `process.stdout.write()` calls. Once `process.stdout.write()` is 691called, `listener` will also be called and the `data` of `write` function will 692be passed to `listener`. What's more, `process.stdout.writeTimes` is a count of 693the number of calls. 694 695### restoreStderr() 696 697Restore the original `process.stderr.write()`. Used to restore `stderr` to its 698original state after calling [`hijackstdio.hijackStdErr()`][]. 699 700### restoreStdout() 701 702Restore the original `process.stdout.write()`. Used to restore `stdout` to its 703original state after calling [`hijackstdio.hijackStdOut()`][]. 704 705## HTTP/2 Module 706 707The http2.js module provides a handful of utilities for creating mock HTTP/2 708frames for testing of HTTP/2 endpoints 709 710<!-- eslint-disable no-unused-vars, node-core/require-common-first, node-core/required-modules --> 711```js 712const http2 = require('../common/http2'); 713``` 714 715### Class: Frame 716 717The `http2.Frame` is a base class that creates a `Buffer` containing a 718serialized HTTP/2 frame header. 719 720<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 721```js 722// length is a 24-bit unsigned integer 723// type is an 8-bit unsigned integer identifying the frame type 724// flags is an 8-bit unsigned integer containing the flag bits 725// id is the 32-bit stream identifier, if any. 726const frame = new http2.Frame(length, type, flags, id); 727 728// Write the frame data to a socket 729socket.write(frame.data); 730``` 731 732The serialized `Buffer` may be retrieved using the `frame.data` property. 733 734### Class: DataFrame extends Frame 735 736The `http2.DataFrame` is a subclass of `http2.Frame` that serializes a `DATA` 737frame. 738 739<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 740```js 741// id is the 32-bit stream identifier 742// payload is a Buffer containing the DATA payload 743// padlen is an 8-bit integer giving the number of padding bytes to include 744// final is a boolean indicating whether the End-of-stream flag should be set, 745// defaults to false. 746const frame = new http2.DataFrame(id, payload, padlen, final); 747 748socket.write(frame.data); 749``` 750 751### Class: HeadersFrame 752 753The `http2.HeadersFrame` is a subclass of `http2.Frame` that serializes a 754`HEADERS` frame. 755 756<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 757```js 758// id is the 32-bit stream identifier 759// payload is a Buffer containing the HEADERS payload (see either 760// http2.kFakeRequestHeaders or http2.kFakeResponseHeaders). 761// padlen is an 8-bit integer giving the number of padding bytes to include 762// final is a boolean indicating whether the End-of-stream flag should be set, 763// defaults to false. 764const frame = new http2.HeadersFrame(id, payload, padlen, final); 765 766socket.write(frame.data); 767``` 768 769### Class: SettingsFrame 770 771The `http2.SettingsFrame` is a subclass of `http2.Frame` that serializes an 772empty `SETTINGS` frame. 773 774<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 775```js 776// ack is a boolean indicating whether or not to set the ACK flag. 777const frame = new http2.SettingsFrame(ack); 778 779socket.write(frame.data); 780``` 781 782### `http2.kFakeRequestHeaders` 783 784Set to a `Buffer` instance that contains a minimal set of serialized HTTP/2 785request headers to be used as the payload of a `http2.HeadersFrame`. 786 787<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 788```js 789const frame = new http2.HeadersFrame(1, http2.kFakeRequestHeaders, 0, true); 790 791socket.write(frame.data); 792``` 793 794### `http2.kFakeResponseHeaders` 795 796Set to a `Buffer` instance that contains a minimal set of serialized HTTP/2 797response headers to be used as the payload a `http2.HeadersFrame`. 798 799<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 800```js 801const frame = new http2.HeadersFrame(1, http2.kFakeResponseHeaders, 0, true); 802 803socket.write(frame.data); 804``` 805 806### `http2.kClientMagic` 807 808Set to a `Buffer` containing the preamble bytes an HTTP/2 client must send 809upon initial establishment of a connection. 810 811<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 812```js 813socket.write(http2.kClientMagic); 814``` 815 816## Internet Module 817 818The `common/internet` module provides utilities for working with 819internet-related tests. 820 821### `internet.addresses` 822 823* [<Object>][] 824 * `INET_HOST` [<string>][] A generic host that has registered common 825 DNS records, supports both IPv4 and IPv6, and provides basic HTTP/HTTPS 826 services 827 * `INET4_HOST` [<string>][] A host that provides IPv4 services 828 * `INET6_HOST` [<string>][] A host that provides IPv6 services 829 * `INET4_IP` [<string>][] An accessible IPv4 IP, defaults to the 830 Google Public DNS IPv4 address 831 * `INET6_IP` [<string>][] An accessible IPv6 IP, defaults to the 832 Google Public DNS IPv6 address 833 * `INVALID_HOST` [<string>][] An invalid host that cannot be resolved 834 * `MX_HOST` [<string>][] A host with MX records registered 835 * `SRV_HOST` [<string>][] A host with SRV records registered 836 * `PTR_HOST` [<string>][] A host with PTR records registered 837 * `NAPTR_HOST` [<string>][] A host with NAPTR records registered 838 * `SOA_HOST` [<string>][] A host with SOA records registered 839 * `CNAME_HOST` [<string>][] A host with CNAME records registered 840 * `NS_HOST` [<string>][] A host with NS records registered 841 * `TXT_HOST` [<string>][] A host with TXT records registered 842 * `DNS4_SERVER` [<string>][] An accessible IPv4 DNS server 843 * `DNS6_SERVER` [<string>][] An accessible IPv6 DNS server 844 845A set of addresses for internet-related tests. All properties are configurable 846via `NODE_TEST_*` environment variables. For example, to configure 847`internet.addresses.INET_HOST`, set the environment 848variable `NODE_TEST_INET_HOST` to a specified host. 849 850## ongc Module 851 852The `ongc` module allows a garbage collection listener to be installed. The 853module exports a single `onGC()` function. 854 855```js 856require('../common'); 857const onGC = require('../common/ongc'); 858 859onGC({}, { ongc() { console.log('collected'); } }); 860``` 861 862### `onGC(target, listener)` 863 864* `target` [<Object>][] 865* `listener` [<Object>][] 866 * `ongc` [<Function>][] 867 868Installs a GC listener for the collection of `target`. 869 870This uses `async_hooks` for GC tracking. This means that it enables 871`async_hooks` tracking, which may affect the test functionality. It also 872means that between a `global.gc()` call and the listener being invoked 873a full `setImmediate()` invocation passes. 874 875`listener` is an object to make it easier to use a closure; the target object 876should not be in scope when `listener.ongc()` is created. 877 878## Report Module 879 880The `report` module provides helper functions for testing diagnostic reporting 881functionality. 882 883### `findReports(pid, dir)` 884 885* `pid` [<number>][] Process ID to retrieve diagnostic report files for. 886* `dir` [<string>][] Directory to search for diagnostic report files. 887* return [<Array>][] 888 889Returns an array of diagnotic report file names found in `dir`. The files should 890have been generated by a process whose PID matches `pid`. 891 892### `validate(filepath)` 893 894* `filepath` [<string>][] Diagnostic report filepath to validate. 895 896Validates the schema of a diagnostic report file whose path is specified in 897`filepath`. If the report fails validation, an exception is thrown. 898 899### `validateContent(report)` 900 901* `report` [<Object>][] | [<string>][] JSON contents of a diagnostic 902 report file, the parsed Object thereof, or the result of 903 `process.report.getReport()`. 904 905Validates the schema of a diagnostic report whose content is specified in 906`report`. If the report fails validation, an exception is thrown. 907 908## tick Module 909 910The `tick` module provides a helper function that can be used to call a callback 911after a given number of event loop "ticks". 912 913### `tick(x, cb)` 914 915* `x` [<number>][] Number of event loop "ticks". 916* `cb` [<Function>][] A callback function. 917 918## tmpdir Module 919 920The `tmpdir` module supports the use of a temporary directory for testing. 921 922### `path` 923 924* [<string>][] 925 926The realpath of the testing temporary directory. 927 928### `refresh()` 929 930Deletes and recreates the testing temporary directory. 931 932## UDP pair helper 933 934The `common/udppair` module exports a function `makeUDPPair` and a class 935`FakeUDPWrap`. 936 937`FakeUDPWrap` emits `'send'` events when data is to be sent on it, and provides 938an `emitReceived()` API for actin as if data has been received on it. 939 940`makeUDPPair` returns an object `{ clientSide, serverSide }` where each side 941is an `FakeUDPWrap` connected to the other side. 942 943There is no difference between cient or server side beyond their names. 944 945## WPT Module 946 947### `harness` 948 949A legacy port of [Web Platform Tests][] harness. 950 951See the source code for definitions. Please avoid using it in new 952code - the current usage of this port in tests is being migrated to 953the original WPT harness, see [the WPT tests README][]. 954 955### Class: WPTRunner 956 957A driver class for running WPT with the WPT harness in a worker thread. 958 959See [the WPT tests README][] for details. 960 961[<Array>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array 962[<ArrayBufferView>]: https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView 963[<Buffer>]: https://nodejs.org/api/buffer.html#buffer_class_buffer 964[<BufferSource>]: https://developer.mozilla.org/en-US/docs/Web/API/BufferSource 965[<Error>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error 966[<Function>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function 967[<Object>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object 968[<RegExp>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp 969[<bigint>]: https://github.com/tc39/proposal-bigint 970[<boolean>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type 971[<number>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type 972[<string>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type 973[Web Platform Tests]: https://github.com/web-platform-tests/wpt 974[`hijackstdio.hijackStdErr()`]: #hijackstderrlistener 975[`hijackstdio.hijackStdOut()`]: #hijackstdoutlistener 976[internationalization]: https://github.com/nodejs/node/wiki/Intl 977[the WPT tests README]: ../wpt/README.md 978