rooms-kit / test / subpaths.test.mjs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
 * Every path the v1.0.0 tsc output published must still resolve, exporting the
 * same names.
 *
 * v1.0.0's dist/ mirrored src/ one file per module (dist/lib/crypto.js,
 * dist/node/env.js, …). A shadow-cljs :esm build emits one FLAT file per
 * :modules entry instead, so scripts/gen-subpaths.mjs writes that tree back as
 * thin re-export shims. This is the table those shims are checked against — the
 * package's own `exports` map is checked in api.test.mjs.
 */
import { test } from "node:test";
import assert from "node:assert/strict";
import { load } from "./helpers/load.mjs";

/** dist path (without .js) -> the names that file exported in v1.0.0 */
const TREE = {
  "index": ["ChatClient", "newRoomSecret", "CHAT_SALT", "BoardClient", "BOARD_SALT", "installOrigin",
            "installBrowserGlobals", "Identity"],
  "chat/index": ["ChatClient", "newRoomSecret", "CHAT_SALT"],
  "board/index": ["BoardClient", "BOARD_SALT", "newRoomSecret"],
  "lib/crypto": ["randomBytes", "toB64", "fromB64", "toB64url", "fromB64url", "newRoomSecret", "newPeerId",
                 "Sealer", "AtRestCipher", "RoomCrypto"],
  "lib/encryption": ["makeLogEncryption"],
  "lib/descriptor": ["resolveRelayConfig"],
  "lib/turn": ["IceConfig"],
  "lib/access": ["HardenedIPFSAccessController", "signerMatchesIdentity"],
  "lib/orbit-identity": ["SuetaIdentityProvider", "registerSuetaProvider"],
  "lib/log": ["openHelia", "RoomLog"],
  "lib/net": ["newSessionKey", "Net"],
  "node/env": ["selfPeerIds", "installOrigin", "installOriginWebSocket", "installBrowserGlobals", "installOriginFetch"],
  // types only in the TypeScript original — an empty module, exactly as tsc emitted
  "lib/protocol": [],
};

for (const [path, expected] of Object.entries(TREE)) {
  test(`dist/${path}.js exports ${expected.length} historical name(s)`, async () => {
    const mod = await load(`${path}.js`);
    for (const name of expected) {
      assert.notEqual(mod[name], undefined, `dist/${path}.js is missing ${name}`);
    }
    const actual = Object.keys(mod).filter((k) => k !== "default" && k !== "__esModule");
    assert.deepEqual(actual.slice().sort(), expected.slice().sort(), `dist/${path}.js export set`);
  });
}

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/rooms-kit.git