browser-storage.js
composeApp/karma.config.d/browser-storage.js
1// Load the same OPFS implementation used by the application before Kotlin/Wasm contract tests.2{3 const fs = require('fs');4 const path = require('path');5 let directory = process.cwd();6 let script;7 while (true) {8 script = [path.join(directory, 'src/wasmJsMain/resources/browser-storage.js'),9 path.join(directory, 'composeApp/src/wasmJsMain/resources/browser-storage.js')].find(p => fs.existsSync(p));10 if (script || path.dirname(directory) === directory) break;11 directory = path.dirname(directory);12 }13 if (!script) throw new Error('Cannot locate browser-storage.js for Kotlin/Wasm tests');14 config.files.unshift({ pattern: script, included: true, served: true, watched: false });15 config.files.push({ pattern: path.join(path.dirname(script), 'browser-archives.js'), included: false, served: true, watched: false });16 config.files.push({ pattern: path.join(path.dirname(script), 'browser-files-sw.js'), included: false, served: true, watched: false });17 config.files.push({ pattern: path.join(path.dirname(script), 'vendor/zipjs-2.23.0/zip-native.min.js'), included: false, served: true, watched: false });18 // The production media worker and its dependencies live alongside the app page.19 // Karma otherwise serves these scripts under /absolute/... outside the runner page's scope.20 config.proxies = { ...(config.proxies || {}),21 '/browser-files-sw.js': '/absolute' + path.join(path.dirname(script), 'browser-files-sw.js'),22 '/browser-archives.js': '/absolute' + path.join(path.dirname(script), 'browser-archives.js'),23 '/vendor/zipjs-2.23.0/zip-native.min.js': '/absolute' + path.join(path.dirname(script), 'vendor/zipjs-2.23.0/zip-native.min.js'),24 };25 config.failOnEmptyTestSuite = true;26 // Contract checks stream >64 MiB through Kotlin/Wasm; Mocha's 2 s default flakes on cold/slow hosts.27 config.client = config.client || {};28 config.client.mocha = { ...(config.client.mocha || {}), timeout: 30000 };29}30