lib,src,test: fix tests without SQLite

PR-URL: https://github.com/nodejs/node/pull/60906
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Antoine du Hamel 2025-12-11 23:04:24 +01:00 committed by GitHub
parent 4db307a4b0
commit 14f02fc2f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 35 additions and 12 deletions

View File

@ -192,7 +192,7 @@ jobs:
--arg ccache '(import <nixpkgs> {}).sccache' \
--arg devTools '[]' \
--arg benchmarkTools '[]' \
${{ endsWith(matrix.system, '-darwin') && '--arg extraConfigFlags ''["--without-amaro" "--without-inspector" "--without-node-options"]'' \' || '\' }}
${{ endsWith(matrix.system, '-darwin') && '--arg withAmaro false --arg withSQLite false --arg extraConfigFlags ''["--without-inspector" "--without-node-options"]'' \' || '\' }}
--run '
make -C "$TAR_DIR" run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
'

View File

@ -933,7 +933,6 @@
'sources': [
'<@(node_sqlite_sources)',
],
'defines': [ 'HAVE_SQLITE=1' ],
}],
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
'product_extension': '<(shlib_suffix)',
@ -982,7 +981,6 @@
'sources': [
'<@(node_sqlite_sources)',
],
'defines': [ 'HAVE_SQLITE=1' ],
}],
[ 'OS in "linux freebsd mac solaris openharmony" and '
'target_arch=="x64" and '

View File

@ -436,5 +436,10 @@
}, {
'defines': [ 'HAVE_AMARO=0' ]
}],
[ 'node_use_sqlite=="true"', {
'defines': [ 'HAVE_SQLITE=1' ],
}, {
'defines': [ 'HAVE_SQLITE=0' ]
}],
],
}

View File

@ -577,7 +577,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"experimental Web Storage API",
&EnvironmentOptions::webstorage,
kAllowedInEnvvar,
true);
HAVE_SQLITE);
AddAlias("--webstorage", "--experimental-webstorage");
AddOption("--localstorage-file",
"file used to persist localStorage data",

View File

@ -127,7 +127,7 @@ class EnvironmentOptions : public Options {
bool experimental_fetch = true;
bool experimental_websocket = true;
bool experimental_sqlite = true;
bool webstorage = true;
bool webstorage = HAVE_SQLITE;
#ifndef OPENSSL_NO_QUIC
bool experimental_quic = false;
#endif

View File

@ -370,7 +370,6 @@ const knownGlobals = new Set([
'CompressionStream',
'DecompressionStream',
'Storage',
'sessionStorage',
].forEach((i) => {
if (globalThis[i] !== undefined) {
knownGlobals.add(globalThis[i]);
@ -387,6 +386,9 @@ if (hasCrypto) {
if (hasLocalStorage) {
knownGlobals.add(globalThis.localStorage);
}
if (hasSQLite) {
knownGlobals.add(globalThis.sessionStorage);
}
const { Worker } = require('node:worker_threads');
knownGlobals.add(Worker);

View File

@ -12,11 +12,14 @@ const { registerHooks } = require('module');
const schemelessBlockList = new Set([
'sea',
'sqlite',
'test',
'test/reporters',
]);
if (common.hasSQLite) {
schemelessBlockList.add('sqlite');
}
const testModules = [];
for (const mod of schemelessBlockList) {
testModules.push(`node:${mod}`);

View File

@ -36,11 +36,14 @@ hook.deregister();
// stripped for internal lookups should not get passed into the hooks.
const schemelessBlockList = new Set([
'sea',
'sqlite',
'test',
'test/reporters',
]);
if (common.hasSQLite) {
schemelessBlockList.add('sqlite');
}
const testModules = [];
for (const mod of schemelessBlockList) {
testModules.push(`node:${mod}`);

View File

@ -59,9 +59,10 @@ for (const moduleName of builtinModules) {
'fetch',
'crypto',
'navigator',
'localStorage',
'sessionStorage',
];
if (common.hasSQLite) {
expected.push('localStorage', 'sessionStorage');
}
assert.deepStrictEqual(new Set(Object.keys(globalThis)), new Set(expected));
expected.forEach((value) => {
const desc = Object.getOwnPropertyDescriptor(globalThis, value);

View File

@ -2,8 +2,8 @@
const { skipIfSQLiteMissing } = require('../common/index.mjs');
const { test } = require('node:test');
const assert = require('node:assert');
const { DatabaseSync } = require('node:sqlite');
skipIfSQLiteMissing();
const { DatabaseSync } = require('node:sqlite');
function checkDefensiveMode(db) {
function journalMode() {

View File

@ -1,5 +1,7 @@
'use strict';
require('../common');
const { skipIfSQLiteMissing } = require('../common');
skipIfSQLiteMissing();
const assert = require('assert');
const { DatabaseSync } = require('node:sqlite');
const { test, beforeEach } = require('node:test');

View File

@ -0,0 +1,8 @@
'use strict';
const { hasSQLite } = require('../common');
const assert = require('node:assert');
// Ensuring that `sessionStorage` is not a getter that throws when built without SQLite.
assert.strictEqual(typeof sessionStorage, hasSQLite ? 'object' : 'undefined');
assert.strictEqual(Object.hasOwn(globalThis, 'sessionStorage'), hasSQLite);

View File

@ -8,6 +8,7 @@ export interface ConfigBinding {
hasTracing: boolean;
hasNodeOptions: boolean;
hasInspector: boolean;
hasSQLite: boolean;
noBrowserGlobals: boolean;
bits: number;
getDefaultLocale(): string;