@shivaedev/effect-trpc 0.1.1 → 0.2.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 +7 -0
- package/README.md +5 -0
- package/dist/internal/vitest-trpc.d.ts +2 -1
- package/dist/internal/vitest-trpc.d.ts.map +1 -1
- package/dist/internal/vitest-trpc.js +8 -3
- package/dist/internal/vitest-trpc.js.map +1 -1
- package/dist/testing/types.d.ts +19 -9
- package/dist/testing/types.d.ts.map +1 -1
- package/dist/testing/vitest.d.ts +2 -1
- package/dist/testing/vitest.d.ts.map +1 -1
- package/dist/testing/vitest.js +29 -22
- package/dist/testing/vitest.js.map +1 -1
- package/dist/testing.d.ts +2 -2
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
- package/src/internal/vitest-trpc.ts +34 -17
- package/src/testing/types.ts +61 -14
- package/src/testing/vitest.ts +72 -26
- package/src/testing.ts +7 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -140,3 +140,8 @@ The test Layer is built once per worker. Its services override matching
|
|
|
140
140
|
application runtime services while all other runtime services remain available.
|
|
141
141
|
Use `around` to add application-wide test behavior such as a rollback wrapper.
|
|
142
142
|
`effectTRPC` supports `skip`, `skipIf`, `runIf`, `only`, `each`, and `fails`.
|
|
143
|
+
|
|
144
|
+
`makeTrpcHarnessIt` builds an application-defined Effectful harness around the
|
|
145
|
+
caller when tests need additional services or fixtures. The harness is created
|
|
146
|
+
inside both the test Layer and the `around` wrapper, so setup participates in
|
|
147
|
+
the same scoped lifecycle as the test body.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TestContext, TestOptions } from "@effect/vitest";
|
|
2
2
|
import { type Context } from "effect";
|
|
3
|
-
import type { TrpcTester, TrpcTestRuntimeOptions } from "../testing/types.js";
|
|
3
|
+
import type { TrpcHarnessTester, TrpcHarnessTestRuntimeOptions, TrpcTester, TrpcTestRuntimeOptions } from "../testing/types.js";
|
|
4
4
|
export declare const fixtureName = "__effectTrpcContext";
|
|
5
5
|
export type TrpcFixture<Provided> = TestContext & {
|
|
6
6
|
readonly [fixtureName]: Context.Context<Provided>;
|
|
@@ -14,5 +14,6 @@ export interface FixtureTestApi<Provided> {
|
|
|
14
14
|
readonly fails: FixtureTestApi<Provided>;
|
|
15
15
|
readonly for: <Item>(cases: ReadonlyArray<Item>) => (name: string, options: TestOptions, body: (item: Item, context: TrpcFixture<Provided>) => Promise<unknown>) => void;
|
|
16
16
|
}
|
|
17
|
+
export declare const makeTrpcHarnessTester: <Options, Caller extends object, Harness, Provided, LayerError>(fixtureIt: FixtureTestApi<Provided>, options: TrpcHarnessTestRuntimeOptions<Options, Caller, Harness, Provided, LayerError>) => TrpcHarnessTester<Harness, Provided>;
|
|
17
18
|
export declare const makeTrpcTester: <Options, Caller extends object, Provided, LayerError>(fixtureIt: FixtureTestApi<Provided>, options: TrpcTestRuntimeOptions<Options, Caller, Provided, LayerError>) => TrpcTester<Options, Caller, Provided>;
|
|
18
19
|
//# sourceMappingURL=vitest-trpc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest-trpc.d.ts","sourceRoot":"","sources":["../../src/internal/vitest-trpc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAS,KAAK,OAAO,EAAmC,MAAM,QAAQ,CAAC;AAI9E,OAAO,KAAK,EAEX,UAAU,EACV,sBAAsB,EACtB,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,WAAW,wBAAwB,CAAC;AAEjD,MAAM,MAAM,WAAW,CAAC,QAAQ,IAAI,WAAW,GAAG;IACjD,QAAQ,CAAC,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;CAClD,CAAC;AAEF,MAA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,MAAM,qBAAqB,GACjC,OAAO,EACP,MAAM,SAAS,MAAM,EACrB,OAAO,EACP,QAAQ,EACR,UAAU,EAEV,WAAW,cAAc,CAAC,QAAQ,CAAC,EACnC,SAAS,6BAA6B,CACrC,OAAO,EACP,MAAM,EACN,OAAO,EACP,QAAQ,EACR,UAAU,CACV,KACC,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAoHrC,CAAC;AAEF,eAAO,MAAM,cAAc,GAC1B,OAAO,EACP,MAAM,SAAS,MAAM,EACrB,QAAQ,EACR,UAAU,EAEV,WAAW,cAAc,CAAC,QAAQ,CAAC,EACnC,SAAS,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,KACpE,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAIK,CAAC"}
|
|
@@ -16,12 +16,13 @@ const runEffectTest = (effect, context) => Effect.runPromise(Effect.gen(function
|
|
|
16
16
|
}
|
|
17
17
|
return yield* exit;
|
|
18
18
|
}).pipe(Effect.scoped, Effect.provide(TestEnvironment)), { signal: context.signal });
|
|
19
|
-
export const
|
|
19
|
+
export const makeTrpcHarnessTester = (fixtureIt, options) => {
|
|
20
20
|
const run = (body, context) => {
|
|
21
21
|
const program = Effect.gen(function* () {
|
|
22
22
|
const services = yield* Effect.context();
|
|
23
23
|
const trpc = makeEffectCallerFactory(options.adapter, options.createCaller, services);
|
|
24
|
-
|
|
24
|
+
const harness = yield* options.makeHarness(trpc, context);
|
|
25
|
+
return yield* Effect.gen(() => body(harness, context));
|
|
25
26
|
});
|
|
26
27
|
// The body constraint proves every yielded service is part of Provided.
|
|
27
28
|
// TypeScript cannot reduce that generic generator requirement here.
|
|
@@ -60,11 +61,15 @@ export const makeTrpcTester = (fixtureIt, options) => {
|
|
|
60
61
|
expect,
|
|
61
62
|
_local,
|
|
62
63
|
});
|
|
63
|
-
return runEffectTest(run((
|
|
64
|
+
return runEffectTest(run((harness, testContext) => body(item, harness, testContext), context), context);
|
|
64
65
|
}),
|
|
65
66
|
fails: register(current.fails),
|
|
66
67
|
});
|
|
67
68
|
};
|
|
68
69
|
return make(fixtureIt);
|
|
69
70
|
};
|
|
71
|
+
export const makeTrpcTester = (fixtureIt, options) => makeTrpcHarnessTester(fixtureIt, {
|
|
72
|
+
...options,
|
|
73
|
+
makeHarness: (trpc) => Effect.succeed(trpc),
|
|
74
|
+
});
|
|
70
75
|
//# sourceMappingURL=vitest-trpc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest-trpc.js","sourceRoot":"","sources":["../../src/internal/vitest-trpc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAgB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAc,MAAM,QAAQ,CAAC;AAC9E,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,WAAW,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"vitest-trpc.js","sourceRoot":"","sources":["../../src/internal/vitest-trpc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAgB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAc,MAAM,QAAQ,CAAC;AAC9E,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,WAAW,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAS/D,MAAM,CAAC,MAAM,WAAW,GAAG,qBAAqB,CAAC;AA0BjD,MAAM,eAAe,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;AAE7E,MAAM,oBAAoB,GAAG,CAC5B,OAAyC,EAC3B,EAAE,CAChB,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,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,CAAC,SAAS,CAAC,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAM7B,SAAmC,EACnC,OAAsE,EAC9B,EAAE,CAC1C,qBAAqB,CAAC,SAAS,EAAE;IAChC,GAAG,OAAO;IACV,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;CAC3C,CAA0C,CAAC"}
|
package/dist/testing/types.d.ts
CHANGED
|
@@ -2,30 +2,40 @@ import type { TestContext, TestOptions, Vitest } from "@effect/vitest";
|
|
|
2
2
|
import type { Effect, Layer } from "effect";
|
|
3
3
|
import type { EffectTRPCAdapter } from "../adapter.js";
|
|
4
4
|
import type { EffectCallerFactory } from "./caller.js";
|
|
5
|
-
export type
|
|
6
|
-
export interface
|
|
7
|
-
readonly skip:
|
|
8
|
-
readonly skipIf: (condition: unknown) =>
|
|
9
|
-
readonly runIf: (condition: unknown) =>
|
|
10
|
-
readonly only:
|
|
11
|
-
readonly each: <Item>(cases: ReadonlyArray<Item>) => <A, Eff extends Effect.Effect<unknown, unknown, Provided>>(name: string, body: (item: Item,
|
|
12
|
-
readonly fails:
|
|
5
|
+
export type TrpcHarnessTest<Harness, Provided> = <A, Eff extends Effect.Effect<unknown, unknown, Provided>>(name: string, body: (harness: Harness, context: TestContext) => Generator<Eff, A, never>, options?: number | TestOptions) => void;
|
|
6
|
+
export interface TrpcHarnessTester<Harness, Provided> extends TrpcHarnessTest<Harness, Provided> {
|
|
7
|
+
readonly skip: TrpcHarnessTest<Harness, Provided>;
|
|
8
|
+
readonly skipIf: (condition: unknown) => TrpcHarnessTest<Harness, Provided>;
|
|
9
|
+
readonly runIf: (condition: unknown) => TrpcHarnessTest<Harness, Provided>;
|
|
10
|
+
readonly only: TrpcHarnessTest<Harness, Provided>;
|
|
11
|
+
readonly each: <Item>(cases: ReadonlyArray<Item>) => <A, Eff extends Effect.Effect<unknown, unknown, Provided>>(name: string, body: (item: Item, harness: Harness, context: TestContext) => Generator<Eff, A, never>, options?: number | TestOptions) => void;
|
|
12
|
+
readonly fails: TrpcHarnessTest<Harness, Provided>;
|
|
13
13
|
}
|
|
14
|
+
export type TrpcTest<Options, Caller, Provided> = TrpcHarnessTest<EffectCallerFactory<Options, Caller>, Provided>;
|
|
15
|
+
export type TrpcTester<Options, Caller, Provided> = TrpcHarnessTester<EffectCallerFactory<Options, Caller>, Provided>;
|
|
14
16
|
export type TrpcIt<Options, Caller, Provided> = Vitest.Methods & {
|
|
15
17
|
readonly effectTRPC: TrpcTester<Options, Caller, Provided>;
|
|
16
18
|
};
|
|
17
|
-
export
|
|
19
|
+
export type TrpcHarnessIt<Harness, Provided> = Vitest.Methods & {
|
|
20
|
+
readonly effectTRPC: TrpcHarnessTester<Harness, Provided>;
|
|
21
|
+
};
|
|
22
|
+
export interface TrpcHarnessTestRuntimeOptions<Options, Caller extends object, Harness, Provided, LayerError> {
|
|
18
23
|
readonly adapter: Pick<EffectTRPCAdapter<never>, "runWithServices">;
|
|
19
24
|
readonly around?: <A, E>(effect: Effect.Effect<A, E, Provided>) => Effect.Effect<A, unknown, Provided>;
|
|
20
25
|
readonly createCaller: (options?: Options) => Caller;
|
|
21
26
|
readonly layer: Layer.Layer<Provided, LayerError>;
|
|
27
|
+
readonly makeHarness: (trpc: EffectCallerFactory<Options, Caller>, context: TestContext) => Effect.Effect<Harness, unknown, Provided>;
|
|
22
28
|
}
|
|
29
|
+
export type TrpcTestRuntimeOptions<Options, Caller extends object, Provided, LayerError> = Omit<TrpcHarnessTestRuntimeOptions<Options, Caller, EffectCallerFactory<Options, Caller>, Provided, LayerError>, "makeHarness">;
|
|
23
30
|
export interface MakeTrpcItOptions<CreateCaller extends (...arguments_: never[]) => object, TestLayer extends Layer.Layer<any, any, never>> {
|
|
24
31
|
readonly adapter: Pick<EffectTRPCAdapter<never>, "runWithServices">;
|
|
25
32
|
readonly around?: <A, E>(effect: Effect.Effect<A, E, Layer.Success<TestLayer>>) => Effect.Effect<A, unknown, Layer.Success<TestLayer>>;
|
|
26
33
|
readonly createCaller: CreateCaller;
|
|
27
34
|
readonly layer: TestLayer;
|
|
28
35
|
}
|
|
36
|
+
export interface MakeTrpcHarnessItOptions<CreateCaller extends (...arguments_: never[]) => object, TestLayer extends Layer.Layer<any, any, never>, Harness> extends MakeTrpcItOptions<CreateCaller, TestLayer> {
|
|
37
|
+
readonly makeHarness: (trpc: EffectCallerFactory<CallerOptions<CreateCaller>, CallerResult<CreateCaller>>, context: TestContext) => Effect.Effect<Harness, unknown, Layer.Success<TestLayer>>;
|
|
38
|
+
}
|
|
29
39
|
export type CallerOptions<CreateCaller> = CreateCaller extends (...arguments_: infer Arguments) => object ? Arguments[0] : never;
|
|
30
40
|
export type CallerResult<CreateCaller> = CreateCaller extends (...arguments_: infer _Arguments) => infer Caller ? Caller extends object ? Caller : never : never;
|
|
31
41
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/testing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/testing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM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AAS,CAAC,GAAG,UAAU,EAAE,KAAK,EAAE,KAAK,MAAM,EAEvD,SAAS,SAAS,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,EAC9C,OAAO,CACN,SAAQ,iBAAiB,CAAC,YAAY,EAAE,SAAS,CAAC;IACnD,QAAQ,CAAC,WAAW,EAAE,CACrB,IAAI,EAAE,mBAAmB,CACxB,aAAa,CAAC,YAAY,CAAC,EAC3B,YAAY,CAAC,YAAY,CAAC,CAC1B,EACD,OAAO,EAAE,WAAW,KAChB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;CAC/D;AAED,MAAM,MAAM,aAAa,CAAC,YAAY,IAAI,YAAY,SAAS,CAC9D,GAAG,UAAU,EAAE,MAAM,SAAS,KAC1B,MAAM,GACR,SAAS,CAAC,CAAC,CAAC,GACZ,KAAK,CAAC;AAET,MAAM,MAAM,YAAY,CAAC,YAAY,IAAI,YAAY,SAAS,CAC7D,GAAG,UAAU,EAAE,MAAM,UAAU,KAC3B,MAAM,MAAM,GACd,MAAM,SAAS,MAAM,GACpB,MAAM,GACN,KAAK,GACN,KAAK,CAAC"}
|
package/dist/testing/vitest.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
|
-
import type { CallerOptions, CallerResult, MakeTrpcItOptions, TrpcIt } from "./types.js";
|
|
2
|
+
import type { CallerOptions, CallerResult, MakeTrpcHarnessItOptions, MakeTrpcItOptions, TrpcHarnessIt, TrpcIt } from "./types.js";
|
|
3
3
|
export declare const makeTrpcIt: <CreateCaller extends (...arguments_: never[]) => object, TestLayer extends Layer.Layer<any, any, never>>(options: MakeTrpcItOptions<CreateCaller, TestLayer>) => TrpcIt<CallerOptions<CreateCaller>, CallerResult<CreateCaller>, Layer.Success<TestLayer>>;
|
|
4
|
+
export declare const makeTrpcHarnessIt: <CreateCaller extends (...arguments_: never[]) => object, TestLayer extends Layer.Layer<any, any, never>, Harness>(options: MakeTrpcHarnessItOptions<CreateCaller, TestLayer, Harness>) => TrpcHarnessIt<Harness, Layer.Success<TestLayer>>;
|
|
4
5
|
//# sourceMappingURL=vitest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../../src/testing/vitest.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,EAAS,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"vitest.d.ts","sourceRoot":"","sources":["../../src/testing/vitest.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,EAAS,MAAM,QAAQ,CAAC;AAOpD,OAAO,KAAK,EACX,aAAa,EACb,YAAY,EACZ,wBAAwB,EACxB,iBAAiB,EACjB,aAAa,EACb,MAAM,EACN,MAAM,YAAY,CAAC;AAoCpB,eAAO,MAAM,UAAU,GACtB,YAAY,SAAS,CAAC,GAAG,UAAU,EAAE,KAAK,EAAE,KAAK,MAAM,EAEvD,SAAS,SAAS,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,EAE9C,SAAS,iBAAiB,CAAC,YAAY,EAAE,SAAS,CAAC,KACjD,MAAM,CACR,aAAa,CAAC,YAAY,CAAC,EAC3B,YAAY,CAAC,YAAY,CAAC,EAC1B,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAkBxB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC7B,YAAY,SAAS,CAAC,GAAG,UAAU,EAAE,KAAK,EAAE,KAAK,MAAM,EAEvD,SAAS,SAAS,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,EAC9C,OAAO,EAEP,SAAS,wBAAwB,CAAC,YAAY,EAAE,SAAS,EAAE,OAAO,CAAC,KACjE,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAsBjD,CAAC"}
|
package/dist/testing/vitest.js
CHANGED
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
import { it as effectIt } from "@effect/vitest";
|
|
2
2
|
import { Effect, Exit, Layer, Scope } from "effect";
|
|
3
|
-
import { fixtureName, makeTrpcTester, } from "../internal/vitest-trpc.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
import { fixtureName, makeTrpcHarnessTester, makeTrpcTester, } from "../internal/vitest-trpc.js";
|
|
4
|
+
const makeFixtureIt = (layer) => effectIt.extend(fixtureName, { scope: "worker" },
|
|
5
|
+
// biome-ignore lint/correctness/noEmptyPattern: Vitest fixtures require a destructured context parameter.
|
|
6
|
+
async ({}, { onCleanup }) => {
|
|
7
|
+
const scope = Effect.runSync(Scope.make());
|
|
8
|
+
onCleanup(() => Effect.runPromise(Scope.close(scope, Exit.void)));
|
|
9
|
+
try {
|
|
10
|
+
return await Effect.runPromise(Layer.buildWithScope(layer, scope));
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
await Effect.runPromise(Scope.close(scope, Exit.void));
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const withEffectTRPC = (tester) => new Proxy(effectIt, {
|
|
18
|
+
get(target, property, receiver) {
|
|
19
|
+
if (property === "effectTRPC") {
|
|
20
|
+
return tester;
|
|
16
21
|
}
|
|
17
|
-
|
|
22
|
+
return Reflect.get(target, property, receiver);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
export const makeTrpcIt = (options) => {
|
|
26
|
+
const fixtureIt = makeFixtureIt(options.layer);
|
|
18
27
|
const effectTRPC = makeTrpcTester(fixtureIt, options);
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
});
|
|
28
|
+
return withEffectTRPC(effectTRPC);
|
|
29
|
+
};
|
|
30
|
+
export const makeTrpcHarnessIt = (options) => {
|
|
31
|
+
const fixtureIt = makeFixtureIt(options.layer);
|
|
32
|
+
const effectTRPC = makeTrpcHarnessTester(fixtureIt, options);
|
|
33
|
+
return withEffectTRPC(effectTRPC);
|
|
27
34
|
};
|
|
28
35
|
//# sourceMappingURL=vitest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.js","sourceRoot":"","sources":["../../src/testing/vitest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,QAAQ,
|
|
1
|
+
{"version":3,"file":"vitest.js","sourceRoot":"","sources":["../../src/testing/vitest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,QAAQ,EAAe,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,EAEN,WAAW,EACX,qBAAqB,EACrB,cAAc,GACd,MAAM,4BAA4B,CAAC;AAUpC,MAAM,aAAa,GAAG,CACrB,KAAwC,EACb,EAAE,CAC7B,QAAQ,CAAC,MAAM,CACd,WAAW,EACX,EAAE,KAAK,EAAE,QAAQ,EAAE;AACnB,0GAA0G;AAC1G,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;IAC3B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3C,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAElE,IAAI,CAAC;QACJ,OAAO,MAAM,MAAM,CAAC,UAAU,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} from "./testing/caller.js";
|
|
2
|
-
export type { MakeTrpcItOptions, TrpcIt, TrpcTest, TrpcTester, } from "./testing/types.js";
|
|
3
|
-
export { makeTrpcIt } from "./testing/vitest.js";
|
|
2
|
+
export type { CallerOptions, CallerResult, MakeTrpcHarnessItOptions, MakeTrpcItOptions, TrpcHarnessIt, TrpcHarnessTest, TrpcHarnessTester, TrpcIt, TrpcTest, TrpcTester, } from "./testing/types.js";
|
|
3
|
+
export { makeTrpcHarnessIt, makeTrpcIt } from "./testing/vitest.js";
|
|
4
4
|
//# sourceMappingURL=testing.d.ts.map
|
package/dist/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,gBAAgB,EAChB,uBAAuB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACX,iBAAiB,EACjB,MAAM,EACN,QAAQ,EACR,UAAU,GACV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,gBAAgB,EAChB,uBAAuB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACX,aAAa,EACb,YAAY,EACZ,wBAAwB,EACxB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,MAAM,EACN,QAAQ,EACR,UAAU,GACV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/testing.js
CHANGED
package/dist/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,gBAAgB,EAChB,uBAAuB,GACvB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,gBAAgB,EAChB,uBAAuB,GACvB,MAAM,qBAAqB,CAAC;AAa7B,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,9 @@ import * as TestClock from "effect/testing/TestClock";
|
|
|
4
4
|
import * as TestConsole from "effect/testing/TestConsole";
|
|
5
5
|
import { makeEffectCallerFactory } from "../testing/caller.js";
|
|
6
6
|
import type {
|
|
7
|
-
|
|
7
|
+
TrpcHarnessTest,
|
|
8
|
+
TrpcHarnessTester,
|
|
9
|
+
TrpcHarnessTestRuntimeOptions,
|
|
8
10
|
TrpcTester,
|
|
9
11
|
TrpcTestRuntimeOptions,
|
|
10
12
|
} from "../testing/types.js";
|
|
@@ -69,22 +71,24 @@ const runEffectTest = <A, E>(
|
|
|
69
71
|
{ signal: context.signal },
|
|
70
72
|
);
|
|
71
73
|
|
|
72
|
-
export const
|
|
74
|
+
export const makeTrpcHarnessTester = <
|
|
73
75
|
Options,
|
|
74
76
|
Caller extends object,
|
|
77
|
+
Harness,
|
|
75
78
|
Provided,
|
|
76
79
|
LayerError,
|
|
77
80
|
>(
|
|
78
81
|
fixtureIt: FixtureTestApi<Provided>,
|
|
79
|
-
options:
|
|
80
|
-
|
|
82
|
+
options: TrpcHarnessTestRuntimeOptions<
|
|
83
|
+
Options,
|
|
84
|
+
Caller,
|
|
85
|
+
Harness,
|
|
86
|
+
Provided,
|
|
87
|
+
LayerError
|
|
88
|
+
>,
|
|
89
|
+
): TrpcHarnessTester<Harness, Provided> => {
|
|
81
90
|
const run = <A, Eff extends Effect.Effect<unknown, unknown, Provided>>(
|
|
82
|
-
body: (
|
|
83
|
-
trpc: ReturnType<
|
|
84
|
-
typeof makeEffectCallerFactory<Options, Caller, Provided>
|
|
85
|
-
>,
|
|
86
|
-
context: TestContext,
|
|
87
|
-
) => Generator<Eff, A, never>,
|
|
91
|
+
body: (harness: Harness, context: TestContext) => Generator<Eff, A, never>,
|
|
88
92
|
context: TestContext,
|
|
89
93
|
): Effect.Effect<A, unknown, Scope.Scope> => {
|
|
90
94
|
const program = Effect.gen(function* () {
|
|
@@ -94,7 +98,8 @@ export const makeTrpcTester = <
|
|
|
94
98
|
options.createCaller,
|
|
95
99
|
services,
|
|
96
100
|
);
|
|
97
|
-
|
|
101
|
+
const harness = yield* options.makeHarness(trpc, context);
|
|
102
|
+
return yield* Effect.gen(() => body(harness, context));
|
|
98
103
|
});
|
|
99
104
|
// The body constraint proves every yielded service is part of Provided.
|
|
100
105
|
// TypeScript cannot reduce that generic generator requirement here.
|
|
@@ -106,7 +111,7 @@ export const makeTrpcTester = <
|
|
|
106
111
|
};
|
|
107
112
|
|
|
108
113
|
const register =
|
|
109
|
-
(current: FixtureTestApi<Provided>):
|
|
114
|
+
(current: FixtureTestApi<Provided>): TrpcHarnessTest<Harness, Provided> =>
|
|
110
115
|
(name, body, testOptions) =>
|
|
111
116
|
current(
|
|
112
117
|
name,
|
|
@@ -138,7 +143,7 @@ export const makeTrpcTester = <
|
|
|
138
143
|
|
|
139
144
|
const make = (
|
|
140
145
|
current: FixtureTestApi<Provided>,
|
|
141
|
-
):
|
|
146
|
+
): TrpcHarnessTester<Harness, Provided> => {
|
|
142
147
|
const test = register(current);
|
|
143
148
|
return Object.assign(test, {
|
|
144
149
|
skip: register(current.skip),
|
|
@@ -151,9 +156,7 @@ export const makeTrpcTester = <
|
|
|
151
156
|
name: string,
|
|
152
157
|
body: (
|
|
153
158
|
item: Item,
|
|
154
|
-
|
|
155
|
-
typeof makeEffectCallerFactory<Options, Caller, Provided>
|
|
156
|
-
>,
|
|
159
|
+
harness: Harness,
|
|
157
160
|
context: TestContext,
|
|
158
161
|
) => Generator<Eff, A, never>,
|
|
159
162
|
testOptions?: number | TestOptions,
|
|
@@ -187,7 +190,7 @@ export const makeTrpcTester = <
|
|
|
187
190
|
});
|
|
188
191
|
return runEffectTest(
|
|
189
192
|
run(
|
|
190
|
-
(
|
|
193
|
+
(harness, testContext) => body(item, harness, testContext),
|
|
191
194
|
context,
|
|
192
195
|
),
|
|
193
196
|
context,
|
|
@@ -200,3 +203,17 @@ export const makeTrpcTester = <
|
|
|
200
203
|
|
|
201
204
|
return make(fixtureIt);
|
|
202
205
|
};
|
|
206
|
+
|
|
207
|
+
export const makeTrpcTester = <
|
|
208
|
+
Options,
|
|
209
|
+
Caller extends object,
|
|
210
|
+
Provided,
|
|
211
|
+
LayerError,
|
|
212
|
+
>(
|
|
213
|
+
fixtureIt: FixtureTestApi<Provided>,
|
|
214
|
+
options: TrpcTestRuntimeOptions<Options, Caller, Provided, LayerError>,
|
|
215
|
+
): TrpcTester<Options, Caller, Provided> =>
|
|
216
|
+
makeTrpcHarnessTester(fixtureIt, {
|
|
217
|
+
...options,
|
|
218
|
+
makeHarness: (trpc) => Effect.succeed(trpc),
|
|
219
|
+
}) as TrpcTester<Options, Caller, Provided>;
|
package/src/testing/types.ts
CHANGED
|
@@ -3,45 +3,57 @@ import type { Effect, Layer } from "effect";
|
|
|
3
3
|
import type { EffectTRPCAdapter } from "../adapter.js";
|
|
4
4
|
import type { EffectCallerFactory } from "./caller.js";
|
|
5
5
|
|
|
6
|
-
export type
|
|
6
|
+
export type TrpcHarnessTest<Harness, Provided> = <
|
|
7
7
|
A,
|
|
8
8
|
Eff extends Effect.Effect<unknown, unknown, Provided>,
|
|
9
9
|
>(
|
|
10
10
|
name: string,
|
|
11
|
-
body: (
|
|
12
|
-
trpc: EffectCallerFactory<Options, Caller>,
|
|
13
|
-
context: TestContext,
|
|
14
|
-
) => Generator<Eff, A, never>,
|
|
11
|
+
body: (harness: Harness, context: TestContext) => Generator<Eff, A, never>,
|
|
15
12
|
options?: number | TestOptions,
|
|
16
13
|
) => void;
|
|
17
14
|
|
|
18
|
-
export interface
|
|
19
|
-
extends
|
|
20
|
-
readonly skip:
|
|
21
|
-
readonly skipIf: (condition: unknown) =>
|
|
22
|
-
readonly runIf: (condition: unknown) =>
|
|
23
|
-
readonly only:
|
|
15
|
+
export interface TrpcHarnessTester<Harness, Provided>
|
|
16
|
+
extends TrpcHarnessTest<Harness, Provided> {
|
|
17
|
+
readonly skip: TrpcHarnessTest<Harness, Provided>;
|
|
18
|
+
readonly skipIf: (condition: unknown) => TrpcHarnessTest<Harness, Provided>;
|
|
19
|
+
readonly runIf: (condition: unknown) => TrpcHarnessTest<Harness, Provided>;
|
|
20
|
+
readonly only: TrpcHarnessTest<Harness, Provided>;
|
|
24
21
|
readonly each: <Item>(
|
|
25
22
|
cases: ReadonlyArray<Item>,
|
|
26
23
|
) => <A, Eff extends Effect.Effect<unknown, unknown, Provided>>(
|
|
27
24
|
name: string,
|
|
28
25
|
body: (
|
|
29
26
|
item: Item,
|
|
30
|
-
|
|
27
|
+
harness: Harness,
|
|
31
28
|
context: TestContext,
|
|
32
29
|
) => Generator<Eff, A, never>,
|
|
33
30
|
options?: number | TestOptions,
|
|
34
31
|
) => void;
|
|
35
|
-
readonly fails:
|
|
32
|
+
readonly fails: TrpcHarnessTest<Harness, Provided>;
|
|
36
33
|
}
|
|
37
34
|
|
|
35
|
+
export type TrpcTest<Options, Caller, Provided> = TrpcHarnessTest<
|
|
36
|
+
EffectCallerFactory<Options, Caller>,
|
|
37
|
+
Provided
|
|
38
|
+
>;
|
|
39
|
+
|
|
40
|
+
export type TrpcTester<Options, Caller, Provided> = TrpcHarnessTester<
|
|
41
|
+
EffectCallerFactory<Options, Caller>,
|
|
42
|
+
Provided
|
|
43
|
+
>;
|
|
44
|
+
|
|
38
45
|
export type TrpcIt<Options, Caller, Provided> = Vitest.Methods & {
|
|
39
46
|
readonly effectTRPC: TrpcTester<Options, Caller, Provided>;
|
|
40
47
|
};
|
|
41
48
|
|
|
42
|
-
export
|
|
49
|
+
export type TrpcHarnessIt<Harness, Provided> = Vitest.Methods & {
|
|
50
|
+
readonly effectTRPC: TrpcHarnessTester<Harness, Provided>;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export interface TrpcHarnessTestRuntimeOptions<
|
|
43
54
|
Options,
|
|
44
55
|
Caller extends object,
|
|
56
|
+
Harness,
|
|
45
57
|
Provided,
|
|
46
58
|
LayerError,
|
|
47
59
|
> {
|
|
@@ -51,8 +63,28 @@ export interface TrpcTestRuntimeOptions<
|
|
|
51
63
|
) => Effect.Effect<A, unknown, Provided>;
|
|
52
64
|
readonly createCaller: (options?: Options) => Caller;
|
|
53
65
|
readonly layer: Layer.Layer<Provided, LayerError>;
|
|
66
|
+
readonly makeHarness: (
|
|
67
|
+
trpc: EffectCallerFactory<Options, Caller>,
|
|
68
|
+
context: TestContext,
|
|
69
|
+
) => Effect.Effect<Harness, unknown, Provided>;
|
|
54
70
|
}
|
|
55
71
|
|
|
72
|
+
export type TrpcTestRuntimeOptions<
|
|
73
|
+
Options,
|
|
74
|
+
Caller extends object,
|
|
75
|
+
Provided,
|
|
76
|
+
LayerError,
|
|
77
|
+
> = Omit<
|
|
78
|
+
TrpcHarnessTestRuntimeOptions<
|
|
79
|
+
Options,
|
|
80
|
+
Caller,
|
|
81
|
+
EffectCallerFactory<Options, Caller>,
|
|
82
|
+
Provided,
|
|
83
|
+
LayerError
|
|
84
|
+
>,
|
|
85
|
+
"makeHarness"
|
|
86
|
+
>;
|
|
87
|
+
|
|
56
88
|
export interface MakeTrpcItOptions<
|
|
57
89
|
CreateCaller extends (...arguments_: never[]) => object,
|
|
58
90
|
// biome-ignore lint/suspicious/noExplicitAny: Layer output and error are recovered with Layer utility types
|
|
@@ -66,6 +98,21 @@ export interface MakeTrpcItOptions<
|
|
|
66
98
|
readonly layer: TestLayer;
|
|
67
99
|
}
|
|
68
100
|
|
|
101
|
+
export interface MakeTrpcHarnessItOptions<
|
|
102
|
+
CreateCaller extends (...arguments_: never[]) => object,
|
|
103
|
+
// biome-ignore lint/suspicious/noExplicitAny: Layer output and error are recovered with Layer utility types
|
|
104
|
+
TestLayer extends Layer.Layer<any, any, never>,
|
|
105
|
+
Harness,
|
|
106
|
+
> extends MakeTrpcItOptions<CreateCaller, TestLayer> {
|
|
107
|
+
readonly makeHarness: (
|
|
108
|
+
trpc: EffectCallerFactory<
|
|
109
|
+
CallerOptions<CreateCaller>,
|
|
110
|
+
CallerResult<CreateCaller>
|
|
111
|
+
>,
|
|
112
|
+
context: TestContext,
|
|
113
|
+
) => Effect.Effect<Harness, unknown, Layer.Success<TestLayer>>;
|
|
114
|
+
}
|
|
115
|
+
|
|
69
116
|
export type CallerOptions<CreateCaller> = CreateCaller extends (
|
|
70
117
|
...arguments_: infer Arguments
|
|
71
118
|
) => object
|
package/src/testing/vitest.ts
CHANGED
|
@@ -1,17 +1,54 @@
|
|
|
1
|
-
import { it as effectIt } from "@effect/vitest";
|
|
1
|
+
import { it as effectIt, type Vitest } from "@effect/vitest";
|
|
2
2
|
import { Effect, Exit, Layer, Scope } from "effect";
|
|
3
3
|
import {
|
|
4
4
|
type FixtureTestApi,
|
|
5
5
|
fixtureName,
|
|
6
|
+
makeTrpcHarnessTester,
|
|
6
7
|
makeTrpcTester,
|
|
7
8
|
} from "../internal/vitest-trpc.js";
|
|
8
9
|
import type {
|
|
9
10
|
CallerOptions,
|
|
10
11
|
CallerResult,
|
|
12
|
+
MakeTrpcHarnessItOptions,
|
|
11
13
|
MakeTrpcItOptions,
|
|
14
|
+
TrpcHarnessIt,
|
|
12
15
|
TrpcIt,
|
|
13
16
|
} from "./types.js";
|
|
14
17
|
|
|
18
|
+
const makeFixtureIt = <Provided, LayerError>(
|
|
19
|
+
layer: Layer.Layer<Provided, LayerError>,
|
|
20
|
+
): FixtureTestApi<Provided> =>
|
|
21
|
+
effectIt.extend(
|
|
22
|
+
fixtureName,
|
|
23
|
+
{ scope: "worker" },
|
|
24
|
+
// biome-ignore lint/correctness/noEmptyPattern: Vitest fixtures require a destructured context parameter.
|
|
25
|
+
async ({}, { onCleanup }) => {
|
|
26
|
+
const scope = Effect.runSync(Scope.make());
|
|
27
|
+
onCleanup(() => Effect.runPromise(Scope.close(scope, Exit.void)));
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
return await Effect.runPromise(Layer.buildWithScope(layer, scope));
|
|
31
|
+
} catch (error) {
|
|
32
|
+
await Effect.runPromise(Scope.close(scope, Exit.void));
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
) as unknown as FixtureTestApi<Provided>;
|
|
37
|
+
|
|
38
|
+
const withEffectTRPC = <Tester>(
|
|
39
|
+
tester: Tester,
|
|
40
|
+
): Vitest.Methods & {
|
|
41
|
+
readonly effectTRPC: Tester;
|
|
42
|
+
} =>
|
|
43
|
+
new Proxy(effectIt, {
|
|
44
|
+
get(target, property, receiver) {
|
|
45
|
+
if (property === "effectTRPC") {
|
|
46
|
+
return tester;
|
|
47
|
+
}
|
|
48
|
+
return Reflect.get(target, property, receiver);
|
|
49
|
+
},
|
|
50
|
+
}) as Vitest.Methods & { readonly effectTRPC: Tester };
|
|
51
|
+
|
|
15
52
|
export const makeTrpcIt = <
|
|
16
53
|
CreateCaller extends (...arguments_: never[]) => object,
|
|
17
54
|
// biome-ignore lint/suspicious/noExplicitAny: Layer output and error are recovered with Layer utility types
|
|
@@ -27,23 +64,8 @@ export const makeTrpcIt = <
|
|
|
27
64
|
type Caller = CallerResult<CreateCaller>;
|
|
28
65
|
type Provided = Layer.Success<TestLayer>;
|
|
29
66
|
|
|
30
|
-
const fixtureIt =
|
|
31
|
-
|
|
32
|
-
{ scope: "worker" },
|
|
33
|
-
// biome-ignore lint/correctness/noEmptyPattern: Vitest fixtures require a destructured context parameter.
|
|
34
|
-
async ({}, { onCleanup }) => {
|
|
35
|
-
const scope = Effect.runSync(Scope.make());
|
|
36
|
-
onCleanup(() => Effect.runPromise(Scope.close(scope, Exit.void)));
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
return await Effect.runPromise(
|
|
40
|
-
Layer.buildWithScope(options.layer, scope),
|
|
41
|
-
);
|
|
42
|
-
} catch (error) {
|
|
43
|
-
await Effect.runPromise(Scope.close(scope, Exit.void));
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
},
|
|
67
|
+
const fixtureIt = makeFixtureIt<Provided, Layer.Error<TestLayer>>(
|
|
68
|
+
options.layer,
|
|
47
69
|
);
|
|
48
70
|
|
|
49
71
|
const effectTRPC = makeTrpcTester(
|
|
@@ -53,12 +75,36 @@ export const makeTrpcIt = <
|
|
|
53
75
|
>[1],
|
|
54
76
|
);
|
|
55
77
|
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
return withEffectTRPC(effectTRPC) as TrpcIt<Options, Caller, Provided>;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const makeTrpcHarnessIt = <
|
|
82
|
+
CreateCaller extends (...arguments_: never[]) => object,
|
|
83
|
+
// biome-ignore lint/suspicious/noExplicitAny: Layer output and error are recovered with Layer utility types
|
|
84
|
+
TestLayer extends Layer.Layer<any, any, never>,
|
|
85
|
+
Harness,
|
|
86
|
+
>(
|
|
87
|
+
options: MakeTrpcHarnessItOptions<CreateCaller, TestLayer, Harness>,
|
|
88
|
+
): TrpcHarnessIt<Harness, Layer.Success<TestLayer>> => {
|
|
89
|
+
type Options = CallerOptions<CreateCaller>;
|
|
90
|
+
type Caller = CallerResult<CreateCaller>;
|
|
91
|
+
type Provided = Layer.Success<TestLayer>;
|
|
92
|
+
|
|
93
|
+
const fixtureIt = makeFixtureIt<Provided, Layer.Error<TestLayer>>(
|
|
94
|
+
options.layer,
|
|
95
|
+
);
|
|
96
|
+
const effectTRPC = makeTrpcHarnessTester(
|
|
97
|
+
fixtureIt,
|
|
98
|
+
options as unknown as Parameters<
|
|
99
|
+
typeof makeTrpcHarnessTester<
|
|
100
|
+
Options,
|
|
101
|
+
Caller,
|
|
102
|
+
Harness,
|
|
103
|
+
Provided,
|
|
104
|
+
Layer.Error<TestLayer>
|
|
105
|
+
>
|
|
106
|
+
>[1],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
return withEffectTRPC(effectTRPC);
|
|
64
110
|
};
|
package/src/testing.ts
CHANGED
|
@@ -5,9 +5,15 @@ export {
|
|
|
5
5
|
makeEffectCallerFactory,
|
|
6
6
|
} from "./testing/caller.js";
|
|
7
7
|
export type {
|
|
8
|
+
CallerOptions,
|
|
9
|
+
CallerResult,
|
|
10
|
+
MakeTrpcHarnessItOptions,
|
|
8
11
|
MakeTrpcItOptions,
|
|
12
|
+
TrpcHarnessIt,
|
|
13
|
+
TrpcHarnessTest,
|
|
14
|
+
TrpcHarnessTester,
|
|
9
15
|
TrpcIt,
|
|
10
16
|
TrpcTest,
|
|
11
17
|
TrpcTester,
|
|
12
18
|
} from "./testing/types.js";
|
|
13
|
-
export { makeTrpcIt } from "./testing/vitest.js";
|
|
19
|
+
export { makeTrpcHarnessIt, makeTrpcIt } from "./testing/vitest.js";
|