Files
breeze/tests/web_storage_test.mjs
T
waozi 7a88e3df9e Move Inbe application logic to Kryon and refresh the app
Move product behavior, app types, storage, audio, and tray logic into .kry modules. Use shared Kryon widgets, layout policies, asset-backed images, and app KSS styling with a smaller native boundary.

Include the pending navigation, sync recovery, localization, launcher icon, design asset, and 2.0.0 release metadata updates. Add version consistency checks and improve browser persistence and interaction validation.
2026-09-19 11:58:09 -03:00

50 lines
1.8 KiB
JavaScript

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import vm from 'node:vm';
const source = readFileSync(new URL('../src/web_boot.js', import.meta.url), 'utf8');
function boot(syncfs) {
const element = { addEventListener() {} };
const context = vm.createContext({
console: { log() {}, error() {} },
setTimeout, clearTimeout,
window: { addEventListener() {} },
document: {
querySelector() { return element; },
getElementById() { return element; },
addEventListener() {}
},
FS: { syncfs }
});
vm.runInContext(source, context);
return context.Module;
}
// IDBFS can complete synchronously when there is nothing to write.
const immediate = boot((populate, done) => done(null));
assert.equal(await immediate.__kryonFlushStorageSync(false), true);
assert.equal(immediate.__kryonStorageSyncLastOk, true);
assert.equal(await immediate.__kryonFlushStorageSync(false), true);
const failed = boot((populate, done) => done(new Error('write failed')));
assert.equal(await failed.__kryonFlushStorageSync(false), false);
assert.equal(failed.__kryonStorageSyncLastError, 'write failed');
const callbacks = [];
const queued = boot((populate, done) => callbacks.push(done));
const first = queued.__kryonFlushStorageSync(false);
const second = queued.__kryonFlushStorageSync(false);
assert.equal(first, second);
let resolved = false;
first.then(() => { resolved = true; });
callbacks.shift()(null);
await new Promise(resolve => setTimeout(resolve, 10));
assert.equal(resolved, false, 'flush must include writes queued during a save');
assert.equal(callbacks.length, 1);
callbacks.shift()(null);
assert.equal(await first, true);
assert.equal(await second, true);
assert.equal(queued.__kryonStorageSyncPending, false);
console.log('web storage tests passed');