experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(test): run unit tests under Electron's Node to match native module ABI

postinstall compiles better-sqlite3 for Electron's ABI (143), but
test:unit was running via system node (ABI 137). Now uses
ELECTRON_RUN_AS_NODE=1 npx electron --test for all unit test scripts.

Also optimizes check-native-modules.js to try loading the module under
Electron's Node first, only running electron-rebuild on mismatch.

+35 -9
+1
CHANGELOG.md
··· 97 97 - [x] fix: window-list returns actual URLs from peek://app/page containers 98 98 - [x] fix: mode detection from URL in window creation 99 99 - [x] fix: add native module check script (prevents NODE_MODULE_VERSION mismatch) 100 + - [x] fix: unit tests run under Electron's Node (ELECTRON_RUN_AS_NODE=1) to match native module ABI 100 101 - [x] fix(ipc): cast address to string for type safety (32a7f8a0) 101 102 - [x] fix(ipc): sanitize window params to prevent serialization crash (fca6a26f) 102 103 - [x] fix(build): exclude tmp/ agent workspaces from electron-builder (f0f26e31)
+1 -1
DEVELOPMENT.md
··· 110 110 │ ├── tabs.js # Tab sync (one-way import) 111 111 │ ├── history.js # History sync (one-way import, update-on-revisit) 112 112 │ ├── options.js # Options page logic 113 - │ └── tests/ # Node.js unit tests (node --test) 113 + │ └── tests/ # Unit tests (ELECTRON_RUN_AS_NODE=1, node --test) 114 114 └── server/ # Webhook API server for mobile sync 115 115 ├── index.js # Hono HTTP server 116 116 ├── db.js # SQLite via better-sqlite3
+4 -4
package.json
··· 137 137 "test:packaged": "yarn kill:packaged; HEADLESS=1 PACKAGED=1 npx playwright test tests/desktop/", 138 138 "test:packaged:debug": "yarn kill:packaged; HEADLESS=1 PACKAGED=1 DEBUG=1 npx playwright test tests/desktop/", 139 139 "//-- Testing --//": "", 140 - "test:unit": "./scripts/timed.sh sh -c 'yarn build && node --test dist/backend/electron/*.test.js'", 141 - "test:unit:modes": "./scripts/timed.sh sh -c 'yarn build && node --test dist/backend/electron/modes.test.js'", 142 - "test:unit:shortcuts": "./scripts/timed.sh sh -c 'yarn build && node --test dist/backend/electron/shortcuts.test.js'", 143 - "test:unit:datastore": "./scripts/timed.sh sh -c 'yarn build && node --test dist/backend/electron/datastore.test.js'", 140 + "test:unit": "./scripts/timed.sh sh -c 'yarn build && ELECTRON_RUN_AS_NODE=1 npx electron --test dist/backend/electron/*.test.js'", 141 + "test:unit:modes": "./scripts/timed.sh sh -c 'yarn build && ELECTRON_RUN_AS_NODE=1 npx electron --test dist/backend/electron/modes.test.js'", 142 + "test:unit:shortcuts": "./scripts/timed.sh sh -c 'yarn build && ELECTRON_RUN_AS_NODE=1 npx electron --test dist/backend/electron/shortcuts.test.js'", 143 + "test:unit:datastore": "./scripts/timed.sh sh -c 'yarn build && ELECTRON_RUN_AS_NODE=1 npx electron --test dist/backend/electron/datastore.test.js'", 144 144 "test": "./scripts/timed.sh sh -c 'yarn build && yarn test:electron && yarn test:tauri'", 145 145 "test:electron": "./scripts/timed.sh sh -c 'yarn check:native && yarn build && HEADLESS=1 BACKEND=electron npx playwright test tests/desktop/'", 146 146 "test:electron:x": "./scripts/timed.sh sh -c 'yarn build && HEADLESS=1 BACKEND=electron npx playwright test tests/desktop/ -x'",
+22 -4
scripts/check-native-modules.js
··· 2 2 /** 3 3 * Ensure native modules (better-sqlite3) are compiled for Electron's Node ABI. 4 4 * 5 - * This runs electron-rebuild which is idempotent - it only rebuilds if needed. 6 - * This prevents the recurring "NODE_MODULE_VERSION mismatch" error that occurs 7 - * when Electron's embedded Node version differs from the system Node version. 5 + * Fast path: tries to require() better-sqlite3 under Electron's Node runtime. 6 + * Only runs electron-rebuild if the module fails to load (ABI mismatch). 8 7 */ 9 8 10 9 import { execSync } from 'child_process'; ··· 13 12 14 13 const __dirname = dirname(fileURLToPath(import.meta.url)); 15 14 const ROOT = join(__dirname, '..'); 15 + const MODULE_PATH = join(ROOT, 'node_modules/better-sqlite3'); 16 + 17 + function canLoad() { 18 + try { 19 + const result = execSync( 20 + `ELECTRON_RUN_AS_NODE=1 npx electron -e "try { require('${MODULE_PATH}'); process.stdout.write('ok') } catch(e) { process.stdout.write('fail') }"`, 21 + { cwd: ROOT, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] } 22 + ); 23 + return result.trim() === 'ok'; 24 + } catch { 25 + return false; 26 + } 27 + } 28 + 29 + if (canLoad()) { 30 + console.log('[check-native-modules] better-sqlite3 loads in Electron — skip rebuild'); 31 + process.exit(0); 32 + } 33 + 34 + console.log('[check-native-modules] better-sqlite3 ABI mismatch — rebuilding...'); 16 35 17 36 try { 18 - // electron-rebuild is idempotent - only rebuilds if the ABI doesn't match 19 37 execSync('npx electron-rebuild -f -w better-sqlite3', { 20 38 cwd: ROOT, 21 39 stdio: 'inherit'
+7
tests/README.md
··· 25 25 # Run all tests (Electron Playwright + Tauri Rust) 26 26 yarn test 27 27 28 + # Unit tests (runs under Electron's Node via ELECTRON_RUN_AS_NODE=1) 29 + yarn test:unit # All unit tests 30 + yarn test:unit:datastore # Datastore tests only 31 + yarn test:unit:modes # Modes tests only 32 + yarn test:unit:shortcuts # Shortcuts tests only 33 + 28 34 # Run specific backend 29 35 yarn test:electron # Electron Playwright tests (headless) 30 36 yarn test:tauri # Tauri Rust unit tests ··· 44 50 | Backend | Status | Test Framework | Command | 45 51 |---------|--------|----------------|---------| 46 52 | Electron | ✅ Working | Playwright | `yarn test:electron` | 53 + | Electron | ✅ Working | Node unit tests (ELECTRON_RUN_AS_NODE=1) | `yarn test:unit` | 47 54 | Tauri | ✅ Working | Frontend Mock + Rust | `yarn test:tauri` | 48 55 49 56 ### Tauri Testing Notes