f81308a0df
Move all test files out of source dirs into per-workspace tests/: - shared/tests/ (3 unit test files) - server/tests/ (1 integration test) - src/tests/ (8 characterization + scenario tests + testHelpers) Fix all relative import paths (App, storage, __mocks__, testHelpers). Fix jest.config testMatch globs in shared/ and server/ (rootDir + <rootDir>/tests pattern). Delete scripts/repro-pause-bug.js (debug scratch, superseded by turn.pause-add.test.js). Keep scripts/replay-combat.js + scripts/audit-rotation.js as manual demo/exploratory tools (NOT unit tests, not deterministic). No logic changes. All green: shared 49 + 1 validated RED, server 23, FE 62. Scenario test unchanged (240s timeout, pre-existing slow).
37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
// Layer 2 test: exercise ws.js storage adapter against a LIVE backend.
|
|
// Complements Layer 1 (App + firebase mock) which proves App call shape but
|
|
// never touches ws.js. This catches translation bugs in the adapter.
|
|
//
|
|
// Runs the shared storage contract (same spec memory/firebase satisfy) against
|
|
// createWsStorage pointed at an ephemeral backend instance. A FRESH backend is
|
|
// spun up per test to guarantee isolation (backend has no reset endpoint yet).
|
|
|
|
'use strict';
|
|
|
|
const path = require('path');
|
|
const os = require('os');
|
|
const { createServer } = require('../index');
|
|
const { createWsStorage } = require('../../src/storage/ws');
|
|
const { runStorageContract } = require('../../src/storage/contract');
|
|
|
|
let nextPort = 4000 + Math.floor(Math.random() * 999);
|
|
|
|
// Factory: fresh backend (unique sqlite file) + storage pointed at it.
|
|
// Disposing the storage closes the backend so each test is fully isolated.
|
|
async function makeStorage() {
|
|
const port = nextPort++;
|
|
const dbPath = path.join(os.tmpdir(), `ws-contract-${port}-${Date.now()}.sqlite`);
|
|
const handle = createServer({ dbPath, port });
|
|
await new Promise((resolve, reject) => {
|
|
handle.server.on('error', reject);
|
|
handle.server.listen(port, resolve);
|
|
});
|
|
const baseUrl = `http://127.0.0.1:${port}`;
|
|
const wsUrl = `ws://127.0.0.1:${port}/ws`;
|
|
const storage = createWsStorage({ baseUrl, wsUrl });
|
|
storage.dispose = (done) => handle.close(done);
|
|
return storage;
|
|
}
|
|
|
|
runStorageContract('ws (live backend)', makeStorage);
|