Skip to content

Commit 0bb8f5f

Browse files
committed
lib,src,test: fix tests without SQLite
PR-URL: #60906 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent f3fe0e7 commit 0bb8f5f

File tree

9 files changed

+33
-8
lines changed

9 files changed

+33
-8
lines changed

node.gyp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,6 @@
927927
'sources': [
928928
'<@(node_sqlite_sources)',
929929
],
930-
'defines': [ 'HAVE_SQLITE=1' ],
931930
}],
932931
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
933932
'product_extension': '<(shlib_suffix)',
@@ -981,7 +980,6 @@
981980
'sources': [
982981
'<@(node_sqlite_sources)',
983982
],
984-
'defines': [ 'HAVE_SQLITE=1' ],
985983
}],
986984
[ 'OS in "linux freebsd mac solaris openharmony" and '
987985
'target_arch=="x64" and '

node.gypi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,5 +440,10 @@
440440
}, {
441441
'defines': [ 'HAVE_AMARO=0' ]
442442
}],
443+
[ 'node_use_sqlite=="true"', {
444+
'defines': [ 'HAVE_SQLITE=1' ],
445+
}, {
446+
'defines': [ 'HAVE_SQLITE=0' ]
447+
}],
443448
],
444449
}

test/common/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,6 @@ const knownGlobals = new Set([
350350
'CompressionStream',
351351
'DecompressionStream',
352352
'Storage',
353-
'localStorage',
354-
'sessionStorage',
355353
].forEach((i) => {
356354
if (globalThis[i] !== undefined) {
357355
knownGlobals.add(globalThis[i]);
@@ -365,6 +363,11 @@ if (hasCrypto) {
365363
knownGlobals.add(globalThis.SubtleCrypto);
366364
}
367365

366+
if (hasSQLite) {
367+
knownGlobals.add(globalThis.localStorage);
368+
knownGlobals.add(globalThis.sessionStorage);
369+
}
370+
368371
const { Worker } = require('node:worker_threads');
369372
knownGlobals.add(Worker);
370373

test/module-hooks/test-module-hooks-builtin-require.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ const { registerHooks } = require('module');
1212

1313
const schemelessBlockList = new Set([
1414
'sea',
15-
'sqlite',
1615
'test',
1716
'test/reporters',
1817
]);
1918

19+
if (common.hasSQLite) {
20+
schemelessBlockList.add('sqlite');
21+
}
22+
2023
const testModules = [];
2124
for (const mod of schemelessBlockList) {
2225
testModules.push(`node:${mod}`);

test/module-hooks/test-module-hooks-load-builtin-require.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ hook.deregister();
3636
// stripped for internal lookups should not get passed into the hooks.
3737
const schemelessBlockList = new Set([
3838
'sea',
39-
'sqlite',
4039
'test',
4140
'test/reporters',
4241
]);
4342

43+
if (common.hasSQLite) {
44+
schemelessBlockList.add('sqlite');
45+
}
46+
4447
const testModules = [];
4548
for (const mod of schemelessBlockList) {
4649
testModules.push(`node:${mod}`);

test/parallel/test-sqlite-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
const { skipIfSQLiteMissing } = require('../common/index.mjs');
33
const { test } = require('node:test');
44
const assert = require('node:assert');
5-
const { DatabaseSync } = require('node:sqlite');
65
skipIfSQLiteMissing();
6+
const { DatabaseSync } = require('node:sqlite');
77

88
function checkDefensiveMode(db) {
99
function journalMode() {

test/parallel/test-sqlite-template-tag.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
2-
require('../common');
2+
const { skipIfSQLiteMissing } = require('../common');
3+
skipIfSQLiteMissing();
4+
35
const assert = require('assert');
46
const { DatabaseSync } = require('node:sqlite');
57
const { test, beforeEach } = require('node:test');
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
// Flags: --experimental-webstorage --localstorage-file=./test/fixtures/empty.js
4+
5+
const { hasSQLite } = require('../common');
6+
const assert = require('node:assert');
7+
8+
// Ensuring that `sessionStorage` is not a getter that throws when built without SQLite.
9+
assert.strictEqual(typeof sessionStorage, hasSQLite ? 'object' : 'undefined');
10+
assert.strictEqual(Object.hasOwn(globalThis, 'sessionStorage'), hasSQLite);

typings/internalBinding/config.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface ConfigBinding {
88
hasTracing: boolean;
99
hasNodeOptions: boolean;
1010
hasInspector: boolean;
11+
hasSQLite: boolean;
1112
noBrowserGlobals: boolean;
1213
bits: number;
1314
getDefaultLocale(): string;

0 commit comments

Comments
 (0)