@vttforge/testing 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @vttforge/testing
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 76fb4d5: `withMockFoundry` takes a `globals` option for anything outside the fixed set it installs.
8
+
9
+ Foundry puts every document class on the global scope, and code under test reaches for them by name. `JournalEntry.create`, `Actor.create`, `ChatMessage.getSpeaker`. None of those were covered, so testing code that touched one meant saving and restoring the global by hand in every file.
10
+
11
+ ```ts
12
+ const foundry = withMockFoundry({
13
+ globals: { JournalEntry: { create: vi.fn() } },
14
+ });
15
+ ```
16
+
17
+ `restore()` clears them along with the rest, putting back whatever was there before, including nothing. Naming one of the built-ins overrides it rather than being overwritten by it.
18
+
3
19
  ## 0.3.3
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -28,6 +28,17 @@ settings, notifications) so a test can assert on what happened rather than only
28
28
  on what did not throw. `restore()` puts every global back, including deleting the
29
29
  ones that never existed.
30
30
 
31
+ Anything else your code reads goes in `globals`. Foundry puts every document
32
+ class on the global scope, and the fixed set above does not include them:
33
+
34
+ ```ts
35
+ const foundry = withMockFoundry({
36
+ globals: { JournalEntry: { create: vi.fn() } },
37
+ });
38
+ ```
39
+
40
+ `restore()` clears those too.
41
+
31
42
  The mock documents behave like real ones where it counts: `update` merges rather
32
43
  than replacing, and dotted paths expand. Both matter: a mock that replaces lets
33
44
  a test pass while the real thing drops every sibling key.
@@ -124,6 +124,22 @@ interface MockFoundryOptions {
124
124
  foundry?: Record<string, unknown>;
125
125
  /** Extra `game.*` members, merged over the defaults. */
126
126
  game?: Record<string, unknown>;
127
+ /**
128
+ * Any other globals your code reads, installed for the life of the mock and
129
+ * removed by `restore()` along with the rest.
130
+ *
131
+ * Foundry puts each document class on the global scope, and code under test
132
+ * reaches for them by name: `Actor.create`, `JournalEntry.create`,
133
+ * `ChatMessage.getSpeaker`. Those are not part of the fixed set this helper
134
+ * installs, so name the ones you need.
135
+ *
136
+ * ```ts
137
+ * withMockFoundry({
138
+ * globals: { JournalEntry: { create: vi.fn() } },
139
+ * });
140
+ * ```
141
+ */
142
+ globals?: Record<string, unknown>;
127
143
  }
128
144
  /**
129
145
  * Stand up the globals, run the callback, tear them down.
@@ -159,4 +175,4 @@ declare global {
159
175
  }
160
176
  //#endregion
161
177
  export { RecordedSetting as a, MockDocument as c, createMockItem as d, RecordedHook as i, MockDocumentOptions as l, MockFoundryOptions as n, RecordedSheet as o, RecordedEnricher as r, withMockFoundry as s, MockFoundry as t, createMockActor as u };
162
- //# sourceMappingURL=index-DB9kK9Rn.d.mts.map
178
+ //# sourceMappingURL=index-BCCkkf3P.d.mts.map
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { n as QuenchContext, r as registerBatch, t as BatchOptions } from "./index-G_T1z-KX.mjs";
2
- import { a as RecordedSetting, c as MockDocument, d as createMockItem, i as RecordedHook, l as MockDocumentOptions, n as MockFoundryOptions, o as RecordedSheet, r as RecordedEnricher, s as withMockFoundry, t as MockFoundry, u as createMockActor } from "./index-DB9kK9Rn.mjs";
2
+ import { a as RecordedSetting, c as MockDocument, d as createMockItem, i as RecordedHook, l as MockDocumentOptions, n as MockFoundryOptions, o as RecordedSheet, r as RecordedEnricher, s as withMockFoundry, t as MockFoundry, u as createMockActor } from "./index-BCCkkf3P.mjs";
3
3
  export { type BatchOptions, type MockDocument, type MockDocumentOptions, type MockFoundry, type MockFoundryOptions, type QuenchContext, type RecordedEnricher, type RecordedHook, type RecordedSetting, type RecordedSheet, createMockActor, createMockItem, registerBatch, withMockFoundry };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import { t as registerBatch } from "./quench-C6E-Sh9r.mjs";
2
- import { n as createMockActor, r as createMockItem, t as withMockFoundry } from "./vitest-C9NdKAgo.mjs";
2
+ import { n as createMockActor, r as createMockItem, t as withMockFoundry } from "./vitest-CBmtoWrF.mjs";
3
3
  export { createMockActor, createMockItem, registerBatch, withMockFoundry };
@@ -1,2 +1,2 @@
1
- import { a as RecordedSetting, c as MockDocument, d as createMockItem, i as RecordedHook, l as MockDocumentOptions, n as MockFoundryOptions, o as RecordedSheet, r as RecordedEnricher, s as withMockFoundry, t as MockFoundry, u as createMockActor } from "../index-DB9kK9Rn.mjs";
1
+ import { a as RecordedSetting, c as MockDocument, d as createMockItem, i as RecordedHook, l as MockDocumentOptions, n as MockFoundryOptions, o as RecordedSheet, r as RecordedEnricher, s as withMockFoundry, t as MockFoundry, u as createMockActor } from "../index-BCCkkf3P.mjs";
2
2
  export { type MockDocument, type MockDocumentOptions, type MockFoundry, type MockFoundryOptions, type RecordedEnricher, type RecordedHook, type RecordedSetting, type RecordedSheet, createMockActor, createMockItem, withMockFoundry };
@@ -1,2 +1,2 @@
1
- import { n as createMockActor, r as createMockItem, t as withMockFoundry } from "../vitest-C9NdKAgo.mjs";
1
+ import { n as createMockActor, r as createMockItem, t as withMockFoundry } from "../vitest-CBmtoWrF.mjs";
2
2
  export { createMockActor, createMockItem, withMockFoundry };
@@ -128,7 +128,8 @@ function expandObject(flat) {
128
128
  function withMockFoundry(options = {}) {
129
129
  const saved = /* @__PURE__ */ new Map();
130
130
  const scope = globalThis;
131
- for (const name of GLOBALS) saved.set(name, scope[name]);
131
+ const extra = Object.keys(options.globals ?? {});
132
+ for (const name of [...GLOBALS, ...extra]) saved.set(name, scope[name]);
132
133
  const hooks = [];
133
134
  const settings = [];
134
135
  const values = /* @__PURE__ */ new Map();
@@ -287,6 +288,7 @@ function withMockFoundry(options = {}) {
287
288
  },
288
289
  ...options.game
289
290
  };
291
+ for (const [name, value] of Object.entries(options.globals ?? {})) scope[name] = value;
290
292
  return {
291
293
  hooks,
292
294
  settings,
@@ -304,4 +306,4 @@ function withMockFoundry(options = {}) {
304
306
  //#endregion
305
307
  export { createMockActor as n, createMockItem as r, withMockFoundry as t };
306
308
 
307
- //# sourceMappingURL=vitest-C9NdKAgo.mjs.map
309
+ //# sourceMappingURL=vitest-CBmtoWrF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest-CBmtoWrF.mjs","names":[],"sources":["../src/vitest/mock-foundry.ts","../src/vitest/with-mock-foundry.ts"],"sourcesContent":["/**\n * A Foundry runtime, faked well enough to import a package and construct\n * its classes.\n *\n * Every `@vttforge/core` test built this by hand before this existed, and no\n * two built it quite the same way. That is the problem: the globals a package\n * needs are not obvious, they are not documented anywhere, and you discover\n * them one `ReferenceError` at a time.\n *\n * What this covers is the boundary the SDK actually sits on: everything up\n * to the moment a window renders. `_renderHTML` and beyond needs a real\n * browser and a real Foundry; that is what the Quench half is for.\n */\n\n/** A Foundry document, as much of one as a unit test needs. */\nexport interface MockDocument {\n id: string;\n name: string;\n type: string;\n // biome-ignore lint/suspicious/noExplicitAny: a document's system data is whatever its schema says\n system: Record<string, any>;\n flags: Record<string, Record<string, unknown>>;\n getFlag(scope: string, key: string): unknown;\n setFlag(scope: string, key: string, value: unknown): Promise<MockDocument>;\n unsetFlag(scope: string, key: string): Promise<MockDocument>;\n update(delta: Record<string, unknown>): Promise<MockDocument>;\n /** Every update this document received, in order. */\n readonly updates: ReadonlyArray<Record<string, unknown>>;\n}\n\nexport interface MockDocumentOptions {\n id?: string;\n name?: string;\n type?: string;\n // biome-ignore lint/suspicious/noExplicitAny: mirrors MockDocument.system\n system?: Record<string, any>;\n flags?: Record<string, Record<string, unknown>>;\n}\n\nlet nextId = 0;\n\n/** `{'system.hp.value': 3}` → `{system: {hp: {value: 3}}}`. */\nfunction expand(flat: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [path, value] of Object.entries(flat)) {\n const parts = path.split('.');\n const last = parts.pop();\n if (!last) continue;\n let target = out;\n for (const part of parts) {\n target[part] ??= {};\n target = target[part] as Record<string, unknown>;\n }\n target[last] = value;\n }\n return out;\n}\n\n/** Deep-merge, the way a document update behaves. Arrays replace wholesale. */\nfunction merge(target: Record<string, unknown>, source: Record<string, unknown>): void {\n for (const [key, value] of Object.entries(source)) {\n const isPlain =\n value !== null &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n Object.getPrototypeOf(value) === Object.prototype;\n if (isPlain) {\n if (typeof target[key] !== 'object' || target[key] === null) target[key] = {};\n merge(target[key] as Record<string, unknown>, value as Record<string, unknown>);\n } else {\n target[key] = value;\n }\n }\n}\n\nfunction createMockDocument(kind: string, options: MockDocumentOptions = {}): MockDocument {\n nextId += 1;\n const updates: Record<string, unknown>[] = [];\n\n const doc: MockDocument = {\n id: options.id ?? `${kind}${String(nextId).padStart(12, '0')}`,\n name: options.name ?? `Test ${kind}`,\n type: options.type ?? 'base',\n system: options.system ?? {},\n flags: options.flags ?? {},\n updates,\n\n getFlag: (scope, key) => doc.flags[scope]?.[key],\n\n setFlag: async (scope, key, value) => {\n doc.flags[scope] ??= {};\n doc.flags[scope][key] = value;\n return doc;\n },\n\n unsetFlag: async (scope, key) => {\n delete doc.flags[scope]?.[key];\n return doc;\n },\n\n /**\n * Records the delta and merges it in.\n *\n * Merges, not replaces, which is what Foundry does and what a mock has\n * to match. Assigning `{system: {hp: {value: 4}}}` wholesale drops\n * `hp.max`, and a test written against that passes while the real thing\n * loses data.\n *\n * Dotted keys are expanded first, because that is how updates arrive.\n */\n update: async (delta) => {\n updates.push(delta);\n merge(doc as unknown as Record<string, unknown>, expand(delta));\n return doc;\n },\n };\n\n return doc;\n}\n\n/** An Actor for a test. Its `updates` record what the code under test wrote. */\nexport function createMockActor(options: MockDocumentOptions = {}): MockDocument {\n return createMockDocument('Actor', { type: 'character', ...options });\n}\n\n/** An Item for a test. */\nexport function createMockItem(options: MockDocumentOptions = {}): MockDocument {\n return createMockDocument('Item', { type: 'base', ...options });\n}\n","/**\n * Install the Foundry globals a package needs, and take them away again.\n *\n * The globals are the awkward part of testing anything built on Foundry:\n * `foundry`, `game`, `CONFIG`, `Hooks`, `ui`, `CONST`. A package touches some\n * subset, the subset is not written down, and you find it one\n * `ReferenceError` at a time.\n *\n * Everything here is a plain object or a recording stub, so a test can assert\n * on what was registered rather than only on what did not throw.\n */\n\n/** A hook registration the code under test made. */\nexport interface RecordedHook {\n event: string;\n once: boolean;\n fn: (...args: unknown[]) => unknown;\n}\n\n/** A setting the code under test registered. */\nexport interface RecordedSetting {\n namespace: string;\n key: string;\n config: Record<string, unknown>;\n}\n\n/** One `DocumentSheetConfig.registerSheet`, as VTTForge makes it. */\nexport interface RecordedSheet {\n /** The key Foundry persists: `<package id>.<sheet id>`. */\n readonly key: string;\n /** The package that registered it. */\n readonly scope: string;\n /** The sheet id, the class name VTTForge pinned. */\n readonly id: string;\n readonly sheetClass: unknown;\n readonly documentClass: unknown;\n readonly options: Record<string, unknown>;\n}\n\n/** One entry pushed onto `CONFIG.TextEditor.enrichers`. */\nexport interface RecordedEnricher {\n /** The namespaced id: `<package id>.<enricher id>`. */\n readonly id: string;\n readonly pattern: RegExp;\n readonly onRender?: unknown;\n}\n\nexport interface MockFoundry {\n /** Every `Hooks.on` and `Hooks.once`, in order. */\n readonly hooks: ReadonlyArray<RecordedHook>;\n /** Every `game.settings.register`, in order. */\n readonly settings: ReadonlyArray<RecordedSetting>;\n /** Every notification raised, by severity. */\n readonly notifications: ReadonlyArray<{ level: 'info' | 'warn' | 'error'; message: string }>;\n /**\n * Every sheet registered, in order.\n *\n * `key` is the thing worth asserting: Foundry saves it on each document\n * using the sheet, so a test that pins the key is a test that the reader's\n * choice survives your next build.\n */\n readonly sheets: ReadonlyArray<RecordedSheet>;\n /**\n * Every text enricher registered, in order.\n *\n * `id` is namespaced, which is what stops a common name from colliding with\n * another package, and what makes `onRender` fire at all.\n */\n readonly enrichers: ReadonlyArray<RecordedEnricher>;\n /** Fire a hook the way Foundry would, for the listeners registered so far. */\n callHook(event: string, ...args: unknown[]): unknown[];\n /** Read back a registered setting's current value. */\n getSetting(namespace: string, key: string): unknown;\n /** Put every global back the way it was. */\n restore(): void;\n}\n\nexport interface MockFoundryOptions {\n /** The current user. Defaults to a GM, since most module code checks. */\n user?: { id?: string; isGM?: boolean; name?: string };\n /** Extra `foundry.*` members, merged over the defaults. */\n foundry?: Record<string, unknown>;\n /** Extra `game.*` members, merged over the defaults. */\n game?: Record<string, unknown>;\n /**\n * Any other globals your code reads, installed for the life of the mock and\n * removed by `restore()` along with the rest.\n *\n * Foundry puts each document class on the global scope, and code under test\n * reaches for them by name: `Actor.create`, `JournalEntry.create`,\n * `ChatMessage.getSpeaker`. Those are not part of the fixed set this helper\n * installs, so name the ones you need.\n *\n * ```ts\n * withMockFoundry({\n * globals: { JournalEntry: { create: vi.fn() } },\n * });\n * ```\n */\n globals?: Record<string, unknown>;\n}\n\nconst GLOBALS = ['foundry', 'game', 'CONFIG', 'Hooks', 'ui', 'CONST'] as const;\n\n/**\n * Flatten and expand, the way `foundry.utils` does.\n *\n * Provided because SDK code calls them on the global, not because a test\n * needs them: leaving them out means every consumer stubs them again.\n */\nfunction flattenObject(obj: Record<string, unknown>, prefix = ''): Record<string, unknown> {\n const flat: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n const path = prefix ? `${prefix}.${key}` : key;\n const isPlain =\n value !== null &&\n typeof value === 'object' &&\n Object.getPrototypeOf(value) === Object.prototype;\n if (isPlain && Object.keys(value as object).length > 0) {\n Object.assign(flat, flattenObject(value as Record<string, unknown>, path));\n } else {\n flat[path] = value;\n }\n }\n return flat;\n}\n\nfunction expandObject(flat: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [path, value] of Object.entries(flat)) {\n const parts = path.split('.');\n const last = parts.pop();\n if (!last) continue;\n let target = out;\n for (const part of parts) {\n target[part] ??= {};\n target = target[part] as Record<string, unknown>;\n }\n target[last] = value;\n }\n return out;\n}\n\n/**\n * Stand up the globals, run the callback, tear them down.\n *\n * ```ts\n * const foundry = withMockFoundry();\n * registerMyModule();\n * expect(foundry.hooks.map((h) => h.event)).toContain('init');\n * foundry.restore();\n * ```\n */\nexport function withMockFoundry(options: MockFoundryOptions = {}): MockFoundry {\n const saved = new Map<string, unknown>();\n const scope = globalThis as Record<string, unknown>;\n const extra = Object.keys(options.globals ?? {});\n // Saved before anything is installed, so `restore()` puts back whatever was\n // there, including nothing.\n for (const name of [...GLOBALS, ...extra]) saved.set(name, scope[name]);\n\n const hooks: RecordedHook[] = [];\n const settings: RecordedSetting[] = [];\n const values = new Map<string, unknown>();\n const notifications: { level: 'info' | 'warn' | 'error'; message: string }[] = [];\n\n const Hooks = {\n on: (event: string, fn: (...a: unknown[]) => unknown) => {\n hooks.push({ event, once: false, fn });\n return hooks.length;\n },\n once: (event: string, fn: (...a: unknown[]) => unknown) => {\n hooks.push({ event, once: true, fn });\n return hooks.length;\n },\n off: () => {},\n call: (event: string, ...args: unknown[]) => callHook(event, ...args).every((r) => r !== false),\n callAll: (event: string, ...args: unknown[]) => {\n callHook(event, ...args);\n return true;\n },\n };\n\n function callHook(event: string, ...args: unknown[]): unknown[] {\n return hooks.filter((h) => h.event === event).map((h) => h.fn(...args));\n }\n\n const user = { id: 'user000000000001', isGM: true, name: 'Gamemaster', ...options.user };\n\n const sheets: RecordedSheet[] = [];\n const enrichers: RecordedEnricher[] = [];\n\n scope.Hooks = Hooks;\n scope.CONST = { DOCUMENT_OWNERSHIP_LEVELS: { NONE: 0, LIMITED: 1, OBSERVER: 2, OWNER: 3 } };\n scope.CONFIG = {\n Actor: { dataModels: {}, sheetClasses: {} },\n Item: { dataModels: {}, sheetClasses: {} },\n TextEditor: { enrichers },\n Combat: {},\n ActiveEffect: {},\n statusEffects: [],\n debug: { hooks: false },\n };\n scope.ui = {\n notifications: {\n info: (m: string) => notifications.push({ level: 'info', message: m }),\n warn: (m: string) => notifications.push({ level: 'warn', message: m }),\n error: (m: string) => notifications.push({ level: 'error', message: m }),\n },\n };\n scope.foundry = {\n utils: {\n flattenObject,\n expandObject,\n mergeObject: (a: Record<string, unknown>, b: Record<string, unknown>) => ({ ...a, ...b }),\n deepClone: <T>(v: T): T => structuredClone(v),\n randomID: () => Math.random().toString(36).slice(2, 18),\n isNewerVersion: (a: string, b: string) =>\n a.localeCompare(b, undefined, { numeric: true }) > 0,\n },\n abstract: { TypeDataModel: class {}, DataModel: class {}, Document: class {} },\n data: { fields: {} },\n applications: {\n api: { ApplicationV2: class {}, HandlebarsApplicationMixin: (b: unknown) => b },\n sheets: { ActorSheetV2: class {}, ItemSheetV2: class {} },\n apps: {\n // Where `registerSystem({ sheets })` and `registerModule({ sheets })`\n // register. Foundry builds the key from the class name, so this\n // records the same key it would persist.\n DocumentSheetConfig: {\n registerSheet(\n documentClass: unknown,\n scope: string,\n sheetClass: { name: string },\n sheetOptions: Record<string, unknown> = {},\n ) {\n sheets.push({\n key: `${scope}.${sheetClass.name}`,\n scope,\n id: sheetClass.name,\n sheetClass,\n documentClass,\n options: sheetOptions,\n });\n },\n unregisterSheet: () => {},\n },\n },\n ux: {},\n instances: new Map(),\n },\n documents: {\n collections: {\n Actors: { registerSheet: () => {}, unregisterSheet: () => {} },\n Items: { registerSheet: () => {}, unregisterSheet: () => {} },\n },\n },\n ...options.foundry,\n };\n scope.game = {\n user,\n userId: user.id,\n ready: true,\n modules: new Map(),\n actors: [],\n items: [],\n i18n: {\n localize: (key: string) => key,\n format: (key: string, data: Record<string, unknown>) => `${key} ${JSON.stringify(data)}`,\n },\n settings: {\n register: (namespace: string, key: string, config: Record<string, unknown>) => {\n settings.push({ namespace, key, config });\n values.set(`${namespace}.${key}`, config.default);\n },\n get: (namespace: string, key: string) => values.get(`${namespace}.${key}`),\n set: async (namespace: string, key: string, value: unknown) => {\n values.set(`${namespace}.${key}`, value);\n return value;\n },\n },\n ...options.game,\n };\n\n // Last, so naming one of the built-ins here overrides it rather than\n // being overwritten by it.\n for (const [name, value] of Object.entries(options.globals ?? {})) scope[name] = value;\n\n return {\n hooks,\n settings,\n notifications,\n sheets,\n enrichers,\n callHook,\n getSetting: (namespace, key) => values.get(`${namespace}.${key}`),\n restore() {\n for (const [name, value] of saved) {\n if (value === undefined) delete scope[name];\n else scope[name] = value;\n }\n },\n };\n}\n"],"mappings":";AAuCA,IAAI,SAAS;;AAGb,SAAS,OAAO,MAAwD;CACtE,MAAM,MAA+B,CAAC;CACtC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,IAAI,GAAG;EAChD,MAAM,QAAQ,KAAK,MAAM,GAAG;EAC5B,MAAM,OAAO,MAAM,IAAI;EACvB,IAAI,CAAC,MAAM;EACX,IAAI,SAAS;EACb,KAAK,MAAM,QAAQ,OAAO;GACxB,OAAO,UAAU,CAAC;GAClB,SAAS,OAAO;EAClB;EACA,OAAO,QAAQ;CACjB;CACA,OAAO;AACT;;AAGA,SAAS,MAAM,QAAiC,QAAuC;CACrF,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAM9C,IAJE,UAAU,QACV,OAAO,UAAU,YACjB,CAAC,MAAM,QAAQ,KAAK,KACpB,OAAO,eAAe,KAAK,MAAM,OAAO,WAC7B;EACX,IAAI,OAAO,OAAO,SAAS,YAAY,OAAO,SAAS,MAAM,OAAO,OAAO,CAAC;EAC5E,MAAM,OAAO,MAAiC,KAAgC;CAChF,OACE,OAAO,OAAO;AAGpB;AAEA,SAAS,mBAAmB,MAAc,UAA+B,CAAC,GAAiB;CACzF,UAAU;CACV,MAAM,UAAqC,CAAC;CAE5C,MAAM,MAAoB;EACxB,IAAI,QAAQ,MAAM,GAAG,OAAO,OAAO,MAAM,CAAC,CAAC,SAAS,IAAI,GAAG;EAC3D,MAAM,QAAQ,QAAQ,QAAQ;EAC9B,MAAM,QAAQ,QAAQ;EACtB,QAAQ,QAAQ,UAAU,CAAC;EAC3B,OAAO,QAAQ,SAAS,CAAC;EACzB;EAEA,UAAU,OAAO,QAAQ,IAAI,MAAM,MAAM,GAAG;EAE5C,SAAS,OAAO,OAAO,KAAK,UAAU;GACpC,IAAI,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ge/testing",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "description": "Foundry mocks for Vitest and Quench helpers, for testing VTTForge systems and modules.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1 +0,0 @@
1
- {"version":3,"file":"vitest-C9NdKAgo.mjs","names":[],"sources":["../src/vitest/mock-foundry.ts","../src/vitest/with-mock-foundry.ts"],"sourcesContent":["/**\n * A Foundry runtime, faked well enough to import a package and construct\n * its classes.\n *\n * Every `@vttforge/core` test built this by hand before this existed, and no\n * two built it quite the same way. That is the problem: the globals a package\n * needs are not obvious, they are not documented anywhere, and you discover\n * them one `ReferenceError` at a time.\n *\n * What this covers is the boundary the SDK actually sits on: everything up\n * to the moment a window renders. `_renderHTML` and beyond needs a real\n * browser and a real Foundry; that is what the Quench half is for.\n */\n\n/** A Foundry document, as much of one as a unit test needs. */\nexport interface MockDocument {\n id: string;\n name: string;\n type: string;\n // biome-ignore lint/suspicious/noExplicitAny: a document's system data is whatever its schema says\n system: Record<string, any>;\n flags: Record<string, Record<string, unknown>>;\n getFlag(scope: string, key: string): unknown;\n setFlag(scope: string, key: string, value: unknown): Promise<MockDocument>;\n unsetFlag(scope: string, key: string): Promise<MockDocument>;\n update(delta: Record<string, unknown>): Promise<MockDocument>;\n /** Every update this document received, in order. */\n readonly updates: ReadonlyArray<Record<string, unknown>>;\n}\n\nexport interface MockDocumentOptions {\n id?: string;\n name?: string;\n type?: string;\n // biome-ignore lint/suspicious/noExplicitAny: mirrors MockDocument.system\n system?: Record<string, any>;\n flags?: Record<string, Record<string, unknown>>;\n}\n\nlet nextId = 0;\n\n/** `{'system.hp.value': 3}` → `{system: {hp: {value: 3}}}`. */\nfunction expand(flat: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [path, value] of Object.entries(flat)) {\n const parts = path.split('.');\n const last = parts.pop();\n if (!last) continue;\n let target = out;\n for (const part of parts) {\n target[part] ??= {};\n target = target[part] as Record<string, unknown>;\n }\n target[last] = value;\n }\n return out;\n}\n\n/** Deep-merge, the way a document update behaves. Arrays replace wholesale. */\nfunction merge(target: Record<string, unknown>, source: Record<string, unknown>): void {\n for (const [key, value] of Object.entries(source)) {\n const isPlain =\n value !== null &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n Object.getPrototypeOf(value) === Object.prototype;\n if (isPlain) {\n if (typeof target[key] !== 'object' || target[key] === null) target[key] = {};\n merge(target[key] as Record<string, unknown>, value as Record<string, unknown>);\n } else {\n target[key] = value;\n }\n }\n}\n\nfunction createMockDocument(kind: string, options: MockDocumentOptions = {}): MockDocument {\n nextId += 1;\n const updates: Record<string, unknown>[] = [];\n\n const doc: MockDocument = {\n id: options.id ?? `${kind}${String(nextId).padStart(12, '0')}`,\n name: options.name ?? `Test ${kind}`,\n type: options.type ?? 'base',\n system: options.system ?? {},\n flags: options.flags ?? {},\n updates,\n\n getFlag: (scope, key) => doc.flags[scope]?.[key],\n\n setFlag: async (scope, key, value) => {\n doc.flags[scope] ??= {};\n doc.flags[scope][key] = value;\n return doc;\n },\n\n unsetFlag: async (scope, key) => {\n delete doc.flags[scope]?.[key];\n return doc;\n },\n\n /**\n * Records the delta and merges it in.\n *\n * Merges, not replaces, which is what Foundry does and what a mock has\n * to match. Assigning `{system: {hp: {value: 4}}}` wholesale drops\n * `hp.max`, and a test written against that passes while the real thing\n * loses data.\n *\n * Dotted keys are expanded first, because that is how updates arrive.\n */\n update: async (delta) => {\n updates.push(delta);\n merge(doc as unknown as Record<string, unknown>, expand(delta));\n return doc;\n },\n };\n\n return doc;\n}\n\n/** An Actor for a test. Its `updates` record what the code under test wrote. */\nexport function createMockActor(options: MockDocumentOptions = {}): MockDocument {\n return createMockDocument('Actor', { type: 'character', ...options });\n}\n\n/** An Item for a test. */\nexport function createMockItem(options: MockDocumentOptions = {}): MockDocument {\n return createMockDocument('Item', { type: 'base', ...options });\n}\n","/**\n * Install the Foundry globals a package needs, and take them away again.\n *\n * The globals are the awkward part of testing anything built on Foundry:\n * `foundry`, `game`, `CONFIG`, `Hooks`, `ui`, `CONST`. A package touches some\n * subset, the subset is not written down, and you find it one\n * `ReferenceError` at a time.\n *\n * Everything here is a plain object or a recording stub, so a test can assert\n * on what was registered rather than only on what did not throw.\n */\n\n/** A hook registration the code under test made. */\nexport interface RecordedHook {\n event: string;\n once: boolean;\n fn: (...args: unknown[]) => unknown;\n}\n\n/** A setting the code under test registered. */\nexport interface RecordedSetting {\n namespace: string;\n key: string;\n config: Record<string, unknown>;\n}\n\n/** One `DocumentSheetConfig.registerSheet`, as VTTForge makes it. */\nexport interface RecordedSheet {\n /** The key Foundry persists: `<package id>.<sheet id>`. */\n readonly key: string;\n /** The package that registered it. */\n readonly scope: string;\n /** The sheet id, the class name VTTForge pinned. */\n readonly id: string;\n readonly sheetClass: unknown;\n readonly documentClass: unknown;\n readonly options: Record<string, unknown>;\n}\n\n/** One entry pushed onto `CONFIG.TextEditor.enrichers`. */\nexport interface RecordedEnricher {\n /** The namespaced id: `<package id>.<enricher id>`. */\n readonly id: string;\n readonly pattern: RegExp;\n readonly onRender?: unknown;\n}\n\nexport interface MockFoundry {\n /** Every `Hooks.on` and `Hooks.once`, in order. */\n readonly hooks: ReadonlyArray<RecordedHook>;\n /** Every `game.settings.register`, in order. */\n readonly settings: ReadonlyArray<RecordedSetting>;\n /** Every notification raised, by severity. */\n readonly notifications: ReadonlyArray<{ level: 'info' | 'warn' | 'error'; message: string }>;\n /**\n * Every sheet registered, in order.\n *\n * `key` is the thing worth asserting: Foundry saves it on each document\n * using the sheet, so a test that pins the key is a test that the reader's\n * choice survives your next build.\n */\n readonly sheets: ReadonlyArray<RecordedSheet>;\n /**\n * Every text enricher registered, in order.\n *\n * `id` is namespaced, which is what stops a common name from colliding with\n * another package, and what makes `onRender` fire at all.\n */\n readonly enrichers: ReadonlyArray<RecordedEnricher>;\n /** Fire a hook the way Foundry would, for the listeners registered so far. */\n callHook(event: string, ...args: unknown[]): unknown[];\n /** Read back a registered setting's current value. */\n getSetting(namespace: string, key: string): unknown;\n /** Put every global back the way it was. */\n restore(): void;\n}\n\nexport interface MockFoundryOptions {\n /** The current user. Defaults to a GM, since most module code checks. */\n user?: { id?: string; isGM?: boolean; name?: string };\n /** Extra `foundry.*` members, merged over the defaults. */\n foundry?: Record<string, unknown>;\n /** Extra `game.*` members, merged over the defaults. */\n game?: Record<string, unknown>;\n}\n\nconst GLOBALS = ['foundry', 'game', 'CONFIG', 'Hooks', 'ui', 'CONST'] as const;\n\n/**\n * Flatten and expand, the way `foundry.utils` does.\n *\n * Provided because SDK code calls them on the global, not because a test\n * needs them: leaving them out means every consumer stubs them again.\n */\nfunction flattenObject(obj: Record<string, unknown>, prefix = ''): Record<string, unknown> {\n const flat: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n const path = prefix ? `${prefix}.${key}` : key;\n const isPlain =\n value !== null &&\n typeof value === 'object' &&\n Object.getPrototypeOf(value) === Object.prototype;\n if (isPlain && Object.keys(value as object).length > 0) {\n Object.assign(flat, flattenObject(value as Record<string, unknown>, path));\n } else {\n flat[path] = value;\n }\n }\n return flat;\n}\n\nfunction expandObject(flat: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [path, value] of Object.entries(flat)) {\n const parts = path.split('.');\n const last = parts.pop();\n if (!last) continue;\n let target = out;\n for (const part of parts) {\n target[part] ??= {};\n target = target[part] as Record<string, unknown>;\n }\n target[last] = value;\n }\n return out;\n}\n\n/**\n * Stand up the globals, run the callback, tear them down.\n *\n * ```ts\n * const foundry = withMockFoundry();\n * registerMyModule();\n * expect(foundry.hooks.map((h) => h.event)).toContain('init');\n * foundry.restore();\n * ```\n */\nexport function withMockFoundry(options: MockFoundryOptions = {}): MockFoundry {\n const saved = new Map<string, unknown>();\n const scope = globalThis as Record<string, unknown>;\n for (const name of GLOBALS) saved.set(name, scope[name]);\n\n const hooks: RecordedHook[] = [];\n const settings: RecordedSetting[] = [];\n const values = new Map<string, unknown>();\n const notifications: { level: 'info' | 'warn' | 'error'; message: string }[] = [];\n\n const Hooks = {\n on: (event: string, fn: (...a: unknown[]) => unknown) => {\n hooks.push({ event, once: false, fn });\n return hooks.length;\n },\n once: (event: string, fn: (...a: unknown[]) => unknown) => {\n hooks.push({ event, once: true, fn });\n return hooks.length;\n },\n off: () => {},\n call: (event: string, ...args: unknown[]) => callHook(event, ...args).every((r) => r !== false),\n callAll: (event: string, ...args: unknown[]) => {\n callHook(event, ...args);\n return true;\n },\n };\n\n function callHook(event: string, ...args: unknown[]): unknown[] {\n return hooks.filter((h) => h.event === event).map((h) => h.fn(...args));\n }\n\n const user = { id: 'user000000000001', isGM: true, name: 'Gamemaster', ...options.user };\n\n const sheets: RecordedSheet[] = [];\n const enrichers: RecordedEnricher[] = [];\n\n scope.Hooks = Hooks;\n scope.CONST = { DOCUMENT_OWNERSHIP_LEVELS: { NONE: 0, LIMITED: 1, OBSERVER: 2, OWNER: 3 } };\n scope.CONFIG = {\n Actor: { dataModels: {}, sheetClasses: {} },\n Item: { dataModels: {}, sheetClasses: {} },\n TextEditor: { enrichers },\n Combat: {},\n ActiveEffect: {},\n statusEffects: [],\n debug: { hooks: false },\n };\n scope.ui = {\n notifications: {\n info: (m: string) => notifications.push({ level: 'info', message: m }),\n warn: (m: string) => notifications.push({ level: 'warn', message: m }),\n error: (m: string) => notifications.push({ level: 'error', message: m }),\n },\n };\n scope.foundry = {\n utils: {\n flattenObject,\n expandObject,\n mergeObject: (a: Record<string, unknown>, b: Record<string, unknown>) => ({ ...a, ...b }),\n deepClone: <T>(v: T): T => structuredClone(v),\n randomID: () => Math.random().toString(36).slice(2, 18),\n isNewerVersion: (a: string, b: string) =>\n a.localeCompare(b, undefined, { numeric: true }) > 0,\n },\n abstract: { TypeDataModel: class {}, DataModel: class {}, Document: class {} },\n data: { fields: {} },\n applications: {\n api: { ApplicationV2: class {}, HandlebarsApplicationMixin: (b: unknown) => b },\n sheets: { ActorSheetV2: class {}, ItemSheetV2: class {} },\n apps: {\n // Where `registerSystem({ sheets })` and `registerModule({ sheets })`\n // register. Foundry builds the key from the class name, so this\n // records the same key it would persist.\n DocumentSheetConfig: {\n registerSheet(\n documentClass: unknown,\n scope: string,\n sheetClass: { name: string },\n sheetOptions: Record<string, unknown> = {},\n ) {\n sheets.push({\n key: `${scope}.${sheetClass.name}`,\n scope,\n id: sheetClass.name,\n sheetClass,\n documentClass,\n options: sheetOptions,\n });\n },\n unregisterSheet: () => {},\n },\n },\n ux: {},\n instances: new Map(),\n },\n documents: {\n collections: {\n Actors: { registerSheet: () => {}, unregisterSheet: () => {} },\n Items: { registerSheet: () => {}, unregisterSheet: () => {} },\n },\n },\n ...options.foundry,\n };\n scope.game = {\n user,\n userId: user.id,\n ready: true,\n modules: new Map(),\n actors: [],\n items: [],\n i18n: {\n localize: (key: string) => key,\n format: (key: string, data: Record<string, unknown>) => `${key} ${JSON.stringify(data)}`,\n },\n settings: {\n register: (namespace: string, key: string, config: Record<string, unknown>) => {\n settings.push({ namespace, key, config });\n values.set(`${namespace}.${key}`, config.default);\n },\n get: (namespace: string, key: string) => values.get(`${namespace}.${key}`),\n set: async (namespace: string, key: string, value: unknown) => {\n values.set(`${namespace}.${key}`, value);\n return value;\n },\n },\n ...options.game,\n };\n\n return {\n hooks,\n settings,\n notifications,\n sheets,\n enrichers,\n callHook,\n getSetting: (namespace, key) => values.get(`${namespace}.${key}`),\n restore() {\n for (const [name, value] of saved) {\n if (value === undefined) delete scope[name];\n else scope[name] = value;\n }\n },\n };\n}\n"],"mappings":";AAuCA,IAAI,SAAS;;AAGb,SAAS,OAAO,MAAwD;CACtE,MAAM,MAA+B,CAAC;CACtC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,IAAI,GAAG;EAChD,MAAM,QAAQ,KAAK,MAAM,GAAG;EAC5B,MAAM,OAAO,MAAM,IAAI;EACvB,IAAI,CAAC,MAAM;EACX,IAAI,SAAS;EACb,KAAK,MAAM,QAAQ,OAAO;GACxB,OAAO,UAAU,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