Files
ttrpg-initiative-tracker/src/tests/StorageEsm.test.js
T

20 lines
895 B
JavaScript
Raw Normal View History

// Lock: storage adapters must use ESM exports (no module.exports).
// Regression guard: CJS in src/ crashes CRA prod build (ESM strict).
// Bug history: ws.js + memory.js used module.exports. Dev lenient (masked),
// prod bundle crashed blank page. firebase.js always ESM.
import fs from 'fs';
import path from 'path';
const ADAPTER_DIR = path.join(__dirname, '..', 'storage');
describe('storage adapters use ESM (no CJS)', () => {
const adapters = ['ws.js', 'memory.js', 'firebase.js', 'index.js'];
test.each(adapters)('%s has no module.exports', (file) => {
const full = fs.readFileSync(path.join(ADAPTER_DIR, file), 'utf8');
// strip line comments so words like 'require' in explanatory comments don't trip the guard
const src = full.replace(/^\s*\/\/.*$/gm, '');
expect(src).not.toMatch(/module\.exports\s*=/);
expect(src).not.toMatch(/\brequire\s*\(/);
});
});