Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3207,6 +3207,7 @@ pub fn copy_dir_recursive(src: &std::path::Path, dst: &std::path::Path) -> anyho
/// - `/home/node/test/common/` — common shims
/// - `/tmp/` — for tmpdir shim
/// - `/home/node/test/fixtures/` — fixture data files (recursively copied)
/// - `/home/node/test/sqlite/` — vendored sqlite test helpers, when present
pub fn setup_node_compat_test_files(temp: &Utf8Path, test_rel_path: &str) -> anyhow::Result<()> {
// Parse the suite name from the relative path (e.g., "parallel/test-foo.js" → "parallel")
let suite = test_rel_path.split('/').next().unwrap_or("parallel");
Expand Down Expand Up @@ -3310,6 +3311,12 @@ pub fn setup_node_compat_test_files(temp: &Utf8Path, test_rel_path: &str) -> any
copy_dir_recursive(vendored_fixtures_src, fixtures_dst.as_std_path())?;
}

// Shared sqlite test helpers, such as `require('../sqlite/next-db.js')`
let vendored_sqlite_src = std::path::Path::new("tests/node_compat/suite/sqlite");
if vendored_sqlite_src.exists() {
copy_dir_recursive(vendored_sqlite_src, test_root.join("sqlite").as_std_path())?;
}

Ok(())
}

Expand Down
8 changes: 7 additions & 1 deletion tests/node_compat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tests/node_compat/
│ ├── es-module/ # ~190 test files from test/es-module/
│ ├── common/ # Node.js test/common/ infrastructure
│ ├── fixtures/ # Node.js test/fixtures/ data files
│ ├── sqlite/ # Node.js test/sqlite/ helpers (next-db.js in newer releases)
│ └── NODE_VERSION # Version string (e.g., "22.14.0")
├── common-shim/ # Our WASM-compatible shim for test/common
│ └── index.js
Expand All @@ -34,7 +35,7 @@ To fetch (or update) the vendored test suite:
```

This sparse-checkouts `test/parallel/`, `test/sequential/`, `test/es-module/`,
`test/common/`, and `test/fixtures/` from the Node.js repository at the
`test/common/`, `test/fixtures/`, and `test/sqlite/` from the Node.js repository at the
specified tag. The `suite/` directory is gitignored — each
developer runs the vendor script to populate it.

Expand Down Expand Up @@ -84,6 +85,11 @@ WASM-appropriate stubs. Key differences:
- `mustCall()` / `mustCallAtLeast()` are pass-through (no `process.on('exit')`)
- `canCreateSymLink()` returns false
- Network/process-related helpers are stubbed or throw
- `common.skip()` counts as a pass, so capability flags added by newer
`test/common` releases (`hasSQLite`, `hasInspector`, `hasFFI`, `hasFIPS()` and
others) report what the component actually provides; `hasSQLite` probes
`node:sqlite` instead of reading `process.versions.sqlite`. A guard must not
skip a test whose module is available.

## How Tests Run

Expand Down
6 changes: 6 additions & 0 deletions tests/node_compat/common-shim/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ module.exports = {
sec1Exp: sec1Exp,
sec1EncExp: sec1EncExp,
hasOpenSSL: hasOpenSSL,
// Upstream: crypto.getFips() === 1 && hasOpenSSL(major, minor, patch).
hasFIPS: function(major, minor, patch) {
return typeof crypto.getFips === 'function' && crypto.getFips() === 1 &&
hasOpenSSL(major, minor, patch);
},
isBoringSSL: Boolean(process.features && process.features.openssl_is_boringssl),
get hasOpenSSL3() {
return false;
},
Expand Down
90 changes: 90 additions & 0 deletions tests/node_compat/common-shim/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,79 @@ var common = {
// Inside directory with unusual characters
get isInsideDirWithUnusualChars() { return false; },

// Helpers that upstream test/common added after 22.14.0. common.skip() counts as a pass, so
// each capability flag reports what this component actually provides rather than build
// metadata it does not set, and never skips a test whose module is available.
hasInspector: Boolean(process.features && process.features.inspector),
get hasSQLite() { return hasSQLite(); },
hasFFI: false,
hasPerfetto: false,
hasDtls: false,
get hasLocalStorage() {
var desc = Object.getOwnPropertyDescriptor(globalThis, 'localStorage');
return hasSQLite() && desc !== undefined && desc.enumerable === true;
},
hasTemporal: typeof globalThis.Temporal !== 'undefined',
get hasFullICU() {
try {
return new Intl.DateTimeFormat('es', { month: 'long' }).format(new Date(9e8)) === 'enero';
} catch (_) {
return false;
}
},
hasV8Sandbox: false,
isRiscv64: process.arch === 'riscv64',
usesSharedLibrary: false,
skipIfSQLiteMissing: function() {
if (!hasSQLite()) {
common.skip('missing SQLite');
}
},
skipIfFFIMissing: function() {
common.skip('missing FFI');
},
skipIfPerfettoEnabled: noop,
skipIfPerfettoDisabled: function() {
common.skip('Perfetto is disabled');
},
expectRequireStack: function(output, expected) {
var assert = require('assert');
var lines = output.replace(/\r/g, '').split('\n');
var start = lines.indexOf('Require stack:');
if (start === -1) {
assert.deepStrictEqual([], expected);
return;
}
var stack = [];
for (var i = start + 1; i < lines.length && lines[i].startsWith('- '); i++) {
stack.push(lines[i].slice(2));
}
assert.deepStrictEqual(stack, expected);
},
expectRequiredTLAError: function(err, stack) {
var assert = require('assert');
var message = /require\(\) cannot be used on an ESM graph with top-level await/;
if (typeof err === 'string') {
assert.match(err, /ERR_REQUIRE_ASYNC_MODULE/);
assert.match(err, message);
if (stack) {
common.expectRequireStack(err, stack);
}
} else {
assert.strictEqual(err.code, 'ERR_REQUIRE_ASYNC_MODULE');
assert.match(err.message, message);
if (stack) {
assert.deepStrictEqual(err.requireStack, stack);
}
}
},
sleepSync: function(ms) {
var end = Date.now() + ms;
while (Date.now() < end) {
// Busy-wait: upstream uses Atomics.wait, but QuickJS is built without Atomics for WASI.
}
},

// mustCall verification
_checkMustCalls: function() {
var errors = [];
Expand Down Expand Up @@ -811,6 +884,23 @@ var common = {
},
};

// Upstream derives hasSQLite from process.versions.sqlite. Probe node:sqlite instead: a build
// without the sqlite feature still loads the module, but its constructor throws. Node 26 renamed
// DatabaseSync to Database and keeps DatabaseSync as a deprecated alias.
var _hasSQLite;
function hasSQLite() {
if (_hasSQLite === undefined) {
try {
var sqlite = require('node:sqlite');
new (sqlite.Database || sqlite.DatabaseSync)(':memory:').close();
_hasSQLite = true;
} catch (_) {
_hasSQLite = false;
}
}
return _hasSQLite;
}

function applyNetFlagsAndDefaults() {
var net;
try {
Expand Down
22 changes: 22 additions & 0 deletions tests/node_compat/common-shim/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ const {
hasIPv6,
hasMultiLocalhost,
hasQuic,
hasInspector,
hasSQLite,
hasFFI,
hasDtls,
hasLocalStorage,
hasTemporal,
hasV8Sandbox,
isRiscv64,
skipIfSQLiteMissing,
skipIfPerfettoEnabled,
sleepSync,
localhostIPv4,
buildType,
mustCall,
Expand Down Expand Up @@ -75,6 +86,17 @@ export {
hasIPv6,
hasMultiLocalhost,
hasQuic,
hasInspector,
hasSQLite,
hasFFI,
hasDtls,
hasLocalStorage,
hasTemporal,
hasV8Sandbox,
isRiscv64,
skipIfSQLiteMissing,
skipIfPerfettoEnabled,
sleepSync,
localhostIPv4,
buildType,
mustCall,
Expand Down
4 changes: 4 additions & 0 deletions tests/node_compat/target-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,17 @@ All of this is required for either target unless marked "26 only".
4. **Vendoring.** Vendor `test/sqlite/`, which `test-sqlite*.js` now load as `../sqlite/next-db.js`,
and copy it in `setup_node_compat_test_files`. `test/sea/` and `test/trace_events/` (26 only)
are where moved tests now live; vendor them only if those cases stay classified.
`test/sqlite/` vendoring and copying are in place; `test/sea/` and `test/trace_events/` are
still open.
5. **Shim helpers.**
- Both targets need `hasFIPS` and `isBoringSSL` in `common-shim/crypto.js`, plus
`hasInspector`, `hasSQLite`, `skipIfSQLiteMissing`, `expectRequireStack`,
`expectRequiredTLAError`, `sleepSync`, `isRiscv64` and `usesSharedLibrary`.
- 26 only: `hasFFI`, `skipIfFFIMissing`, `hasPerfetto`, `skipIfPerfettoEnabled`/`Disabled`,
`hasDtls`, `hasQuic`, `hasLocalStorage`, `hasTemporal`, `hasFullICU` and `hasV8Sandbox`.
- Export them from `index.mjs` too.
- These helpers are in place. Capability flags report what the component provides, because
`common.skip()` counts as a pass; `hasSQLite` probes `node:sqlite`.
6. **Mapping review.** Review the renamed-unmapped (63), now-ignored (38) and removed (85) rows
in the mapping file. Where a subtest of an `--expose-internals` file such as
`test-stream-finished.js` uses only public API, give it an explicit `runnable` category rather
Expand Down
8 changes: 5 additions & 3 deletions tests/node_compat/vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# If no version is specified, defaults to the version in NODE_VERSION below.
# The script sparse-checkouts test/parallel/, test/sequential/, test/es-module/,
# test/common/, and test/fixtures/ from the nodejs/node repository at the given tag.
# test/common/, test/fixtures/, and test/sqlite/ from the nodejs/node repository at the given tag.

set -euo pipefail

Expand All @@ -21,7 +21,7 @@ echo "==> Vendoring Node.js ${TAG} test suite into ${SUITE_DIR}"
rm -rf "${SUITE_DIR}"
mkdir -p "${SUITE_DIR}"

# Clone with sparse checkout — test/parallel, test/common, and test/fixtures
# Clone with sparse checkout
TMPDIR_CLONE="$(mktemp -d)"
trap 'rm -rf "${TMPDIR_CLONE}"' EXIT

Expand All @@ -31,14 +31,16 @@ git clone --depth 1 --sparse --branch "${TAG}" --single-branch \
https://github.com/nodejs/node.git "${TMPDIR_CLONE}/node"

cd "${TMPDIR_CLONE}/node"
git sparse-checkout set test/parallel test/sequential test/es-module test/common test/fixtures
git sparse-checkout set test/parallel test/sequential test/es-module test/common test/fixtures test/sqlite

echo "==> Copying test files..."
cp -r test/parallel "${SUITE_DIR}/parallel"
cp -r test/sequential "${SUITE_DIR}/sequential"
cp -r test/es-module "${SUITE_DIR}/es-module"
cp -r test/common "${SUITE_DIR}/common"
cp -r test/fixtures "${SUITE_DIR}/fixtures"
# Newer test-sqlite*.js files load shared helpers such as ../sqlite/next-db.js.
cp -r test/sqlite "${SUITE_DIR}/sqlite"

# Record the version
echo "${NODE_VERSION}" > "${SUITE_DIR}/NODE_VERSION"
Expand Down
Loading