@absolutejs/sync 1.9.0 → 1.9.2
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/dist/engine/cdc.d.ts +2 -2
- package/dist/engine/index.js +69 -59
- package/dist/engine/index.js.map +3 -3
- package/dist/index.js +71 -63
- package/dist/index.js.map +4 -4
- package/dist/testing.d.ts +53 -0
- package/dist/testing.js +1938 -0
- package/dist/testing.js.map +17 -0
- package/package.json +6 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@absolutejs/sync/testing` — small helpers for testing sync engines and
|
|
3
|
+
* sync packs. Importable from a focused subpath so pack repos don't pull
|
|
4
|
+
* the whole sync barrel into their test surface area.
|
|
5
|
+
*
|
|
6
|
+
* What's here is intentionally tiny. Sync's own tests use
|
|
7
|
+
* `createSyncEngine` directly, and that's still the right call for engine-
|
|
8
|
+
* internal tests. This subpath is for *pack* tests and *consumer* tests
|
|
9
|
+
* where the boilerplate of "boot an engine, expect an async throw, drive
|
|
10
|
+
* a mutation with a labelled actor" repeats across every file.
|
|
11
|
+
*
|
|
12
|
+
* No new test framework is introduced — these are plain helpers you can
|
|
13
|
+
* use with `bun:test`, `vitest`, or anything else.
|
|
14
|
+
*/
|
|
15
|
+
import { type SyncEngine, type SyncEngineOptions } from './engine/syncEngine';
|
|
16
|
+
/**
|
|
17
|
+
* Construct a {@link SyncEngine} for tests. Today this is a documented
|
|
18
|
+
* re-export of {@link createSyncEngine} — the wrapper exists so callers
|
|
19
|
+
* can clearly signal "this engine is test-scoped" at the call site, and
|
|
20
|
+
* so future test-mode defaults (e.g. a synchronous in-memory transaction
|
|
21
|
+
* runner) can be added without churning every test.
|
|
22
|
+
*
|
|
23
|
+
* Pass options through if you need a real transaction runner, schemas,
|
|
24
|
+
* permissions, etc. — same shape as {@link createSyncEngine}.
|
|
25
|
+
*/
|
|
26
|
+
export declare const createTestEngine: (options?: SyncEngineOptions) => SyncEngine;
|
|
27
|
+
/**
|
|
28
|
+
* Await `work` and return the thrown value. Throws if `work` resolves —
|
|
29
|
+
* use it inside tests that expect a specific rejection without relying
|
|
30
|
+
* on `expect(...).rejects.toThrow(...)`, which has been flaky on Bun
|
|
31
|
+
* 1.3.x (oven-sh/bun#31462). Equivalent to the `rejection()` helper
|
|
32
|
+
* sync's own tests use.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const error = await expectRejection(() =>
|
|
36
|
+
* engine.runMutation('comments:edit', { commentId, body }, { userId: 'eve' }),
|
|
37
|
+
* );
|
|
38
|
+
* expect((error as Error).message).toMatch(/not author/);
|
|
39
|
+
*/
|
|
40
|
+
export declare const expectRejection: (work: () => unknown) => Promise<unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Convenience: call `engine.runMutation` with an actor-id-shaped ctx.
|
|
43
|
+
* Matches the standard pack convention (`getActorId: (ctx) => ctx.userId`).
|
|
44
|
+
* Tests that don't need to vary other ctx fields can avoid the
|
|
45
|
+
* `{ userId: 'alice' }` boilerplate.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* await runAsActor(engine, 'alice', 'comments:create', {
|
|
49
|
+
* resourceId: 'doc-1',
|
|
50
|
+
* body: 'first',
|
|
51
|
+
* });
|
|
52
|
+
*/
|
|
53
|
+
export declare const runAsActor: (engine: SyncEngine, actorId: string, mutation: string, args: unknown, extraCtx?: Record<string, unknown>) => Promise<unknown>;
|