'ws' conflated storage mode with transport protocol (WebSocket). Renamed for clarity: the adapter talks the self-hosted server (src/storage/server.js), which happens to use WebSocket for realtime — but the name should describe what it connects to, not how. Renames: - src/storage/ws.js -> server.js - createWsStorage() -> createServerStorage() - storage mode 'ws' -> 'server' - REACT_APP_BACKEND_WS -> REACT_APP_BACKEND_REALTIME_URL - factory param wsUrl -> realtimeUrl - server/tests/ws-*.test.js -> server-*.test.js Kept literal: 'ws' npm package, ws:// protocol URLs, /ws WebSocket endpoint. Transport is accurate there; only storage-naming changed. Updated all docs (DEVELOPMENT, TESTING, REWORK_PLAN, GLOSSARY, TODO), scripts (dev-start.sh, replay-combat.js), factory + ESM tests. 204 tests green.
20 lines
892 B
JavaScript
20 lines
892 B
JavaScript
// Lock: storage adapters must use ESM exports (no module.exports).
|
|
// Regression guard: CJS in src/ crashes CRA prod build (ESM strict).
|
|
// Bug history: server.js + firebase.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 = ['server.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*\(/);
|
|
});
|
|
});
|