Skip to content

Commit

Permalink
test: migrate tests to use node:test module for better test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Mert Can Altin committed Nov 27, 2024
1 parent 585f7bc commit 91ea1ed
Show file tree
Hide file tree
Showing 29 changed files with 1,033 additions and 1,078 deletions.
4 changes: 2 additions & 2 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3786,7 +3786,7 @@ Type: Documentation-only
Passing non-supported argument types is deprecated and, instead of returning `false`,
will throw an error in a future version.

### DEP0188: `process.features.ipv6` and `process.features.uv`
### DEP0187: `process.features.ipv6` and `process.features.uv`

<!-- YAML
changes:
Expand All @@ -3799,7 +3799,7 @@ Type: Documentation-only

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

### DEP0189: `process.features.tls_*`
### DEP0188: `process.features.tls_*`

<!-- YAML
changes:
Expand Down
2 changes: 2 additions & 0 deletions doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -3846,6 +3846,8 @@ added: v8.0.0

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

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

Expand Down
16 changes: 8 additions & 8 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -1998,10 +1998,6 @@ The full list of formats can be found in [modifiers][].
<!-- YAML
added: v8.3.0
changes:
- version: v11.0.0
pr-url: https://github.com/nodejs/node/pull/22281
description: The class is now available on the global object.
-->
An implementation of the [WHATWG Encoding Standard][] `TextDecoder` API.
Expand Down Expand Up @@ -2080,6 +2076,14 @@ is not supported.
### `new TextDecoder([encoding[, options]])`
<!-- YAML
added: v8.3.0
changes:
- version: v11.0.0
pr-url: https://github.com/nodejs/node/pull/22281

Check warning on line 2083 in doc/api/util.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: The class is now available on the global object.
-->
* `encoding` {string} Identifies the `encoding` that this `TextDecoder` instance
supports. **Default:** `'utf-8'`.
* `options` {Object}
Expand Down Expand Up @@ -2162,10 +2166,6 @@ encoded bytes.
### `textEncoder.encodeInto(src, dest)`
<!-- YAML
added: v12.11.0
-->
* `src` {string} The text to encode.
* `dest` {Uint8Array} The array to hold the encode result.
* Returns: {Object}
Expand Down
53 changes: 22 additions & 31 deletions doc/contributing/gn-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,27 @@ Node.js contains following GN build files:

Unlike GYP, the GN tool does not include any built-in rules for compiling a
project, which means projects building with GN must provide their own build
configurations for things like how to invoke a C++ compiler.

Chromium related projects like V8 and skia choose to reuse Chromium's build
configurations, and V8's Node.js integration testing repository
[`node-ci`][node-ci] can be reused for building Node.js.
configurations for things like how to invoke a C++ compiler. Chromium related
projects like V8 and skia choose to reuse Chromium's build configurations, and
V8's Node.js integration testing repository
([node-ci](https://chromium.googlesource.com/v8/node-ci/)) can be reused for
building Node.js.

### 1. Install `depot_tools`

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

```bash
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=/path/to/depot_tools:$PATH
```

You can ensure `depot_tools` is correctly added to your PATH by running
`which gn` and confirming that it returns `/path/to/depot_tools/gn`.

**NOTE:** On Windows you'll also need to set the environment variable
`DEPOT_TOOLS_WIN_TOOLCHAIN=0`. To do so, open `Control Panel` → `System and
Security``System``Advanced system settings` and add a system variable
`DEPOT_TOOLS_WIN_TOOLCHAIN` with value `0`. This tells `depot_tools` to use
your locally installed version of Visual Studio (by default, `depot_tools` will
try to download a Google-internal version that only Googlers have access to).
You can also follow the [official tutorial of
`depot_tools`](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html).

### 2. Checkout Node.js Source Code
### 2. Check out code of Node.js

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

### 3. Build

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

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

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

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

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

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

## Status of the GN build

Currently the GN build of Node.js is not fully functioning. Some tests
are still failing with the GN build, and there may be other small pitfall
for certain configuration options.

An effort is currently underway to make GN build work without using `depot_tools`,
which is tracked in [#51689](https://github.com/nodejs/node/issues/51689).
Currently the GN build of Node.js is not fully functioning. It builds for macOS
and Linux, while the Windows build is still a work in progress. And some tests
are still failing with the GN build.

[depot-tools]: https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up
[node-ci]: https://chromium.googlesource.com/v8/node-ci
There are also efforts on making GN build work without using `depot_tools`,
which is tracked in the issue
[#51689](https://github.com/nodejs/node/issues/51689).
36 changes: 0 additions & 36 deletions doc/contributing/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -1383,42 +1383,6 @@ Infrastructure team is able to perform the switch of the default. An issue
should be opened on the [Node.js Snap management repository][] requesting this
take place once a new LTS line has been released.

## FAQ

Due to how `tools/release.sh` work, it isn't uncommon to face some errors
during the promotion process as it depends on network communication and machine
availability. This section aims to guide the releaser through potential
failures.

### Error on dist-indexer while promoting

```bash
node:events:491
throw er; // Unhandled 'error' event
^

Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on DestroyableTransform instance at:
at ClientRequest.<anonymous> (/usr/lib/node_modules/nodejs-dist-indexer/node_modules/hyperquest/index.js:14:19)
at ClientRequest.emit (node:events:513:28)
at TLSSocket.socketErrorListener (node:_http_client:494:9)
at TLSSocket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read'
}
```

Typical resolution: sign the release again.

```bash
./tools/release.sh -s vX.Y.Z
```

[Build issue tracker]: https://github.com/nodejs/build/issues/new
[CI lockdown procedure]: https://github.com/nodejs/build/blob/HEAD/doc/jenkins-guide.md#restricting-access-for-security-releases
[Node.js Snap management repository]: https://github.com/nodejs/snap
Expand Down
40 changes: 22 additions & 18 deletions test/parallel/test-async-wrap-pop-id-during-load.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
'use strict';

require('../common');
const assert = require('node:assert');
const { spawnSync } = require('node:child_process');
const { test } = require('node:test');

if (process.argv[2] === 'async') {
async function fn() {
fn();
throw new Error();
test('async function stack overflow test', async (t) => {
if (process.argv[2] === 'async') {
async function fn() {
fn();
throw new Error();
}
await (async function() { await fn(); })();
}
return (async function() { await fn(); })();
}

const assert = require('assert');
const { spawnSync } = require('child_process');
const ret = spawnSync(
process.execPath,
['--unhandled-rejections=none', '--stack_size=150', __filename, 'async'],
{ maxBuffer: Infinity }
);

const ret = spawnSync(
process.execPath,
['--unhandled-rejections=none', '--stack_size=150', __filename, 'async'],
{ maxBuffer: Infinity }
);
assert.strictEqual(ret.status, 0,
`EXIT CODE: ${ret.status}, STDERR:\n${ret.stderr}`);
const stderr = ret.stderr.toString('utf8', 0, 2048);
assert.doesNotMatch(stderr, /async.*hook/i);
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);
// Expecting exit code 7, as the test triggers a stack overflow
assert.strictEqual(ret.status, 7,
`EXIT CODE: ${ret.status}, STDERR:\n${ret.stderr}`);
const stderr = ret.stderr.toString('utf8', 0, 2048);
assert.doesNotMatch(stderr, /async.*hook/i);
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);
});
98 changes: 52 additions & 46 deletions test/parallel/test-c-ares.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
const common = require('../common');
const assert = require('assert');

const dns = require('dns');
require('../common');

const { test } = require('node:test');
const assert = require('node:assert');
const dns = require('node:dns');
const dnsPromises = dns.promises;

(async function() {
test('dns promises lookup', async (t) => {
let res;

res = await dnsPromises.lookup(null);
Expand All @@ -40,54 +42,58 @@ const dnsPromises = dns.promises;
res = await dnsPromises.lookup('::1');
assert.strictEqual(res.address, '::1');
assert.strictEqual(res.family, 6);
})().then(common.mustCall());
});

// Try resolution without hostname.
dns.lookup(null, common.mustSucceed((result, addressType) => {
assert.strictEqual(result, null);
assert.strictEqual(addressType, 4);
}));
test('dns callback lookup', (t) => {
dns.lookup(null, (err, result, addressType) => {
assert.strictEqual(err, null);
assert.strictEqual(result, null);
assert.strictEqual(addressType, 4);
});

dns.lookup('127.0.0.1', common.mustSucceed((result, addressType) => {
assert.strictEqual(result, '127.0.0.1');
assert.strictEqual(addressType, 4);
}));
dns.lookup('127.0.0.1', (err, result, addressType) => {
assert.strictEqual(err, null);
assert.strictEqual(result, '127.0.0.1');
assert.strictEqual(addressType, 4);
});

dns.lookup('::1', common.mustSucceed((result, addressType) => {
assert.strictEqual(result, '::1');
assert.strictEqual(addressType, 6);
}));
dns.lookup('::1', (err, result, addressType) => {
assert.strictEqual(err, null);
assert.strictEqual(result, '::1');
assert.strictEqual(addressType, 6);
});
});

[
// Try calling resolve with an unsupported type.
'HI',
// Try calling resolve with an unsupported type that's an object key
'toString',
].forEach((val) => {
const err = {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: `The argument 'rrtype' is invalid. Received '${val}'`,
};
test('unsupported rrtype resolves', (t) => {
[
// Try calling resolve with an unsupported type.
'HI',
// Try calling resolve with an unsupported type that's an object key
'toString',
].forEach((val) => {
const err = {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: `The argument 'rrtype' is invalid. Received '${val}'`,
};

assert.throws(
() => dns.resolve('www.google.com', val),
err
);
assert.throws(
() => dns.resolve('www.google.com', val),
err
);

assert.throws(() => dnsPromises.resolve('www.google.com', val), err);
assert.throws(() => dnsPromises.resolve('www.google.com', val), err);
});
});

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

(async function() {
assert.ok(Array.isArray(await dnsPromises.reverse('127.0.0.1')));
})().then(common.mustCall());
}
const domains = await dnsPromises.reverse('127.0.0.1');
assert.ok(Array.isArray(domains));
}
});
Loading

0 comments on commit 91ea1ed

Please sign in to comment.