diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 81a01d0eb..823653b0a 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -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"); @@ -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(()) } diff --git a/tests/node_compat/README.md b/tests/node_compat/README.md index 810ab35a3..5c7131c16 100644 --- a/tests/node_compat/README.md +++ b/tests/node_compat/README.md @@ -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 @@ -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. @@ -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 diff --git a/tests/node_compat/common-shim/crypto.js b/tests/node_compat/common-shim/crypto.js index 506ee7a9d..8db4d0582 100644 --- a/tests/node_compat/common-shim/crypto.js +++ b/tests/node_compat/common-shim/crypto.js @@ -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; }, diff --git a/tests/node_compat/common-shim/index.js b/tests/node_compat/common-shim/index.js index 78702aab7..ef48e857c 100644 --- a/tests/node_compat/common-shim/index.js +++ b/tests/node_compat/common-shim/index.js @@ -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 = []; @@ -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 { diff --git a/tests/node_compat/common-shim/index.mjs b/tests/node_compat/common-shim/index.mjs index 43f538f0b..a6d5bb4f3 100644 --- a/tests/node_compat/common-shim/index.mjs +++ b/tests/node_compat/common-shim/index.mjs @@ -22,6 +22,17 @@ const { hasIPv6, hasMultiLocalhost, hasQuic, + hasInspector, + hasSQLite, + hasFFI, + hasDtls, + hasLocalStorage, + hasTemporal, + hasV8Sandbox, + isRiscv64, + skipIfSQLiteMissing, + skipIfPerfettoEnabled, + sleepSync, localhostIPv4, buildType, mustCall, @@ -75,6 +86,17 @@ export { hasIPv6, hasMultiLocalhost, hasQuic, + hasInspector, + hasSQLite, + hasFFI, + hasDtls, + hasLocalStorage, + hasTemporal, + hasV8Sandbox, + isRiscv64, + skipIfSQLiteMissing, + skipIfPerfettoEnabled, + sleepSync, localhostIPv4, buildType, mustCall, diff --git a/tests/node_compat/target-selection.md b/tests/node_compat/target-selection.md index 937d81d59..53625b58b 100644 --- a/tests/node_compat/target-selection.md +++ b/tests/node_compat/target-selection.md @@ -317,6 +317,8 @@ 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`, @@ -324,6 +326,8 @@ All of this is required for either target unless marked "26 only". - 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 diff --git a/tests/node_compat/vendor.sh b/tests/node_compat/vendor.sh index ecf011f8d..f260d9dd9 100755 --- a/tests/node_compat/vendor.sh +++ b/tests/node_compat/vendor.sh @@ -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 @@ -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 @@ -31,7 +31,7 @@ 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" @@ -39,6 +39,8 @@ 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"