import assert from 'node:assert/strict'; import { readFile, readdir } from 'node:fs/promises'; import path from 'node:path'; import test from 'node:test'; test('Svelte components own neither HTTP nor browser persistence policy', async () => { const sources = await sourceFiles('src'); const svelte = sources.filter((file) => file.endsWith('.svelte')); for (const file of svelte) { const source = await readFile(file, 'utf8'); assert.doesNotMatch(source, /\bfetch\s*\(/, file); assert.doesNotMatch(source, /\blocalStorage\b/, file); assert.doesNotMatch(source, /\bon:/, file); assert.doesNotMatch(source, /\$:/, file); } const storageOwners = []; for (const file of sources) { const source = await readFile(file, 'utf8'); if (source.includes('nuthatch-recursive-delete')) storageOwners.push(file); } assert.deepEqual(storageOwners, [ path.resolve('src/workflows/recursive-delete-persistence.ts') ]); }); test('upload identity never buffers or digests a complete File', async () => { const sources = await sourceFiles('src'); for (const file of sources) { const source = await readFile(file, 'utf8'); assert.doesNotMatch(source, /\bfile\.arrayBuffer\s*\(/i, file); assert.doesNotMatch(source, /\bcrypto\.subtle\.digest\s*\(/i, file); } }); async function sourceFiles(directory) { const entries = await readdir(directory, { withFileTypes: true }); return ( await Promise.all( entries.map((entry) => { const target = path.resolve(directory, entry.name); return entry.isDirectory() ? sourceFiles(target) : [target]; }) ) ).flat(); }