11cb0ef41Sopenharmony_ci# Node.js Core Test Common Modules 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciThis directory contains modules used to test the Node.js implementation. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci## Table of Contents 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci* [ArrayStream module](#arraystream-module) 81cb0ef41Sopenharmony_ci* [Benchmark module](#benchmark-module) 91cb0ef41Sopenharmony_ci* [Child process module](#child-process-module) 101cb0ef41Sopenharmony_ci* [Common module API](#common-module-api) 111cb0ef41Sopenharmony_ci* [Countdown module](#countdown-module) 121cb0ef41Sopenharmony_ci* [CPU Profiler module](#cpu-profiler-module) 131cb0ef41Sopenharmony_ci* [Debugger module](#debugger-module) 141cb0ef41Sopenharmony_ci* [DNS module](#dns-module) 151cb0ef41Sopenharmony_ci* [Duplex pair helper](#duplex-pair-helper) 161cb0ef41Sopenharmony_ci* [Environment variables](#environment-variables) 171cb0ef41Sopenharmony_ci* [Fixtures module](#fixtures-module) 181cb0ef41Sopenharmony_ci* [Heap dump checker module](#heap-dump-checker-module) 191cb0ef41Sopenharmony_ci* [hijackstdio module](#hijackstdio-module) 201cb0ef41Sopenharmony_ci* [HTTP2 module](#http2-module) 211cb0ef41Sopenharmony_ci* [Internet module](#internet-module) 221cb0ef41Sopenharmony_ci* [ongc module](#ongc-module) 231cb0ef41Sopenharmony_ci* [Report module](#report-module) 241cb0ef41Sopenharmony_ci* [tick module](#tick-module) 251cb0ef41Sopenharmony_ci* [tmpdir module](#tmpdir-module) 261cb0ef41Sopenharmony_ci* [UDP pair helper](#udp-pair-helper) 271cb0ef41Sopenharmony_ci* [WPT module](#wpt-module) 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci## Benchmark Module 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciThe `benchmark` module is used by tests to run benchmarks. 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci### `runBenchmark(name, env)` 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci* `name` [\<string>][<string>] Name of benchmark suite to be run. 361cb0ef41Sopenharmony_ci* `env` [\<Object>][<Object>] Environment variables to be applied during the 371cb0ef41Sopenharmony_ci run. 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci## Child Process Module 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ciThe `child_process` module is used by tests that launch child processes. 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci### `expectSyncExit(child, options)` 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ciChecks if a _synchronous_ child process runs in the way expected. If it does 461cb0ef41Sopenharmony_cinot, print the stdout and stderr output from the child process and additional 471cb0ef41Sopenharmony_ciinformation about it to the stderr of the current process before throwing 481cb0ef41Sopenharmony_ciand error. This helps gathering more information about test failures 491cb0ef41Sopenharmony_cicoming from child processes. 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci* `child` [\<ChildProcess>][<ChildProcess>]: a `ChildProcess` instance 521cb0ef41Sopenharmony_ci returned by `child_process.spawnSync()`. 531cb0ef41Sopenharmony_ci* `options` [\<Object>][<Object>] 541cb0ef41Sopenharmony_ci * `status` [\<number>][<number>] Expected `child.status` 551cb0ef41Sopenharmony_ci * `signal` [\<string>][<string>] | `null` Expected `child.signal` 561cb0ef41Sopenharmony_ci * `stderr` [\<string>][<string>] | [\<RegExp>][<RegExp>] | 571cb0ef41Sopenharmony_ci [\<Function>][<Function>] Optional. If it's a string, check that the output 581cb0ef41Sopenharmony_ci to the stderr of the child process is exactly the same as the string. If 591cb0ef41Sopenharmony_ci it's a regular expression, check that the stderr matches it. If it's a 601cb0ef41Sopenharmony_ci function, invoke it with the stderr output as a string and check 611cb0ef41Sopenharmony_ci that it returns true. The function can just throw errors (e.g. assertion 621cb0ef41Sopenharmony_ci errors) to provide more information if the check fails. 631cb0ef41Sopenharmony_ci * `stdout` [\<string>][<string>] | [\<RegExp>][<RegExp>] | 641cb0ef41Sopenharmony_ci [\<Function>][<Function>] Optional. Similar to `stderr` but for the stdout. 651cb0ef41Sopenharmony_ci * `trim` [\<boolean>][<boolean>] Optional. Whether this method should trim 661cb0ef41Sopenharmony_ci out the whitespace characters when checking `stderr` and `stdout` outputs. 671cb0ef41Sopenharmony_ci Defaults to `false`. 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci### `expectSyncExitWithoutError(child[, options])` 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ciSimilar to `expectSyncExit()` with the `status` expected to be 0 and 721cb0ef41Sopenharmony_ci`signal` expected to be `null`. Any other optional options are passed 731cb0ef41Sopenharmony_ciinto `expectSyncExit()`. 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci## Common Module API 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ciThe `common` module is used by tests for consistency across repeated 781cb0ef41Sopenharmony_citasks. 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci### `allowGlobals(...allowlist)` 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci* `allowlist` [\<Array>][<Array>] Array of Globals 831cb0ef41Sopenharmony_ci* return [\<Array>][<Array>] 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ciTakes `allowlist` and concats that with predefined `knownGlobals`. 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci### `canCreateSymLink()` 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci* return [\<boolean>][<boolean>] 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ciChecks whether the current running process can create symlinks. On Windows, this 921cb0ef41Sopenharmony_cireturns `false` if the process running doesn't have privileges to create 931cb0ef41Sopenharmony_cisymlinks 941cb0ef41Sopenharmony_ci([SeCreateSymbolicLinkPrivilege](https://msdn.microsoft.com/en-us/library/windows/desktop/bb530716\(v=vs.85\).aspx)). 951cb0ef41Sopenharmony_ciOn non-Windows platforms, this always returns `true`. 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci### `createZeroFilledFile(filename)` 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_ciCreates a 10 MiB file of all null characters. 1001cb0ef41Sopenharmony_ci 1011cb0ef41Sopenharmony_ci### `enoughTestMem` 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ciIndicates if there is more than 1gb of total memory. 1061cb0ef41Sopenharmony_ci 1071cb0ef41Sopenharmony_ci### `expectsError(validator[, exact])` 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ci* `validator` [\<Object>][<Object>] | [\<RegExp>][<RegExp>] | 1101cb0ef41Sopenharmony_ci [\<Function>][<Function>] | [\<Error>][<Error>] The validator behaves 1111cb0ef41Sopenharmony_ci identical to `assert.throws(fn, validator)`. 1121cb0ef41Sopenharmony_ci* `exact` [\<number>][<number>] default = 1 1131cb0ef41Sopenharmony_ci* return [\<Function>][<Function>] A callback function that expects an error. 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ciA function suitable as callback to validate callback based errors. The error is 1161cb0ef41Sopenharmony_civalidated using `assert.throws(() => { throw error; }, validator)`. If the 1171cb0ef41Sopenharmony_cireturned function has not been called exactly `exact` number of times when the 1181cb0ef41Sopenharmony_citest is complete, then the test will fail. 1191cb0ef41Sopenharmony_ci 1201cb0ef41Sopenharmony_ci### `expectWarning(name[, expected[, code]])` 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_ci* `name` [\<string>][<string>] | [\<Object>][<Object>] 1231cb0ef41Sopenharmony_ci* `expected` [\<string>][<string>] | [\<Array>][<Array>] | [\<Object>][<Object>] 1241cb0ef41Sopenharmony_ci* `code` [\<string>][<string>] 1251cb0ef41Sopenharmony_ci 1261cb0ef41Sopenharmony_ciTests whether `name`, `expected`, and `code` are part of a raised warning. 1271cb0ef41Sopenharmony_ci 1281cb0ef41Sopenharmony_ciThe code is required in case the name is set to `'DeprecationWarning'`. 1291cb0ef41Sopenharmony_ci 1301cb0ef41Sopenharmony_ciExamples: 1311cb0ef41Sopenharmony_ci 1321cb0ef41Sopenharmony_ci```js 1331cb0ef41Sopenharmony_ciconst { expectWarning } = require('../common'); 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ciexpectWarning('Warning', 'Foobar is really bad'); 1361cb0ef41Sopenharmony_ci 1371cb0ef41Sopenharmony_ciexpectWarning('DeprecationWarning', 'Foobar is deprecated', 'DEP0XXX'); 1381cb0ef41Sopenharmony_ci 1391cb0ef41Sopenharmony_ciexpectWarning('DeprecationWarning', [ 1401cb0ef41Sopenharmony_ci 'Foobar is deprecated', 'DEP0XXX', 1411cb0ef41Sopenharmony_ci]); 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_ciexpectWarning('DeprecationWarning', [ 1441cb0ef41Sopenharmony_ci ['Foobar is deprecated', 'DEP0XXX'], 1451cb0ef41Sopenharmony_ci ['Baz is also deprecated', 'DEP0XX2'], 1461cb0ef41Sopenharmony_ci]); 1471cb0ef41Sopenharmony_ci 1481cb0ef41Sopenharmony_ciexpectWarning('DeprecationWarning', { 1491cb0ef41Sopenharmony_ci DEP0XXX: 'Foobar is deprecated', 1501cb0ef41Sopenharmony_ci DEP0XX2: 'Baz is also deprecated', 1511cb0ef41Sopenharmony_ci}); 1521cb0ef41Sopenharmony_ci 1531cb0ef41Sopenharmony_ciexpectWarning({ 1541cb0ef41Sopenharmony_ci DeprecationWarning: { 1551cb0ef41Sopenharmony_ci DEP0XXX: 'Foobar is deprecated', 1561cb0ef41Sopenharmony_ci DEP0XX1: 'Baz is also deprecated', 1571cb0ef41Sopenharmony_ci }, 1581cb0ef41Sopenharmony_ci Warning: [ 1591cb0ef41Sopenharmony_ci ['Multiple array entries are fine', 'SpecialWarningCode'], 1601cb0ef41Sopenharmony_ci ['No code is also fine'], 1611cb0ef41Sopenharmony_ci ], 1621cb0ef41Sopenharmony_ci SingleEntry: ['This will also work', 'WarningCode'], 1631cb0ef41Sopenharmony_ci SingleString: 'Single string entries without code will also work', 1641cb0ef41Sopenharmony_ci}); 1651cb0ef41Sopenharmony_ci``` 1661cb0ef41Sopenharmony_ci 1671cb0ef41Sopenharmony_ci### `getArrayBufferViews(buf)` 1681cb0ef41Sopenharmony_ci 1691cb0ef41Sopenharmony_ci* `buf` [\<Buffer>][<Buffer>] 1701cb0ef41Sopenharmony_ci* return [\<ArrayBufferView>][<ArrayBufferView>]\[] 1711cb0ef41Sopenharmony_ci 1721cb0ef41Sopenharmony_ciReturns an instance of all possible `ArrayBufferView`s of the provided Buffer. 1731cb0ef41Sopenharmony_ci 1741cb0ef41Sopenharmony_ci### `getBufferSources(buf)` 1751cb0ef41Sopenharmony_ci 1761cb0ef41Sopenharmony_ci* `buf` [\<Buffer>][<Buffer>] 1771cb0ef41Sopenharmony_ci* return [\<BufferSource>][<BufferSource>]\[] 1781cb0ef41Sopenharmony_ci 1791cb0ef41Sopenharmony_ciReturns an instance of all possible `BufferSource`s of the provided Buffer, 1801cb0ef41Sopenharmony_ciconsisting of all `ArrayBufferView` and an `ArrayBuffer`. 1811cb0ef41Sopenharmony_ci 1821cb0ef41Sopenharmony_ci### `getCallSite(func)` 1831cb0ef41Sopenharmony_ci 1841cb0ef41Sopenharmony_ci* `func` [\<Function>][<Function>] 1851cb0ef41Sopenharmony_ci* return [\<string>][<string>] 1861cb0ef41Sopenharmony_ci 1871cb0ef41Sopenharmony_ciReturns the file name and line number for the provided Function. 1881cb0ef41Sopenharmony_ci 1891cb0ef41Sopenharmony_ci### `getTTYfd()` 1901cb0ef41Sopenharmony_ci 1911cb0ef41Sopenharmony_ciAttempts to get a valid TTY file descriptor. Returns `-1` if it fails. 1921cb0ef41Sopenharmony_ci 1931cb0ef41Sopenharmony_ciThe TTY file descriptor is assumed to be capable of being writable. 1941cb0ef41Sopenharmony_ci 1951cb0ef41Sopenharmony_ci### `hasCrypto` 1961cb0ef41Sopenharmony_ci 1971cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 1981cb0ef41Sopenharmony_ci 1991cb0ef41Sopenharmony_ciIndicates whether OpenSSL is available. 2001cb0ef41Sopenharmony_ci 2011cb0ef41Sopenharmony_ci### `hasFipsCrypto` 2021cb0ef41Sopenharmony_ci 2031cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2041cb0ef41Sopenharmony_ci 2051cb0ef41Sopenharmony_ciIndicates that Node.js has been linked with a FIPS compatible OpenSSL library, 2061cb0ef41Sopenharmony_ciand that FIPS as been enabled using `--enable-fips`. 2071cb0ef41Sopenharmony_ci 2081cb0ef41Sopenharmony_ciTo only detect if the OpenSSL library is FIPS compatible, regardless if it has 2091cb0ef41Sopenharmony_cibeen enabled or not, then `process.config.variables.openssl_is_fips` can be 2101cb0ef41Sopenharmony_ciused to determine that situation. 2111cb0ef41Sopenharmony_ci 2121cb0ef41Sopenharmony_ci### `hasIntl` 2131cb0ef41Sopenharmony_ci 2141cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2151cb0ef41Sopenharmony_ci 2161cb0ef41Sopenharmony_ciIndicates if [internationalization][] is supported. 2171cb0ef41Sopenharmony_ci 2181cb0ef41Sopenharmony_ci### `hasIPv6` 2191cb0ef41Sopenharmony_ci 2201cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2211cb0ef41Sopenharmony_ci 2221cb0ef41Sopenharmony_ciIndicates whether `IPv6` is supported on this platform. 2231cb0ef41Sopenharmony_ci 2241cb0ef41Sopenharmony_ci### `hasMultiLocalhost` 2251cb0ef41Sopenharmony_ci 2261cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2271cb0ef41Sopenharmony_ci 2281cb0ef41Sopenharmony_ciIndicates if there are multiple localhosts available. 2291cb0ef41Sopenharmony_ci 2301cb0ef41Sopenharmony_ci### `inFreeBSDJail` 2311cb0ef41Sopenharmony_ci 2321cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2331cb0ef41Sopenharmony_ci 2341cb0ef41Sopenharmony_ciChecks whether free BSD Jail is true or false. 2351cb0ef41Sopenharmony_ci 2361cb0ef41Sopenharmony_ci### `isAIX` 2371cb0ef41Sopenharmony_ci 2381cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2391cb0ef41Sopenharmony_ci 2401cb0ef41Sopenharmony_ciPlatform check for Advanced Interactive eXecutive (AIX). 2411cb0ef41Sopenharmony_ci 2421cb0ef41Sopenharmony_ci### `isAlive(pid)` 2431cb0ef41Sopenharmony_ci 2441cb0ef41Sopenharmony_ci* `pid` [\<number>][<number>] 2451cb0ef41Sopenharmony_ci* return [\<boolean>][<boolean>] 2461cb0ef41Sopenharmony_ci 2471cb0ef41Sopenharmony_ciAttempts to 'kill' `pid` 2481cb0ef41Sopenharmony_ci 2491cb0ef41Sopenharmony_ci### `isDumbTerminal` 2501cb0ef41Sopenharmony_ci 2511cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2521cb0ef41Sopenharmony_ci 2531cb0ef41Sopenharmony_ci### `isFreeBSD` 2541cb0ef41Sopenharmony_ci 2551cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2561cb0ef41Sopenharmony_ci 2571cb0ef41Sopenharmony_ciPlatform check for Free BSD. 2581cb0ef41Sopenharmony_ci 2591cb0ef41Sopenharmony_ci### `isIBMi` 2601cb0ef41Sopenharmony_ci 2611cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2621cb0ef41Sopenharmony_ci 2631cb0ef41Sopenharmony_ciPlatform check for IBMi. 2641cb0ef41Sopenharmony_ci 2651cb0ef41Sopenharmony_ci### `isLinux` 2661cb0ef41Sopenharmony_ci 2671cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2681cb0ef41Sopenharmony_ci 2691cb0ef41Sopenharmony_ciPlatform check for Linux. 2701cb0ef41Sopenharmony_ci 2711cb0ef41Sopenharmony_ci### `isLinuxPPCBE` 2721cb0ef41Sopenharmony_ci 2731cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2741cb0ef41Sopenharmony_ci 2751cb0ef41Sopenharmony_ciPlatform check for Linux on PowerPC. 2761cb0ef41Sopenharmony_ci 2771cb0ef41Sopenharmony_ci### `isOSX` 2781cb0ef41Sopenharmony_ci 2791cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2801cb0ef41Sopenharmony_ci 2811cb0ef41Sopenharmony_ciPlatform check for macOS. 2821cb0ef41Sopenharmony_ci 2831cb0ef41Sopenharmony_ci### `isSunOS` 2841cb0ef41Sopenharmony_ci 2851cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2861cb0ef41Sopenharmony_ci 2871cb0ef41Sopenharmony_ciPlatform check for SunOS. 2881cb0ef41Sopenharmony_ci 2891cb0ef41Sopenharmony_ci### `isWindows` 2901cb0ef41Sopenharmony_ci 2911cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 2921cb0ef41Sopenharmony_ci 2931cb0ef41Sopenharmony_ciPlatform check for Windows. 2941cb0ef41Sopenharmony_ci 2951cb0ef41Sopenharmony_ci### `localhostIPv4` 2961cb0ef41Sopenharmony_ci 2971cb0ef41Sopenharmony_ci* [\<string>][<string>] 2981cb0ef41Sopenharmony_ci 2991cb0ef41Sopenharmony_ciIP of `localhost`. 3001cb0ef41Sopenharmony_ci 3011cb0ef41Sopenharmony_ci### `localIPv6Hosts` 3021cb0ef41Sopenharmony_ci 3031cb0ef41Sopenharmony_ci* [\<Array>][<Array>] 3041cb0ef41Sopenharmony_ci 3051cb0ef41Sopenharmony_ciArray of IPV6 representations for `localhost`. 3061cb0ef41Sopenharmony_ci 3071cb0ef41Sopenharmony_ci### `mustCall([fn][, exact])` 3081cb0ef41Sopenharmony_ci 3091cb0ef41Sopenharmony_ci* `fn` [\<Function>][<Function>] default = () => {} 3101cb0ef41Sopenharmony_ci* `exact` [\<number>][<number>] default = 1 3111cb0ef41Sopenharmony_ci* return [\<Function>][<Function>] 3121cb0ef41Sopenharmony_ci 3131cb0ef41Sopenharmony_ciReturns a function that calls `fn`. If the returned function has not been called 3141cb0ef41Sopenharmony_ciexactly `exact` number of times when the test is complete, then the test will 3151cb0ef41Sopenharmony_cifail. 3161cb0ef41Sopenharmony_ci 3171cb0ef41Sopenharmony_ciIf `fn` is not provided, an empty function will be used. 3181cb0ef41Sopenharmony_ci 3191cb0ef41Sopenharmony_ci### `mustCallAtLeast([fn][, minimum])` 3201cb0ef41Sopenharmony_ci 3211cb0ef41Sopenharmony_ci* `fn` [\<Function>][<Function>] default = () => {} 3221cb0ef41Sopenharmony_ci* `minimum` [\<number>][<number>] default = 1 3231cb0ef41Sopenharmony_ci* return [\<Function>][<Function>] 3241cb0ef41Sopenharmony_ci 3251cb0ef41Sopenharmony_ciReturns a function that calls `fn`. If the returned function has not been called 3261cb0ef41Sopenharmony_ciat least `minimum` number of times when the test is complete, then the test will 3271cb0ef41Sopenharmony_cifail. 3281cb0ef41Sopenharmony_ci 3291cb0ef41Sopenharmony_ciIf `fn` is not provided, an empty function will be used. 3301cb0ef41Sopenharmony_ci 3311cb0ef41Sopenharmony_ci### `mustNotCall([msg])` 3321cb0ef41Sopenharmony_ci 3331cb0ef41Sopenharmony_ci* `msg` [\<string>][<string>] default = 'function should not have been called' 3341cb0ef41Sopenharmony_ci* return [\<Function>][<Function>] 3351cb0ef41Sopenharmony_ci 3361cb0ef41Sopenharmony_ciReturns a function that triggers an `AssertionError` if it is invoked. `msg` is 3371cb0ef41Sopenharmony_ciused as the error message for the `AssertionError`. 3381cb0ef41Sopenharmony_ci 3391cb0ef41Sopenharmony_ci### `mustNotMutateObjectDeep([target])` 3401cb0ef41Sopenharmony_ci 3411cb0ef41Sopenharmony_ci* `target` [\<any>][<any>] default = `undefined` 3421cb0ef41Sopenharmony_ci* return [\<any>][<any>] 3431cb0ef41Sopenharmony_ci 3441cb0ef41Sopenharmony_ciIf `target` is an Object, returns a proxy object that triggers 3451cb0ef41Sopenharmony_cian `AssertionError` on mutation attempt, including mutation of deeply nested 3461cb0ef41Sopenharmony_ciObjects. Otherwise, it returns `target` directly. 3471cb0ef41Sopenharmony_ci 3481cb0ef41Sopenharmony_ciUse of this function is encouraged for relevant regression tests. 3491cb0ef41Sopenharmony_ci 3501cb0ef41Sopenharmony_ci```mjs 3511cb0ef41Sopenharmony_ciimport { open } from 'node:fs/promises'; 3521cb0ef41Sopenharmony_ciimport { mustNotMutateObjectDeep } from '../common/index.mjs'; 3531cb0ef41Sopenharmony_ci 3541cb0ef41Sopenharmony_ciconst _mutableOptions = { length: 4, position: 8 }; 3551cb0ef41Sopenharmony_ciconst options = mustNotMutateObjectDeep(_mutableOptions); 3561cb0ef41Sopenharmony_ci 3571cb0ef41Sopenharmony_ci// In filehandle.read or filehandle.write, attempt to mutate options will throw 3581cb0ef41Sopenharmony_ci// In the test code, options can still be mutated via _mutableOptions 3591cb0ef41Sopenharmony_ciconst fh = await open('/path/to/file', 'r+'); 3601cb0ef41Sopenharmony_ciconst { buffer } = await fh.read(options); 3611cb0ef41Sopenharmony_ci_mutableOptions.position = 4; 3621cb0ef41Sopenharmony_ciawait fh.write(buffer, options); 3631cb0ef41Sopenharmony_ci 3641cb0ef41Sopenharmony_ci// Inline usage 3651cb0ef41Sopenharmony_ciconst stats = await fh.stat(mustNotMutateObjectDeep({ bigint: true })); 3661cb0ef41Sopenharmony_ciconsole.log(stats.size); 3671cb0ef41Sopenharmony_ci``` 3681cb0ef41Sopenharmony_ci 3691cb0ef41Sopenharmony_ciCaveats: built-in objects that make use of their internal slots (for example, 3701cb0ef41Sopenharmony_ci`Map`s and `Set`s) might not work with this function. It returns Functions 3711cb0ef41Sopenharmony_cidirectly, not preventing their mutation. 3721cb0ef41Sopenharmony_ci 3731cb0ef41Sopenharmony_ci### `mustSucceed([fn])` 3741cb0ef41Sopenharmony_ci 3751cb0ef41Sopenharmony_ci* `fn` [\<Function>][<Function>] default = () => {} 3761cb0ef41Sopenharmony_ci* return [\<Function>][<Function>] 3771cb0ef41Sopenharmony_ci 3781cb0ef41Sopenharmony_ciReturns a function that accepts arguments `(err, ...args)`. If `err` is not 3791cb0ef41Sopenharmony_ci`undefined` or `null`, it triggers an `AssertionError`. Otherwise, it calls 3801cb0ef41Sopenharmony_ci`fn(...args)`. 3811cb0ef41Sopenharmony_ci 3821cb0ef41Sopenharmony_ci### `nodeProcessAborted(exitCode, signal)` 3831cb0ef41Sopenharmony_ci 3841cb0ef41Sopenharmony_ci* `exitCode` [\<number>][<number>] 3851cb0ef41Sopenharmony_ci* `signal` [\<string>][<string>] 3861cb0ef41Sopenharmony_ci* return [\<boolean>][<boolean>] 3871cb0ef41Sopenharmony_ci 3881cb0ef41Sopenharmony_ciReturns `true` if the exit code `exitCode` and/or signal name `signal` represent 3891cb0ef41Sopenharmony_cithe exit code and/or signal name of a node process that aborted, `false` 3901cb0ef41Sopenharmony_ciotherwise. 3911cb0ef41Sopenharmony_ci 3921cb0ef41Sopenharmony_ci### `opensslCli` 3931cb0ef41Sopenharmony_ci 3941cb0ef41Sopenharmony_ci* [\<boolean>][<boolean>] 3951cb0ef41Sopenharmony_ci 3961cb0ef41Sopenharmony_ciIndicates whether 'opensslCli' is supported. 3971cb0ef41Sopenharmony_ci 3981cb0ef41Sopenharmony_ci### `platformTimeout(ms)` 3991cb0ef41Sopenharmony_ci 4001cb0ef41Sopenharmony_ci* `ms` [\<number>][<number>] | [\<bigint>][<bigint>] 4011cb0ef41Sopenharmony_ci* return [\<number>][<number>] | [\<bigint>][<bigint>] 4021cb0ef41Sopenharmony_ci 4031cb0ef41Sopenharmony_ciReturns a timeout value based on detected conditions. For example, a debug build 4041cb0ef41Sopenharmony_cimay need extra time so the returned value will be larger than on a release 4051cb0ef41Sopenharmony_cibuild. 4061cb0ef41Sopenharmony_ci 4071cb0ef41Sopenharmony_ci### `PIPE` 4081cb0ef41Sopenharmony_ci 4091cb0ef41Sopenharmony_ci* [\<string>][<string>] 4101cb0ef41Sopenharmony_ci 4111cb0ef41Sopenharmony_ciPath to the test socket. 4121cb0ef41Sopenharmony_ci 4131cb0ef41Sopenharmony_ci### `PORT` 4141cb0ef41Sopenharmony_ci 4151cb0ef41Sopenharmony_ci* [\<number>][<number>] 4161cb0ef41Sopenharmony_ci 4171cb0ef41Sopenharmony_ciA port number for tests to use if one is needed. 4181cb0ef41Sopenharmony_ci 4191cb0ef41Sopenharmony_ci### `printSkipMessage(msg)` 4201cb0ef41Sopenharmony_ci 4211cb0ef41Sopenharmony_ci* `msg` [\<string>][<string>] 4221cb0ef41Sopenharmony_ci 4231cb0ef41Sopenharmony_ciLogs '1..0 # Skipped: ' + `msg` 4241cb0ef41Sopenharmony_ci 4251cb0ef41Sopenharmony_ci### `pwdCommand` 4261cb0ef41Sopenharmony_ci 4271cb0ef41Sopenharmony_ci* [\<array>][<array>] First two argument for the `spawn`/`exec` functions. 4281cb0ef41Sopenharmony_ci 4291cb0ef41Sopenharmony_ciPlatform normalized `pwd` command options. Usage example: 4301cb0ef41Sopenharmony_ci 4311cb0ef41Sopenharmony_ci```js 4321cb0ef41Sopenharmony_ciconst common = require('../common'); 4331cb0ef41Sopenharmony_ciconst { spawn } = require('node:child_process'); 4341cb0ef41Sopenharmony_ci 4351cb0ef41Sopenharmony_cispawn(...common.pwdCommand, { stdio: ['pipe'] }); 4361cb0ef41Sopenharmony_ci``` 4371cb0ef41Sopenharmony_ci 4381cb0ef41Sopenharmony_ci### `requireNoPackageJSONAbove([dir])` 4391cb0ef41Sopenharmony_ci 4401cb0ef41Sopenharmony_ci* `dir` [\<string>][<string>] default = \_\_dirname 4411cb0ef41Sopenharmony_ci 4421cb0ef41Sopenharmony_ciThrows an `AssertionError` if a `package.json` file exists in any ancestor 4431cb0ef41Sopenharmony_cidirectory above `dir`. Such files may interfere with proper test functionality. 4441cb0ef41Sopenharmony_ci 4451cb0ef41Sopenharmony_ci### `runWithInvalidFD(func)` 4461cb0ef41Sopenharmony_ci 4471cb0ef41Sopenharmony_ci* `func` [\<Function>][<Function>] 4481cb0ef41Sopenharmony_ci 4491cb0ef41Sopenharmony_ciRuns `func` with an invalid file descriptor that is an unsigned integer and 4501cb0ef41Sopenharmony_cican be used to trigger `EBADF` as the first argument. If no such file 4511cb0ef41Sopenharmony_cidescriptor could be generated, a skip message will be printed and the `func` 4521cb0ef41Sopenharmony_ciwill not be run. 4531cb0ef41Sopenharmony_ci 4541cb0ef41Sopenharmony_ci### `skip(msg)` 4551cb0ef41Sopenharmony_ci 4561cb0ef41Sopenharmony_ci* `msg` [\<string>][<string>] 4571cb0ef41Sopenharmony_ci 4581cb0ef41Sopenharmony_ciLogs '1..0 # Skipped: ' + `msg` and exits with exit code `0`. 4591cb0ef41Sopenharmony_ci 4601cb0ef41Sopenharmony_ci### `skipIfDumbTerminal()` 4611cb0ef41Sopenharmony_ci 4621cb0ef41Sopenharmony_ciSkip the rest of the tests if the current terminal is a dumb terminal 4631cb0ef41Sopenharmony_ci 4641cb0ef41Sopenharmony_ci### `skipIfEslintMissing()` 4651cb0ef41Sopenharmony_ci 4661cb0ef41Sopenharmony_ciSkip the rest of the tests in the current file when `ESLint` is not available 4671cb0ef41Sopenharmony_ciat `tools/node_modules/eslint` 4681cb0ef41Sopenharmony_ci 4691cb0ef41Sopenharmony_ci### `skipIfInspectorDisabled()` 4701cb0ef41Sopenharmony_ci 4711cb0ef41Sopenharmony_ciSkip the rest of the tests in the current file when the Inspector 4721cb0ef41Sopenharmony_ciwas disabled at compile time. 4731cb0ef41Sopenharmony_ci 4741cb0ef41Sopenharmony_ci### `skipIf32Bits()` 4751cb0ef41Sopenharmony_ci 4761cb0ef41Sopenharmony_ciSkip the rest of the tests in the current file when the Node.js executable 4771cb0ef41Sopenharmony_ciwas compiled with a pointer size smaller than 64 bits. 4781cb0ef41Sopenharmony_ci 4791cb0ef41Sopenharmony_ci### `skipIfWorker()` 4801cb0ef41Sopenharmony_ci 4811cb0ef41Sopenharmony_ciSkip the rest of the tests in the current file when not running on a main 4821cb0ef41Sopenharmony_cithread. 4831cb0ef41Sopenharmony_ci 4841cb0ef41Sopenharmony_ci## ArrayStream Module 4851cb0ef41Sopenharmony_ci 4861cb0ef41Sopenharmony_ciThe `ArrayStream` module provides a simple `Stream` that pushes elements from 4871cb0ef41Sopenharmony_cia given array. 4881cb0ef41Sopenharmony_ci 4891cb0ef41Sopenharmony_ci<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 4901cb0ef41Sopenharmony_ci 4911cb0ef41Sopenharmony_ci```js 4921cb0ef41Sopenharmony_ciconst ArrayStream = require('../common/arraystream'); 4931cb0ef41Sopenharmony_ciconst stream = new ArrayStream(); 4941cb0ef41Sopenharmony_cistream.run(['a', 'b', 'c']); 4951cb0ef41Sopenharmony_ci``` 4961cb0ef41Sopenharmony_ci 4971cb0ef41Sopenharmony_ciIt can be used within tests as a simple mock stream. 4981cb0ef41Sopenharmony_ci 4991cb0ef41Sopenharmony_ci## Countdown Module 5001cb0ef41Sopenharmony_ci 5011cb0ef41Sopenharmony_ciThe `Countdown` module provides a simple countdown mechanism for tests that 5021cb0ef41Sopenharmony_cirequire a particular action to be taken after a given number of completed 5031cb0ef41Sopenharmony_citasks (for instance, shutting down an HTTP server after a specific number of 5041cb0ef41Sopenharmony_cirequests). The Countdown will fail the test if the remainder did not reach 0. 5051cb0ef41Sopenharmony_ci 5061cb0ef41Sopenharmony_ci<!-- eslint-disable strict, node-core/require-common-first, node-core/required-modules --> 5071cb0ef41Sopenharmony_ci 5081cb0ef41Sopenharmony_ci```js 5091cb0ef41Sopenharmony_ciconst Countdown = require('../common/countdown'); 5101cb0ef41Sopenharmony_ci 5111cb0ef41Sopenharmony_cifunction doSomething() { 5121cb0ef41Sopenharmony_ci console.log('.'); 5131cb0ef41Sopenharmony_ci} 5141cb0ef41Sopenharmony_ci 5151cb0ef41Sopenharmony_ciconst countdown = new Countdown(2, doSomething); 5161cb0ef41Sopenharmony_cicountdown.dec(); 5171cb0ef41Sopenharmony_cicountdown.dec(); 5181cb0ef41Sopenharmony_ci``` 5191cb0ef41Sopenharmony_ci 5201cb0ef41Sopenharmony_ci### `new Countdown(limit, callback)` 5211cb0ef41Sopenharmony_ci 5221cb0ef41Sopenharmony_ci* `limit` {number} 5231cb0ef41Sopenharmony_ci* `callback` {function} 5241cb0ef41Sopenharmony_ci 5251cb0ef41Sopenharmony_ciCreates a new `Countdown` instance. 5261cb0ef41Sopenharmony_ci 5271cb0ef41Sopenharmony_ci### `Countdown.prototype.dec()` 5281cb0ef41Sopenharmony_ci 5291cb0ef41Sopenharmony_ciDecrements the `Countdown` counter. 5301cb0ef41Sopenharmony_ci 5311cb0ef41Sopenharmony_ci### `Countdown.prototype.remaining` 5321cb0ef41Sopenharmony_ci 5331cb0ef41Sopenharmony_ciSpecifies the remaining number of times `Countdown.prototype.dec()` must be 5341cb0ef41Sopenharmony_cicalled before the callback is invoked. 5351cb0ef41Sopenharmony_ci 5361cb0ef41Sopenharmony_ci## CPU Profiler module 5371cb0ef41Sopenharmony_ci 5381cb0ef41Sopenharmony_ciThe `cpu-prof` module provides utilities related to CPU profiling tests. 5391cb0ef41Sopenharmony_ci 5401cb0ef41Sopenharmony_ci### `env` 5411cb0ef41Sopenharmony_ci 5421cb0ef41Sopenharmony_ci* Default: { ...process.env, NODE\_DEBUG\_NATIVE: 'INSPECTOR\_PROFILER' } 5431cb0ef41Sopenharmony_ci 5441cb0ef41Sopenharmony_ciEnvironment variables used in profiled processes. 5451cb0ef41Sopenharmony_ci 5461cb0ef41Sopenharmony_ci### `getCpuProfiles(dir)` 5471cb0ef41Sopenharmony_ci 5481cb0ef41Sopenharmony_ci* `dir` {string} The directory containing the CPU profile files. 5491cb0ef41Sopenharmony_ci* return [\<string>][<string>] 5501cb0ef41Sopenharmony_ci 5511cb0ef41Sopenharmony_ciReturns an array of all `.cpuprofile` files found in `dir`. 5521cb0ef41Sopenharmony_ci 5531cb0ef41Sopenharmony_ci### `getFrames(file, suffix)` 5541cb0ef41Sopenharmony_ci 5551cb0ef41Sopenharmony_ci* `file` {string} Path to a `.cpuprofile` file. 5561cb0ef41Sopenharmony_ci* `suffix` {string} Suffix of the URL of call frames to retrieve. 5571cb0ef41Sopenharmony_ci* returns { frames: [\<Object>][<Object>], nodes: [\<Object>][<Object>] } 5581cb0ef41Sopenharmony_ci 5591cb0ef41Sopenharmony_ciReturns an object containing an array of the relevant call frames and an array 5601cb0ef41Sopenharmony_ciof all the profile nodes. 5611cb0ef41Sopenharmony_ci 5621cb0ef41Sopenharmony_ci### `kCpuProfInterval` 5631cb0ef41Sopenharmony_ci 5641cb0ef41Sopenharmony_ciSampling interval in microseconds. 5651cb0ef41Sopenharmony_ci 5661cb0ef41Sopenharmony_ci### `verifyFrames(output, file, suffix)` 5671cb0ef41Sopenharmony_ci 5681cb0ef41Sopenharmony_ci* `output` {string} 5691cb0ef41Sopenharmony_ci* `file` {string} 5701cb0ef41Sopenharmony_ci* `suffix` {string} 5711cb0ef41Sopenharmony_ci 5721cb0ef41Sopenharmony_ciThrows an `AssertionError` if there are no call frames with the expected 5731cb0ef41Sopenharmony_ci`suffix` in the profiling data contained in `file`. 5741cb0ef41Sopenharmony_ci 5751cb0ef41Sopenharmony_ci## Debugger module 5761cb0ef41Sopenharmony_ci 5771cb0ef41Sopenharmony_ciProvides common functionality for tests for `node inspect`. 5781cb0ef41Sopenharmony_ci 5791cb0ef41Sopenharmony_ci### `startCLI(args[[, flags], spawnOpts])` 5801cb0ef41Sopenharmony_ci 5811cb0ef41Sopenharmony_ci* `args` [\<string>][<string>] 5821cb0ef41Sopenharmony_ci* `flags` [\<string>][<string>] default = \[] 5831cb0ef41Sopenharmony_ci* `showOpts` [\<Object>][<Object>] default = {} 5841cb0ef41Sopenharmony_ci* return [\<Object>][<Object>] 5851cb0ef41Sopenharmony_ci 5861cb0ef41Sopenharmony_ciReturns a null-prototype object with properties that are functions and getters 5871cb0ef41Sopenharmony_ciused to interact with the `node inspect` CLI. These functions are: 5881cb0ef41Sopenharmony_ci 5891cb0ef41Sopenharmony_ci* `flushOutput()` 5901cb0ef41Sopenharmony_ci* `waitFor()` 5911cb0ef41Sopenharmony_ci* `waitForPrompt()` 5921cb0ef41Sopenharmony_ci* `waitForInitialBreak()` 5931cb0ef41Sopenharmony_ci* `breakInfo` 5941cb0ef41Sopenharmony_ci* `ctrlC()` 5951cb0ef41Sopenharmony_ci* `output` 5961cb0ef41Sopenharmony_ci* `rawOutput` 5971cb0ef41Sopenharmony_ci* `parseSourceLines()` 5981cb0ef41Sopenharmony_ci* `writeLine()` 5991cb0ef41Sopenharmony_ci* `command()` 6001cb0ef41Sopenharmony_ci* `stepCommand()` 6011cb0ef41Sopenharmony_ci* `quit()` 6021cb0ef41Sopenharmony_ci 6031cb0ef41Sopenharmony_ci## `DNS` Module 6041cb0ef41Sopenharmony_ci 6051cb0ef41Sopenharmony_ciThe `DNS` module provides utilities related to the `dns` built-in module. 6061cb0ef41Sopenharmony_ci 6071cb0ef41Sopenharmony_ci### `errorLookupMock(code, syscall)` 6081cb0ef41Sopenharmony_ci 6091cb0ef41Sopenharmony_ci* `code` [\<string>][<string>] Defaults to `dns.mockedErrorCode`. 6101cb0ef41Sopenharmony_ci* `syscall` [\<string>][<string>] Defaults to `dns.mockedSysCall`. 6111cb0ef41Sopenharmony_ci* return [\<Function>][<Function>] 6121cb0ef41Sopenharmony_ci 6131cb0ef41Sopenharmony_ciA mock for the `lookup` option of `net.connect()` that would result in an error 6141cb0ef41Sopenharmony_ciwith the `code` and the `syscall` specified. Returns a function that has the 6151cb0ef41Sopenharmony_cisame signature as `dns.lookup()`. 6161cb0ef41Sopenharmony_ci 6171cb0ef41Sopenharmony_ci### `mockedErrorCode` 6181cb0ef41Sopenharmony_ci 6191cb0ef41Sopenharmony_ciThe default `code` of errors generated by `errorLookupMock`. 6201cb0ef41Sopenharmony_ci 6211cb0ef41Sopenharmony_ci### `mockedSysCall` 6221cb0ef41Sopenharmony_ci 6231cb0ef41Sopenharmony_ciThe default `syscall` of errors generated by `errorLookupMock`. 6241cb0ef41Sopenharmony_ci 6251cb0ef41Sopenharmony_ci### `readDomainFromPacket(buffer, offset)` 6261cb0ef41Sopenharmony_ci 6271cb0ef41Sopenharmony_ci* `buffer` [\<Buffer>][<Buffer>] 6281cb0ef41Sopenharmony_ci* `offset` [\<number>][<number>] 6291cb0ef41Sopenharmony_ci* return [\<Object>][<Object>] 6301cb0ef41Sopenharmony_ci 6311cb0ef41Sopenharmony_ciReads the domain string from a packet and returns an object containing the 6321cb0ef41Sopenharmony_cinumber of bytes read and the domain. 6331cb0ef41Sopenharmony_ci 6341cb0ef41Sopenharmony_ci### `parseDNSPacket(buffer)` 6351cb0ef41Sopenharmony_ci 6361cb0ef41Sopenharmony_ci* `buffer` [\<Buffer>][<Buffer>] 6371cb0ef41Sopenharmony_ci* return [\<Object>][<Object>] 6381cb0ef41Sopenharmony_ci 6391cb0ef41Sopenharmony_ciParses a DNS packet. Returns an object with the values of the various flags of 6401cb0ef41Sopenharmony_cithe packet depending on the type of packet. 6411cb0ef41Sopenharmony_ci 6421cb0ef41Sopenharmony_ci### `writeIPv6(ip)` 6431cb0ef41Sopenharmony_ci 6441cb0ef41Sopenharmony_ci* `ip` [\<string>][<string>] 6451cb0ef41Sopenharmony_ci* return [\<Buffer>][<Buffer>] 6461cb0ef41Sopenharmony_ci 6471cb0ef41Sopenharmony_ciReads an IPv6 String and returns a Buffer containing the parts. 6481cb0ef41Sopenharmony_ci 6491cb0ef41Sopenharmony_ci### `writeDomainName(domain)` 6501cb0ef41Sopenharmony_ci 6511cb0ef41Sopenharmony_ci* `domain` [\<string>][<string>] 6521cb0ef41Sopenharmony_ci* return [\<Buffer>][<Buffer>] 6531cb0ef41Sopenharmony_ci 6541cb0ef41Sopenharmony_ciReads a Domain String and returns a Buffer containing the domain. 6551cb0ef41Sopenharmony_ci 6561cb0ef41Sopenharmony_ci### `writeDNSPacket(parsed)` 6571cb0ef41Sopenharmony_ci 6581cb0ef41Sopenharmony_ci* `parsed` [\<Object>][<Object>] 6591cb0ef41Sopenharmony_ci* return [\<Buffer>][<Buffer>] 6601cb0ef41Sopenharmony_ci 6611cb0ef41Sopenharmony_ciTakes in a parsed Object and writes its fields to a DNS packet as a Buffer 6621cb0ef41Sopenharmony_ciobject. 6631cb0ef41Sopenharmony_ci 6641cb0ef41Sopenharmony_ci## Duplex pair helper 6651cb0ef41Sopenharmony_ci 6661cb0ef41Sopenharmony_ciThe `common/duplexpair` module exports a single function `makeDuplexPair`, 6671cb0ef41Sopenharmony_ciwhich returns an object `{ clientSide, serverSide }` where each side is a 6681cb0ef41Sopenharmony_ci`Duplex` stream connected to the other side. 6691cb0ef41Sopenharmony_ci 6701cb0ef41Sopenharmony_ciThere is no difference between client or server side beyond their names. 6711cb0ef41Sopenharmony_ci 6721cb0ef41Sopenharmony_ci## Environment variables 6731cb0ef41Sopenharmony_ci 6741cb0ef41Sopenharmony_ciThe behavior of the Node.js test suite can be altered using the following 6751cb0ef41Sopenharmony_cienvironment variables. 6761cb0ef41Sopenharmony_ci 6771cb0ef41Sopenharmony_ci### `NODE_COMMON_PORT` 6781cb0ef41Sopenharmony_ci 6791cb0ef41Sopenharmony_ciIf set, `NODE_COMMON_PORT`'s value overrides the `common.PORT` default value of 6801cb0ef41Sopenharmony_ci12346\. 6811cb0ef41Sopenharmony_ci 6821cb0ef41Sopenharmony_ci### `NODE_REGENERATE_SNAPSHOTS` 6831cb0ef41Sopenharmony_ci 6841cb0ef41Sopenharmony_ciIf set, test snapshots for a the current test are regenerated. 6851cb0ef41Sopenharmony_cifor example `NODE_REGENERATE_SNAPSHOTS=1 out/Release/node test/parallel/test-runner-output.mjs` 6861cb0ef41Sopenharmony_ciwill update all the test runner output snapshots. 6871cb0ef41Sopenharmony_ci 6881cb0ef41Sopenharmony_ci### `NODE_SKIP_FLAG_CHECK` 6891cb0ef41Sopenharmony_ci 6901cb0ef41Sopenharmony_ciIf set, command line arguments passed to individual tests are not validated. 6911cb0ef41Sopenharmony_ci 6921cb0ef41Sopenharmony_ci### `NODE_SKIP_CRYPTO` 6931cb0ef41Sopenharmony_ci 6941cb0ef41Sopenharmony_ciIf set, crypto tests are skipped. 6951cb0ef41Sopenharmony_ci 6961cb0ef41Sopenharmony_ci### `NODE_TEST_KNOWN_GLOBALS` 6971cb0ef41Sopenharmony_ci 6981cb0ef41Sopenharmony_ciA comma-separated list of variables names that are appended to the global 6991cb0ef41Sopenharmony_civariable allowlist. Alternatively, if `NODE_TEST_KNOWN_GLOBALS` is set to `'0'`, 7001cb0ef41Sopenharmony_ciglobal leak detection is disabled. 7011cb0ef41Sopenharmony_ci 7021cb0ef41Sopenharmony_ci## Fixtures Module 7031cb0ef41Sopenharmony_ci 7041cb0ef41Sopenharmony_ciThe `common/fixtures` module provides convenience methods for working with 7051cb0ef41Sopenharmony_cifiles in the `test/fixtures` directory. 7061cb0ef41Sopenharmony_ci 7071cb0ef41Sopenharmony_ci### `fixtures.fixturesDir` 7081cb0ef41Sopenharmony_ci 7091cb0ef41Sopenharmony_ci* [\<string>][<string>] 7101cb0ef41Sopenharmony_ci 7111cb0ef41Sopenharmony_ciThe absolute path to the `test/fixtures/` directory. 7121cb0ef41Sopenharmony_ci 7131cb0ef41Sopenharmony_ci### `fixtures.path(...args)` 7141cb0ef41Sopenharmony_ci 7151cb0ef41Sopenharmony_ci* `...args` [\<string>][<string>] 7161cb0ef41Sopenharmony_ci 7171cb0ef41Sopenharmony_ciReturns the result of `path.join(fixtures.fixturesDir, ...args)`. 7181cb0ef41Sopenharmony_ci 7191cb0ef41Sopenharmony_ci### `fixtures.readSync(args[, enc])` 7201cb0ef41Sopenharmony_ci 7211cb0ef41Sopenharmony_ci* `args` [\<string>][<string>] | [\<Array>][<Array>] 7221cb0ef41Sopenharmony_ci 7231cb0ef41Sopenharmony_ciReturns the result of 7241cb0ef41Sopenharmony_ci`fs.readFileSync(path.join(fixtures.fixturesDir, ...args), 'enc')`. 7251cb0ef41Sopenharmony_ci 7261cb0ef41Sopenharmony_ci### `fixtures.readKey(arg[, enc])` 7271cb0ef41Sopenharmony_ci 7281cb0ef41Sopenharmony_ci* `arg` [\<string>][<string>] 7291cb0ef41Sopenharmony_ci 7301cb0ef41Sopenharmony_ciReturns the result of 7311cb0ef41Sopenharmony_ci`fs.readFileSync(path.join(fixtures.fixturesDir, 'keys', arg), 'enc')`. 7321cb0ef41Sopenharmony_ci 7331cb0ef41Sopenharmony_ci## Heap dump checker module 7341cb0ef41Sopenharmony_ci 7351cb0ef41Sopenharmony_ciThis provides utilities for checking the validity of heap dumps. 7361cb0ef41Sopenharmony_ciThis requires the usage of `--expose-internals`. 7371cb0ef41Sopenharmony_ci 7381cb0ef41Sopenharmony_ci### `heap.recordState()` 7391cb0ef41Sopenharmony_ci 7401cb0ef41Sopenharmony_ciCreate a heap dump and an embedder graph copy for inspection. 7411cb0ef41Sopenharmony_ciThe returned object has a `validateSnapshotNodes` function similar to the 7421cb0ef41Sopenharmony_cione listed below. (`heap.validateSnapshotNodes(...)` is a shortcut for 7431cb0ef41Sopenharmony_ci`heap.recordState().validateSnapshotNodes(...)`.) 7441cb0ef41Sopenharmony_ci 7451cb0ef41Sopenharmony_ci### `heap.validateSnapshotNodes(name, expected, options)` 7461cb0ef41Sopenharmony_ci 7471cb0ef41Sopenharmony_ci* `name` [\<string>][<string>] Look for this string as the name of heap dump 7481cb0ef41Sopenharmony_ci nodes. 7491cb0ef41Sopenharmony_ci* `expected` [\<Array>][<Array>] A list of objects, possibly with an `children` 7501cb0ef41Sopenharmony_ci property that points to expected other adjacent nodes. 7511cb0ef41Sopenharmony_ci* `options` [\<Array>][<Array>] 7521cb0ef41Sopenharmony_ci * `loose` [\<boolean>][<boolean>] Do not expect an exact listing of 7531cb0ef41Sopenharmony_ci occurrences of nodes with name `name` in `expected`. 7541cb0ef41Sopenharmony_ci 7551cb0ef41Sopenharmony_ciCreate a heap dump and an embedder graph copy and validate occurrences. 7561cb0ef41Sopenharmony_ci 7571cb0ef41Sopenharmony_ci<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 7581cb0ef41Sopenharmony_ci 7591cb0ef41Sopenharmony_ci```js 7601cb0ef41Sopenharmony_civalidateSnapshotNodes('TLSWRAP', [ 7611cb0ef41Sopenharmony_ci { 7621cb0ef41Sopenharmony_ci children: [ 7631cb0ef41Sopenharmony_ci { name: 'enc_out' }, 7641cb0ef41Sopenharmony_ci { name: 'enc_in' }, 7651cb0ef41Sopenharmony_ci { name: 'TLSWrap' }, 7661cb0ef41Sopenharmony_ci ], 7671cb0ef41Sopenharmony_ci }, 7681cb0ef41Sopenharmony_ci]); 7691cb0ef41Sopenharmony_ci``` 7701cb0ef41Sopenharmony_ci 7711cb0ef41Sopenharmony_ci## hijackstdio Module 7721cb0ef41Sopenharmony_ci 7731cb0ef41Sopenharmony_ciThe `hijackstdio` module provides utility functions for temporarily redirecting 7741cb0ef41Sopenharmony_ci`stdout` and `stderr` output. 7751cb0ef41Sopenharmony_ci 7761cb0ef41Sopenharmony_ci<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 7771cb0ef41Sopenharmony_ci 7781cb0ef41Sopenharmony_ci```js 7791cb0ef41Sopenharmony_ciconst { hijackStdout, restoreStdout } = require('../common/hijackstdio'); 7801cb0ef41Sopenharmony_ci 7811cb0ef41Sopenharmony_cihijackStdout((data) => { 7821cb0ef41Sopenharmony_ci /* Do something with data */ 7831cb0ef41Sopenharmony_ci restoreStdout(); 7841cb0ef41Sopenharmony_ci}); 7851cb0ef41Sopenharmony_ci 7861cb0ef41Sopenharmony_ciconsole.log('this is sent to the hijacked listener'); 7871cb0ef41Sopenharmony_ci``` 7881cb0ef41Sopenharmony_ci 7891cb0ef41Sopenharmony_ci### `hijackStderr(listener)` 7901cb0ef41Sopenharmony_ci 7911cb0ef41Sopenharmony_ci* `listener` [\<Function>][<Function>]: a listener with a single parameter 7921cb0ef41Sopenharmony_ci called `data`. 7931cb0ef41Sopenharmony_ci 7941cb0ef41Sopenharmony_ciEavesdrop to `process.stderr.write()` calls. Once `process.stderr.write()` is 7951cb0ef41Sopenharmony_cicalled, `listener` will also be called and the `data` of `write` function will 7961cb0ef41Sopenharmony_cibe passed to `listener`. What's more, `process.stderr.writeTimes` is a count of 7971cb0ef41Sopenharmony_cithe number of calls. 7981cb0ef41Sopenharmony_ci 7991cb0ef41Sopenharmony_ci### `hijackStdout(listener)` 8001cb0ef41Sopenharmony_ci 8011cb0ef41Sopenharmony_ci* `listener` [\<Function>][<Function>]: a listener with a single parameter 8021cb0ef41Sopenharmony_ci called `data`. 8031cb0ef41Sopenharmony_ci 8041cb0ef41Sopenharmony_ciEavesdrop to `process.stdout.write()` calls. Once `process.stdout.write()` is 8051cb0ef41Sopenharmony_cicalled, `listener` will also be called and the `data` of `write` function will 8061cb0ef41Sopenharmony_cibe passed to `listener`. What's more, `process.stdout.writeTimes` is a count of 8071cb0ef41Sopenharmony_cithe number of calls. 8081cb0ef41Sopenharmony_ci 8091cb0ef41Sopenharmony_ci### restoreStderr() 8101cb0ef41Sopenharmony_ci 8111cb0ef41Sopenharmony_ciRestore the original `process.stderr.write()`. Used to restore `stderr` to its 8121cb0ef41Sopenharmony_cioriginal state after calling [`hijackstdio.hijackStdErr()`][]. 8131cb0ef41Sopenharmony_ci 8141cb0ef41Sopenharmony_ci### restoreStdout() 8151cb0ef41Sopenharmony_ci 8161cb0ef41Sopenharmony_ciRestore the original `process.stdout.write()`. Used to restore `stdout` to its 8171cb0ef41Sopenharmony_cioriginal state after calling [`hijackstdio.hijackStdOut()`][]. 8181cb0ef41Sopenharmony_ci 8191cb0ef41Sopenharmony_ci## HTTP/2 Module 8201cb0ef41Sopenharmony_ci 8211cb0ef41Sopenharmony_ciThe http2.js module provides a handful of utilities for creating mock HTTP/2 8221cb0ef41Sopenharmony_ciframes for testing of HTTP/2 endpoints 8231cb0ef41Sopenharmony_ci 8241cb0ef41Sopenharmony_ci<!-- eslint-disable no-unused-vars, node-core/require-common-first, node-core/required-modules --> 8251cb0ef41Sopenharmony_ci 8261cb0ef41Sopenharmony_ci```js 8271cb0ef41Sopenharmony_ciconst http2 = require('../common/http2'); 8281cb0ef41Sopenharmony_ci``` 8291cb0ef41Sopenharmony_ci 8301cb0ef41Sopenharmony_ci### Class: Frame 8311cb0ef41Sopenharmony_ci 8321cb0ef41Sopenharmony_ciThe `http2.Frame` is a base class that creates a `Buffer` containing a 8331cb0ef41Sopenharmony_ciserialized HTTP/2 frame header. 8341cb0ef41Sopenharmony_ci 8351cb0ef41Sopenharmony_ci<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 8361cb0ef41Sopenharmony_ci 8371cb0ef41Sopenharmony_ci```js 8381cb0ef41Sopenharmony_ci// length is a 24-bit unsigned integer 8391cb0ef41Sopenharmony_ci// type is an 8-bit unsigned integer identifying the frame type 8401cb0ef41Sopenharmony_ci// flags is an 8-bit unsigned integer containing the flag bits 8411cb0ef41Sopenharmony_ci// id is the 32-bit stream identifier, if any. 8421cb0ef41Sopenharmony_ciconst frame = new http2.Frame(length, type, flags, id); 8431cb0ef41Sopenharmony_ci 8441cb0ef41Sopenharmony_ci// Write the frame data to a socket 8451cb0ef41Sopenharmony_cisocket.write(frame.data); 8461cb0ef41Sopenharmony_ci``` 8471cb0ef41Sopenharmony_ci 8481cb0ef41Sopenharmony_ciThe serialized `Buffer` may be retrieved using the `frame.data` property. 8491cb0ef41Sopenharmony_ci 8501cb0ef41Sopenharmony_ci### Class: DataFrame extends Frame 8511cb0ef41Sopenharmony_ci 8521cb0ef41Sopenharmony_ciThe `http2.DataFrame` is a subclass of `http2.Frame` that serializes a `DATA` 8531cb0ef41Sopenharmony_ciframe. 8541cb0ef41Sopenharmony_ci 8551cb0ef41Sopenharmony_ci<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 8561cb0ef41Sopenharmony_ci 8571cb0ef41Sopenharmony_ci```js 8581cb0ef41Sopenharmony_ci// id is the 32-bit stream identifier 8591cb0ef41Sopenharmony_ci// payload is a Buffer containing the DATA payload 8601cb0ef41Sopenharmony_ci// padlen is an 8-bit integer giving the number of padding bytes to include 8611cb0ef41Sopenharmony_ci// final is a boolean indicating whether the End-of-stream flag should be set, 8621cb0ef41Sopenharmony_ci// defaults to false. 8631cb0ef41Sopenharmony_ciconst frame = new http2.DataFrame(id, payload, padlen, final); 8641cb0ef41Sopenharmony_ci 8651cb0ef41Sopenharmony_cisocket.write(frame.data); 8661cb0ef41Sopenharmony_ci``` 8671cb0ef41Sopenharmony_ci 8681cb0ef41Sopenharmony_ci### Class: HeadersFrame 8691cb0ef41Sopenharmony_ci 8701cb0ef41Sopenharmony_ciThe `http2.HeadersFrame` is a subclass of `http2.Frame` that serializes a 8711cb0ef41Sopenharmony_ci`HEADERS` frame. 8721cb0ef41Sopenharmony_ci 8731cb0ef41Sopenharmony_ci<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 8741cb0ef41Sopenharmony_ci 8751cb0ef41Sopenharmony_ci```js 8761cb0ef41Sopenharmony_ci// id is the 32-bit stream identifier 8771cb0ef41Sopenharmony_ci// payload is a Buffer containing the HEADERS payload (see either 8781cb0ef41Sopenharmony_ci// http2.kFakeRequestHeaders or http2.kFakeResponseHeaders). 8791cb0ef41Sopenharmony_ci// padlen is an 8-bit integer giving the number of padding bytes to include 8801cb0ef41Sopenharmony_ci// final is a boolean indicating whether the End-of-stream flag should be set, 8811cb0ef41Sopenharmony_ci// defaults to false. 8821cb0ef41Sopenharmony_ciconst frame = new http2.HeadersFrame(id, payload, padlen, final); 8831cb0ef41Sopenharmony_ci 8841cb0ef41Sopenharmony_cisocket.write(frame.data); 8851cb0ef41Sopenharmony_ci``` 8861cb0ef41Sopenharmony_ci 8871cb0ef41Sopenharmony_ci### Class: SettingsFrame 8881cb0ef41Sopenharmony_ci 8891cb0ef41Sopenharmony_ciThe `http2.SettingsFrame` is a subclass of `http2.Frame` that serializes an 8901cb0ef41Sopenharmony_ciempty `SETTINGS` frame. 8911cb0ef41Sopenharmony_ci 8921cb0ef41Sopenharmony_ci<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 8931cb0ef41Sopenharmony_ci 8941cb0ef41Sopenharmony_ci```js 8951cb0ef41Sopenharmony_ci// ack is a boolean indicating whether or not to set the ACK flag. 8961cb0ef41Sopenharmony_ciconst frame = new http2.SettingsFrame(ack); 8971cb0ef41Sopenharmony_ci 8981cb0ef41Sopenharmony_cisocket.write(frame.data); 8991cb0ef41Sopenharmony_ci``` 9001cb0ef41Sopenharmony_ci 9011cb0ef41Sopenharmony_ci### `http2.kFakeRequestHeaders` 9021cb0ef41Sopenharmony_ci 9031cb0ef41Sopenharmony_ciSet to a `Buffer` instance that contains a minimal set of serialized HTTP/2 9041cb0ef41Sopenharmony_cirequest headers to be used as the payload of a `http2.HeadersFrame`. 9051cb0ef41Sopenharmony_ci 9061cb0ef41Sopenharmony_ci<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 9071cb0ef41Sopenharmony_ci 9081cb0ef41Sopenharmony_ci```js 9091cb0ef41Sopenharmony_ciconst frame = new http2.HeadersFrame(1, http2.kFakeRequestHeaders, 0, true); 9101cb0ef41Sopenharmony_ci 9111cb0ef41Sopenharmony_cisocket.write(frame.data); 9121cb0ef41Sopenharmony_ci``` 9131cb0ef41Sopenharmony_ci 9141cb0ef41Sopenharmony_ci### `http2.kFakeResponseHeaders` 9151cb0ef41Sopenharmony_ci 9161cb0ef41Sopenharmony_ciSet to a `Buffer` instance that contains a minimal set of serialized HTTP/2 9171cb0ef41Sopenharmony_ciresponse headers to be used as the payload a `http2.HeadersFrame`. 9181cb0ef41Sopenharmony_ci 9191cb0ef41Sopenharmony_ci<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 9201cb0ef41Sopenharmony_ci 9211cb0ef41Sopenharmony_ci```js 9221cb0ef41Sopenharmony_ciconst frame = new http2.HeadersFrame(1, http2.kFakeResponseHeaders, 0, true); 9231cb0ef41Sopenharmony_ci 9241cb0ef41Sopenharmony_cisocket.write(frame.data); 9251cb0ef41Sopenharmony_ci``` 9261cb0ef41Sopenharmony_ci 9271cb0ef41Sopenharmony_ci### `http2.kClientMagic` 9281cb0ef41Sopenharmony_ci 9291cb0ef41Sopenharmony_ciSet to a `Buffer` containing the preamble bytes an HTTP/2 client must send 9301cb0ef41Sopenharmony_ciupon initial establishment of a connection. 9311cb0ef41Sopenharmony_ci 9321cb0ef41Sopenharmony_ci<!-- eslint-disable no-undef, node-core/require-common-first, node-core/required-modules --> 9331cb0ef41Sopenharmony_ci 9341cb0ef41Sopenharmony_ci```js 9351cb0ef41Sopenharmony_cisocket.write(http2.kClientMagic); 9361cb0ef41Sopenharmony_ci``` 9371cb0ef41Sopenharmony_ci 9381cb0ef41Sopenharmony_ci## Internet Module 9391cb0ef41Sopenharmony_ci 9401cb0ef41Sopenharmony_ciThe `common/internet` module provides utilities for working with 9411cb0ef41Sopenharmony_ciinternet-related tests. 9421cb0ef41Sopenharmony_ci 9431cb0ef41Sopenharmony_ci### `internet.addresses` 9441cb0ef41Sopenharmony_ci 9451cb0ef41Sopenharmony_ci* [\<Object>][<Object>] 9461cb0ef41Sopenharmony_ci * `INET_HOST` [\<string>][<string>] A generic host that has registered common 9471cb0ef41Sopenharmony_ci DNS records, supports both IPv4 and IPv6, and provides basic HTTP/HTTPS 9481cb0ef41Sopenharmony_ci services 9491cb0ef41Sopenharmony_ci * `INET4_HOST` [\<string>][<string>] A host that provides IPv4 services 9501cb0ef41Sopenharmony_ci * `INET6_HOST` [\<string>][<string>] A host that provides IPv6 services 9511cb0ef41Sopenharmony_ci * `INET4_IP` [\<string>][<string>] An accessible IPv4 IP, defaults to the 9521cb0ef41Sopenharmony_ci Google Public DNS IPv4 address 9531cb0ef41Sopenharmony_ci * `INET6_IP` [\<string>][<string>] An accessible IPv6 IP, defaults to the 9541cb0ef41Sopenharmony_ci Google Public DNS IPv6 address 9551cb0ef41Sopenharmony_ci * `INVALID_HOST` [\<string>][<string>] An invalid host that cannot be resolved 9561cb0ef41Sopenharmony_ci * `MX_HOST` [\<string>][<string>] A host with MX records registered 9571cb0ef41Sopenharmony_ci * `SRV_HOST` [\<string>][<string>] A host with SRV records registered 9581cb0ef41Sopenharmony_ci * `PTR_HOST` [\<string>][<string>] A host with PTR records registered 9591cb0ef41Sopenharmony_ci * `NAPTR_HOST` [\<string>][<string>] A host with NAPTR records registered 9601cb0ef41Sopenharmony_ci * `SOA_HOST` [\<string>][<string>] A host with SOA records registered 9611cb0ef41Sopenharmony_ci * `CNAME_HOST` [\<string>][<string>] A host with CNAME records registered 9621cb0ef41Sopenharmony_ci * `NS_HOST` [\<string>][<string>] A host with NS records registered 9631cb0ef41Sopenharmony_ci * `TXT_HOST` [\<string>][<string>] A host with TXT records registered 9641cb0ef41Sopenharmony_ci * `DNS4_SERVER` [\<string>][<string>] An accessible IPv4 DNS server 9651cb0ef41Sopenharmony_ci * `DNS6_SERVER` [\<string>][<string>] An accessible IPv6 DNS server 9661cb0ef41Sopenharmony_ci 9671cb0ef41Sopenharmony_ciA set of addresses for internet-related tests. All properties are configurable 9681cb0ef41Sopenharmony_civia `NODE_TEST_*` environment variables. For example, to configure 9691cb0ef41Sopenharmony_ci`internet.addresses.INET_HOST`, set the environment 9701cb0ef41Sopenharmony_civariable `NODE_TEST_INET_HOST` to a specified host. 9711cb0ef41Sopenharmony_ci 9721cb0ef41Sopenharmony_ci## ongc Module 9731cb0ef41Sopenharmony_ci 9741cb0ef41Sopenharmony_ciThe `ongc` module allows a garbage collection listener to be installed. The 9751cb0ef41Sopenharmony_cimodule exports a single `onGC()` function. 9761cb0ef41Sopenharmony_ci 9771cb0ef41Sopenharmony_ci```js 9781cb0ef41Sopenharmony_cirequire('../common'); 9791cb0ef41Sopenharmony_ciconst onGC = require('../common/ongc'); 9801cb0ef41Sopenharmony_ci 9811cb0ef41Sopenharmony_cionGC({}, { ongc() { console.log('collected'); } }); 9821cb0ef41Sopenharmony_ci``` 9831cb0ef41Sopenharmony_ci 9841cb0ef41Sopenharmony_ci### `onGC(target, listener)` 9851cb0ef41Sopenharmony_ci 9861cb0ef41Sopenharmony_ci* `target` [\<Object>][<Object>] 9871cb0ef41Sopenharmony_ci* `listener` [\<Object>][<Object>] 9881cb0ef41Sopenharmony_ci * `ongc` [\<Function>][<Function>] 9891cb0ef41Sopenharmony_ci 9901cb0ef41Sopenharmony_ciInstalls a GC listener for the collection of `target`. 9911cb0ef41Sopenharmony_ci 9921cb0ef41Sopenharmony_ciThis uses `async_hooks` for GC tracking. This means that it enables 9931cb0ef41Sopenharmony_ci`async_hooks` tracking, which may affect the test functionality. It also 9941cb0ef41Sopenharmony_cimeans that between a `global.gc()` call and the listener being invoked 9951cb0ef41Sopenharmony_cia full `setImmediate()` invocation passes. 9961cb0ef41Sopenharmony_ci 9971cb0ef41Sopenharmony_ci`listener` is an object to make it easier to use a closure; the target object 9981cb0ef41Sopenharmony_cishould not be in scope when `listener.ongc()` is created. 9991cb0ef41Sopenharmony_ci 10001cb0ef41Sopenharmony_ci## Report Module 10011cb0ef41Sopenharmony_ci 10021cb0ef41Sopenharmony_ciThe `report` module provides helper functions for testing diagnostic reporting 10031cb0ef41Sopenharmony_cifunctionality. 10041cb0ef41Sopenharmony_ci 10051cb0ef41Sopenharmony_ci### `findReports(pid, dir)` 10061cb0ef41Sopenharmony_ci 10071cb0ef41Sopenharmony_ci* `pid` [\<number>][<number>] Process ID to retrieve diagnostic report files 10081cb0ef41Sopenharmony_ci for. 10091cb0ef41Sopenharmony_ci* `dir` [\<string>][<string>] Directory to search for diagnostic report files. 10101cb0ef41Sopenharmony_ci* return [\<Array>][<Array>] 10111cb0ef41Sopenharmony_ci 10121cb0ef41Sopenharmony_ciReturns an array of diagnostic report file names found in `dir`. The files 10131cb0ef41Sopenharmony_cishould have been generated by a process whose PID matches `pid`. 10141cb0ef41Sopenharmony_ci 10151cb0ef41Sopenharmony_ci### `validate(filepath)` 10161cb0ef41Sopenharmony_ci 10171cb0ef41Sopenharmony_ci* `filepath` [\<string>][<string>] Diagnostic report filepath to validate. 10181cb0ef41Sopenharmony_ci 10191cb0ef41Sopenharmony_ciValidates the schema of a diagnostic report file whose path is specified in 10201cb0ef41Sopenharmony_ci`filepath`. If the report fails validation, an exception is thrown. 10211cb0ef41Sopenharmony_ci 10221cb0ef41Sopenharmony_ci### `validateContent(report)` 10231cb0ef41Sopenharmony_ci 10241cb0ef41Sopenharmony_ci* `report` [\<Object>][<Object>] | [\<string>][<string>] JSON contents of a 10251cb0ef41Sopenharmony_ci diagnostic report file, the parsed Object thereof, or the result of 10261cb0ef41Sopenharmony_ci `process.report.getReport()`. 10271cb0ef41Sopenharmony_ci 10281cb0ef41Sopenharmony_ciValidates the schema of a diagnostic report whose content is specified in 10291cb0ef41Sopenharmony_ci`report`. If the report fails validation, an exception is thrown. 10301cb0ef41Sopenharmony_ci 10311cb0ef41Sopenharmony_ci## tick Module 10321cb0ef41Sopenharmony_ci 10331cb0ef41Sopenharmony_ciThe `tick` module provides a helper function that can be used to call a callback 10341cb0ef41Sopenharmony_ciafter a given number of event loop "ticks". 10351cb0ef41Sopenharmony_ci 10361cb0ef41Sopenharmony_ci### `tick(x, cb)` 10371cb0ef41Sopenharmony_ci 10381cb0ef41Sopenharmony_ci* `x` [\<number>][<number>] Number of event loop "ticks". 10391cb0ef41Sopenharmony_ci* `cb` [\<Function>][<Function>] A callback function. 10401cb0ef41Sopenharmony_ci 10411cb0ef41Sopenharmony_ci## tmpdir Module 10421cb0ef41Sopenharmony_ci 10431cb0ef41Sopenharmony_ciThe `tmpdir` module supports the use of a temporary directory for testing. 10441cb0ef41Sopenharmony_ci 10451cb0ef41Sopenharmony_ci### `path` 10461cb0ef41Sopenharmony_ci 10471cb0ef41Sopenharmony_ci* [\<string>][<string>] 10481cb0ef41Sopenharmony_ci 10491cb0ef41Sopenharmony_ciThe realpath of the testing temporary directory. 10501cb0ef41Sopenharmony_ci 10511cb0ef41Sopenharmony_ci### `fileURL([...paths])` 10521cb0ef41Sopenharmony_ci 10531cb0ef41Sopenharmony_ci* `...paths` [\<string>][<string>] 10541cb0ef41Sopenharmony_ci* return [\<URL>][<URL>] 10551cb0ef41Sopenharmony_ci 10561cb0ef41Sopenharmony_ciResolves a sequence of paths into absolute url in the temporary directory. 10571cb0ef41Sopenharmony_ci 10581cb0ef41Sopenharmony_ciWhen called without arguments, returns absolute url of the testing 10591cb0ef41Sopenharmony_citemporary directory with explicit trailing `/`. 10601cb0ef41Sopenharmony_ci 10611cb0ef41Sopenharmony_ci### `refresh()` 10621cb0ef41Sopenharmony_ci 10631cb0ef41Sopenharmony_ciDeletes and recreates the testing temporary directory. 10641cb0ef41Sopenharmony_ci 10651cb0ef41Sopenharmony_ciThe first time `refresh()` runs, it adds a listener to process `'exit'` that 10661cb0ef41Sopenharmony_cicleans the temporary directory. Thus, every file under `tmpdir.path` needs to 10671cb0ef41Sopenharmony_cibe closed before the test completes. A good way to do this is to add a 10681cb0ef41Sopenharmony_cilistener to process `'beforeExit'`. If a file needs to be left open until 10691cb0ef41Sopenharmony_ciNode.js completes, use a child process and call `refresh()` only in the 10701cb0ef41Sopenharmony_ciparent. 10711cb0ef41Sopenharmony_ci 10721cb0ef41Sopenharmony_ciIt is usually only necessary to call `refresh()` once in a test file. 10731cb0ef41Sopenharmony_ciAvoid calling it more than once in an asynchronous context as one call 10741cb0ef41Sopenharmony_cimight refresh the temporary directory of a different context, causing 10751cb0ef41Sopenharmony_cithe test to fail somewhat mysteriously. 10761cb0ef41Sopenharmony_ci 10771cb0ef41Sopenharmony_ci### `resolve([...paths])` 10781cb0ef41Sopenharmony_ci 10791cb0ef41Sopenharmony_ci* `...paths` [\<string>][<string>] 10801cb0ef41Sopenharmony_ci* return [\<string>][<string>] 10811cb0ef41Sopenharmony_ci 10821cb0ef41Sopenharmony_ciResolves a sequence of paths into absolute path in the temporary directory. 10831cb0ef41Sopenharmony_ci 10841cb0ef41Sopenharmony_ci### `hasEnoughSpace(size)` 10851cb0ef41Sopenharmony_ci 10861cb0ef41Sopenharmony_ci* `size` [\<number>][<number>] Required size, in bytes. 10871cb0ef41Sopenharmony_ci 10881cb0ef41Sopenharmony_ciReturns `true` if the available blocks of the file system underlying `path` 10891cb0ef41Sopenharmony_ciare likely sufficient to hold a single file of `size` bytes. This is useful for 10901cb0ef41Sopenharmony_ciskipping tests that require hundreds of megabytes or even gigabytes of temporary 10911cb0ef41Sopenharmony_cifiles, but it is inaccurate and susceptible to race conditions. 10921cb0ef41Sopenharmony_ci 10931cb0ef41Sopenharmony_ci## UDP pair helper 10941cb0ef41Sopenharmony_ci 10951cb0ef41Sopenharmony_ciThe `common/udppair` module exports a function `makeUDPPair` and a class 10961cb0ef41Sopenharmony_ci`FakeUDPWrap`. 10971cb0ef41Sopenharmony_ci 10981cb0ef41Sopenharmony_ci`FakeUDPWrap` emits `'send'` events when data is to be sent on it, and provides 10991cb0ef41Sopenharmony_cian `emitReceived()` API for actin as if data has been received on it. 11001cb0ef41Sopenharmony_ci 11011cb0ef41Sopenharmony_ci`makeUDPPair` returns an object `{ clientSide, serverSide }` where each side 11021cb0ef41Sopenharmony_ciis an `FakeUDPWrap` connected to the other side. 11031cb0ef41Sopenharmony_ci 11041cb0ef41Sopenharmony_ciThere is no difference between client or server side beyond their names. 11051cb0ef41Sopenharmony_ci 11061cb0ef41Sopenharmony_ci## WPT Module 11071cb0ef41Sopenharmony_ci 11081cb0ef41Sopenharmony_ci### `harness` 11091cb0ef41Sopenharmony_ci 11101cb0ef41Sopenharmony_ciA legacy port of [Web Platform Tests][] harness. 11111cb0ef41Sopenharmony_ci 11121cb0ef41Sopenharmony_ciSee the source code for definitions. Please avoid using it in new 11131cb0ef41Sopenharmony_cicode - the current usage of this port in tests is being migrated to 11141cb0ef41Sopenharmony_cithe original WPT harness, see [the WPT tests README][]. 11151cb0ef41Sopenharmony_ci 11161cb0ef41Sopenharmony_ci### Class: WPTRunner 11171cb0ef41Sopenharmony_ci 11181cb0ef41Sopenharmony_ciA driver class for running WPT with the WPT harness in a worker thread. 11191cb0ef41Sopenharmony_ci 11201cb0ef41Sopenharmony_ciSee [the WPT tests README][] for details. 11211cb0ef41Sopenharmony_ci 11221cb0ef41Sopenharmony_ci[<Array>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array 11231cb0ef41Sopenharmony_ci[<ArrayBufferView>]: https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView 11241cb0ef41Sopenharmony_ci[<Buffer>]: https://nodejs.org/api/buffer.html#buffer_class_buffer 11251cb0ef41Sopenharmony_ci[<BufferSource>]: https://developer.mozilla.org/en-US/docs/Web/API/BufferSource 11261cb0ef41Sopenharmony_ci[<ChildProcess>]: ../../doc/api/child_process.md#class-childprocess 11271cb0ef41Sopenharmony_ci[<Error>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error 11281cb0ef41Sopenharmony_ci[<Function>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function 11291cb0ef41Sopenharmony_ci[<Object>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object 11301cb0ef41Sopenharmony_ci[<RegExp>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp 11311cb0ef41Sopenharmony_ci[<URL>]: https://developer.mozilla.org/en-US/docs/Web/API/URL 11321cb0ef41Sopenharmony_ci[<any>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types 11331cb0ef41Sopenharmony_ci[<bigint>]: https://github.com/tc39/proposal-bigint 11341cb0ef41Sopenharmony_ci[<boolean>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type 11351cb0ef41Sopenharmony_ci[<number>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type 11361cb0ef41Sopenharmony_ci[<string>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type 11371cb0ef41Sopenharmony_ci[Web Platform Tests]: https://github.com/web-platform-tests/wpt 11381cb0ef41Sopenharmony_ci[`hijackstdio.hijackStdErr()`]: #hijackstderrlistener 11391cb0ef41Sopenharmony_ci[`hijackstdio.hijackStdOut()`]: #hijackstdoutlistener 11401cb0ef41Sopenharmony_ci[internationalization]: ../../doc/api/intl.md 11411cb0ef41Sopenharmony_ci[the WPT tests README]: ../wpt/README.md 1142