Skip to content

Commit 91ea1ed

Browse files
author
Mert Can Altin
committed
test: migrate tests to use node:test module for better test structure
1 parent 585f7bc commit 91ea1ed

29 files changed

+1033
-1078
lines changed

doc/api/deprecations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,7 +3786,7 @@ Type: Documentation-only
37863786
Passing non-supported argument types is deprecated and, instead of returning `false`,
37873787
will throw an error in a future version.
37883788

3789-
### DEP0188: `process.features.ipv6` and `process.features.uv`
3789+
### DEP0187: `process.features.ipv6` and `process.features.uv`
37903790

37913791
<!-- YAML
37923792
changes:
@@ -3799,7 +3799,7 @@ Type: Documentation-only
37993799

38003800
These properties are unconditionally `true`. Any checks based on these properties are redundant.
38013801

3802-
### DEP0189: `process.features.tls_*`
3802+
### DEP0188: `process.features.tls_*`
38033803

38043804
<!-- YAML
38053805
changes:

doc/api/stream.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,6 +3846,8 @@ added: v8.0.0
38463846

38473847
The `_destroy()` method is called by [`writable.destroy()`][writable-destroy].
38483848
It can be overridden by child classes but it **must not** be called directly.
3849+
Furthermore, the `callback` should not be mixed with async/await
3850+
once it is executed when a promise is resolved.
38493851

38503852
#### `writable._final(callback)`
38513853

doc/api/util.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,10 +1998,6 @@ The full list of formats can be found in [modifiers][].
19981998
19991999
<!-- YAML
20002000
added: v8.3.0
2001-
changes:
2002-
- version: v11.0.0
2003-
pr-url: https://github.com/nodejs/node/pull/22281
2004-
description: The class is now available on the global object.
20052001
-->
20062002
20072003
An implementation of the [WHATWG Encoding Standard][] `TextDecoder` API.
@@ -2080,6 +2076,14 @@ is not supported.
20802076
20812077
### `new TextDecoder([encoding[, options]])`
20822078
2079+
<!-- YAML
2080+
added: v8.3.0
2081+
changes:
2082+
- version: v11.0.0
2083+
pr-url: https://github.com/nodejs/node/pull/22281
2084+
description: The class is now available on the global object.
2085+
-->
2086+
20832087
* `encoding` {string} Identifies the `encoding` that this `TextDecoder` instance
20842088
supports. **Default:** `'utf-8'`.
20852089
* `options` {Object}
@@ -2162,10 +2166,6 @@ encoded bytes.
21622166
21632167
### `textEncoder.encodeInto(src, dest)`
21642168
2165-
<!-- YAML
2166-
added: v12.11.0
2167-
-->
2168-
21692169
* `src` {string} The text to encode.
21702170
* `dest` {Uint8Array} The array to hold the encode result.
21712171
* Returns: {Object}

doc/contributing/gn-build.md

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,27 @@ Node.js contains following GN build files:
2828

2929
Unlike GYP, the GN tool does not include any built-in rules for compiling a
3030
project, which means projects building with GN must provide their own build
31-
configurations for things like how to invoke a C++ compiler.
32-
33-
Chromium related projects like V8 and skia choose to reuse Chromium's build
34-
configurations, and V8's Node.js integration testing repository
35-
[`node-ci`][node-ci] can be reused for building Node.js.
31+
configurations for things like how to invoke a C++ compiler. Chromium related
32+
projects like V8 and skia choose to reuse Chromium's build configurations, and
33+
V8's Node.js integration testing repository
34+
([node-ci](https://chromium.googlesource.com/v8/node-ci/)) can be reused for
35+
building Node.js.
3636

3737
### 1. Install `depot_tools`
3838

39-
You'll need to install [`depot_tools`][depot-tools] the toolset
40-
used for fetching Chromium and its dependencies.
39+
The `depot_tools` is a set of tools used by Chromium related projects for
40+
checking out code and managing dependencies, and since this guide is reusing the
41+
infra of V8, it needs to be installed and added to `PATH`:
4142

4243
```bash
4344
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
4445
export PATH=/path/to/depot_tools:$PATH
4546
```
4647

47-
You can ensure `depot_tools` is correctly added to your PATH by running
48-
`which gn` and confirming that it returns `/path/to/depot_tools/gn`.
49-
50-
**NOTE:** On Windows you'll also need to set the environment variable
51-
`DEPOT_TOOLS_WIN_TOOLCHAIN=0`. To do so, open `Control Panel` → `System and
52-
Security``System``Advanced system settings` and add a system variable
53-
`DEPOT_TOOLS_WIN_TOOLCHAIN` with value `0`. This tells `depot_tools` to use
54-
your locally installed version of Visual Studio (by default, `depot_tools` will
55-
try to download a Google-internal version that only Googlers have access to).
48+
You can also follow the [official tutorial of
49+
`depot_tools`](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html).
5650

57-
### 2. Checkout Node.js Source Code
51+
### 2. Check out code of Node.js
5852

5953
To check out the latest main branch of Node.js for building, use the `fetch`
6054
tool from `depot_tools`:
@@ -97,9 +91,9 @@ out at `node_gn/node/node`.
9791

9892
### 3. Build
9993

100-
GN only supports [`ninja`](https://ninja-build.org) for building. To build
101-
Node.js with GN you'll first need to generate `ninja` build files and then invoke
102-
`ninja` to perform the build.
94+
GN only supports [`ninja`](https://ninja-build.org) for building, so to build
95+
Node.js with GN, `ninja` build files should be generated first, and then
96+
`ninja` can be invoked to do the building.
10397

10498
The `node-ci` repository provides a script for calling GN:
10599

@@ -109,10 +103,9 @@ cd node # Enter `node_gn/node` which contains a node-ci checkout
109103
```
110104

111105
which writes `ninja` build files into the `out/Release` directory under
112-
`node_gn/node`. To see all possible configurable options, run
113-
`tools/gn-gen.py --help`.
106+
`node_gn/node`.
114107

115-
When `gn-gen.py` has executed successfully, you can then execute `ninja`:
108+
And then you can execute `ninja`:
116109

117110
```bash
118111
ninja -C out/Release node
@@ -123,12 +116,10 @@ After the build is completed, the compiled Node.js executable can be found in
123116

124117
## Status of the GN build
125118

126-
Currently the GN build of Node.js is not fully functioning. Some tests
127-
are still failing with the GN build, and there may be other small pitfall
128-
for certain configuration options.
129-
130-
An effort is currently underway to make GN build work without using `depot_tools`,
131-
which is tracked in [#51689](https://github.com/nodejs/node/issues/51689).
119+
Currently the GN build of Node.js is not fully functioning. It builds for macOS
120+
and Linux, while the Windows build is still a work in progress. And some tests
121+
are still failing with the GN build.
132122

133-
[depot-tools]: https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up
134-
[node-ci]: https://chromium.googlesource.com/v8/node-ci
123+
There are also efforts on making GN build work without using `depot_tools`,
124+
which is tracked in the issue
125+
[#51689](https://github.com/nodejs/node/issues/51689).

doc/contributing/releases.md

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,42 +1383,6 @@ Infrastructure team is able to perform the switch of the default. An issue
13831383
should be opened on the [Node.js Snap management repository][] requesting this
13841384
take place once a new LTS line has been released.
13851385

1386-
## FAQ
1387-
1388-
Due to how `tools/release.sh` work, it isn't uncommon to face some errors
1389-
during the promotion process as it depends on network communication and machine
1390-
availability. This section aims to guide the releaser through potential
1391-
failures.
1392-
1393-
### Error on dist-indexer while promoting
1394-
1395-
```bash
1396-
node:events:491
1397-
throw er; // Unhandled 'error' event
1398-
^
1399-
1400-
Error: read ECONNRESET
1401-
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
1402-
Emitted 'error' event on DestroyableTransform instance at:
1403-
at ClientRequest.<anonymous> (/usr/lib/node_modules/nodejs-dist-indexer/node_modules/hyperquest/index.js:14:19)
1404-
at ClientRequest.emit (node:events:513:28)
1405-
at TLSSocket.socketErrorListener (node:_http_client:494:9)
1406-
at TLSSocket.emit (node:events:513:28)
1407-
at emitErrorNT (node:internal/streams/destroy:157:8)
1408-
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
1409-
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
1410-
errno: -104,
1411-
code: 'ECONNRESET',
1412-
syscall: 'read'
1413-
}
1414-
```
1415-
1416-
Typical resolution: sign the release again.
1417-
1418-
```bash
1419-
./tools/release.sh -s vX.Y.Z
1420-
```
1421-
14221386
[Build issue tracker]: https://github.com/nodejs/build/issues/new
14231387
[CI lockdown procedure]: https://github.com/nodejs/build/blob/HEAD/doc/jenkins-guide.md#restricting-access-for-security-releases
14241388
[Node.js Snap management repository]: https://github.com/nodejs/snap
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
'use strict';
22

33
require('../common');
4+
const assert = require('node:assert');
5+
const { spawnSync } = require('node:child_process');
6+
const { test } = require('node:test');
47

5-
if (process.argv[2] === 'async') {
6-
async function fn() {
7-
fn();
8-
throw new Error();
8+
test('async function stack overflow test', async (t) => {
9+
if (process.argv[2] === 'async') {
10+
async function fn() {
11+
fn();
12+
throw new Error();
13+
}
14+
await (async function() { await fn(); })();
915
}
10-
return (async function() { await fn(); })();
11-
}
1216

13-
const assert = require('assert');
14-
const { spawnSync } = require('child_process');
17+
const ret = spawnSync(
18+
process.execPath,
19+
['--unhandled-rejections=none', '--stack_size=150', __filename, 'async'],
20+
{ maxBuffer: Infinity }
21+
);
1522

16-
const ret = spawnSync(
17-
process.execPath,
18-
['--unhandled-rejections=none', '--stack_size=150', __filename, 'async'],
19-
{ maxBuffer: Infinity }
20-
);
21-
assert.strictEqual(ret.status, 0,
22-
`EXIT CODE: ${ret.status}, STDERR:\n${ret.stderr}`);
23-
const stderr = ret.stderr.toString('utf8', 0, 2048);
24-
assert.doesNotMatch(stderr, /async.*hook/i);
25-
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);
23+
// Expecting exit code 7, as the test triggers a stack overflow
24+
assert.strictEqual(ret.status, 7,
25+
`EXIT CODE: ${ret.status}, STDERR:\n${ret.stderr}`);
26+
const stderr = ret.stderr.toString('utf8', 0, 2048);
27+
assert.doesNotMatch(stderr, /async.*hook/i);
28+
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);
29+
});

test/parallel/test-c-ares.js

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
const common = require('../common');
24-
const assert = require('assert');
2523

26-
const dns = require('dns');
24+
require('../common');
25+
26+
const { test } = require('node:test');
27+
const assert = require('node:assert');
28+
const dns = require('node:dns');
2729
const dnsPromises = dns.promises;
2830

29-
(async function() {
31+
test('dns promises lookup', async (t) => {
3032
let res;
3133

3234
res = await dnsPromises.lookup(null);
@@ -40,54 +42,58 @@ const dnsPromises = dns.promises;
4042
res = await dnsPromises.lookup('::1');
4143
assert.strictEqual(res.address, '::1');
4244
assert.strictEqual(res.family, 6);
43-
})().then(common.mustCall());
45+
});
4446

45-
// Try resolution without hostname.
46-
dns.lookup(null, common.mustSucceed((result, addressType) => {
47-
assert.strictEqual(result, null);
48-
assert.strictEqual(addressType, 4);
49-
}));
47+
test('dns callback lookup', (t) => {
48+
dns.lookup(null, (err, result, addressType) => {
49+
assert.strictEqual(err, null);
50+
assert.strictEqual(result, null);
51+
assert.strictEqual(addressType, 4);
52+
});
5053

51-
dns.lookup('127.0.0.1', common.mustSucceed((result, addressType) => {
52-
assert.strictEqual(result, '127.0.0.1');
53-
assert.strictEqual(addressType, 4);
54-
}));
54+
dns.lookup('127.0.0.1', (err, result, addressType) => {
55+
assert.strictEqual(err, null);
56+
assert.strictEqual(result, '127.0.0.1');
57+
assert.strictEqual(addressType, 4);
58+
});
5559

56-
dns.lookup('::1', common.mustSucceed((result, addressType) => {
57-
assert.strictEqual(result, '::1');
58-
assert.strictEqual(addressType, 6);
59-
}));
60+
dns.lookup('::1', (err, result, addressType) => {
61+
assert.strictEqual(err, null);
62+
assert.strictEqual(result, '::1');
63+
assert.strictEqual(addressType, 6);
64+
});
65+
});
6066

61-
[
62-
// Try calling resolve with an unsupported type.
63-
'HI',
64-
// Try calling resolve with an unsupported type that's an object key
65-
'toString',
66-
].forEach((val) => {
67-
const err = {
68-
code: 'ERR_INVALID_ARG_VALUE',
69-
name: 'TypeError',
70-
message: `The argument 'rrtype' is invalid. Received '${val}'`,
71-
};
67+
test('unsupported rrtype resolves', (t) => {
68+
[
69+
// Try calling resolve with an unsupported type.
70+
'HI',
71+
// Try calling resolve with an unsupported type that's an object key
72+
'toString',
73+
].forEach((val) => {
74+
const err = {
75+
code: 'ERR_INVALID_ARG_VALUE',
76+
name: 'TypeError',
77+
message: `The argument 'rrtype' is invalid. Received '${val}'`,
78+
};
7279

73-
assert.throws(
74-
() => dns.resolve('www.google.com', val),
75-
err
76-
);
80+
assert.throws(
81+
() => dns.resolve('www.google.com', val),
82+
err
83+
);
7784

78-
assert.throws(() => dnsPromises.resolve('www.google.com', val), err);
85+
assert.throws(() => dnsPromises.resolve('www.google.com', val), err);
86+
});
7987
});
8088

81-
// Windows doesn't usually have an entry for localhost 127.0.0.1 in
82-
// C:\Windows\System32\drivers\etc\hosts
83-
// so we disable this test on Windows.
84-
// IBMi reports `ENOTFOUND` when get hostname by address 127.0.0.1
85-
if (!common.isWindows && !common.isIBMi) {
86-
dns.reverse('127.0.0.1', common.mustSucceed((domains) => {
87-
assert.ok(Array.isArray(domains));
88-
}));
89+
test('reverse DNS lookup (non-Windows, non-IBMi)', async (t) => {
90+
if (!process.platform.startsWith('win') && process.platform !== 'aix') {
91+
dns.reverse('127.0.0.1', (err, domains) => {
92+
assert.strictEqual(err, null);
93+
assert.ok(Array.isArray(domains));
94+
});
8995

90-
(async function() {
91-
assert.ok(Array.isArray(await dnsPromises.reverse('127.0.0.1')));
92-
})().then(common.mustCall());
93-
}
96+
const domains = await dnsPromises.reverse('127.0.0.1');
97+
assert.ok(Array.isArray(domains));
98+
}
99+
});

0 commit comments

Comments
 (0)