test(httpapi): add route exerciser
This commit is contained in:
@@ -3,8 +3,24 @@ import { Cause, Effect, Exit, Layer } from "effect"
|
||||
import type * as Scope from "effect/Scope"
|
||||
import * as TestClock from "effect/testing/TestClock"
|
||||
import * as TestConsole from "effect/testing/TestConsole"
|
||||
import type { Config } from "@/config/config"
|
||||
import { TestInstance, withTmpdirInstance } from "../fixture/fixture"
|
||||
|
||||
type Body<A, E, R> = Effect.Effect<A, E, R> | (() => Effect.Effect<A, E, R>)
|
||||
type InstanceOptions = { git?: boolean; config?: Partial<Config.Info> }
|
||||
|
||||
function isInstanceOptions(options: InstanceOptions | number | TestOptions | undefined): options is InstanceOptions {
|
||||
return !!options && typeof options === "object" && ("git" in options || "config" in options)
|
||||
}
|
||||
|
||||
function instanceArgs(
|
||||
options?: InstanceOptions | number | TestOptions,
|
||||
testOptions?: number | TestOptions,
|
||||
): { instanceOptions: InstanceOptions | undefined; testOptions: number | TestOptions | undefined } {
|
||||
if (typeof options === "number") return { instanceOptions: undefined, testOptions: options }
|
||||
if (isInstanceOptions(options)) return { instanceOptions: options, testOptions }
|
||||
return { instanceOptions: undefined, testOptions: options }
|
||||
}
|
||||
|
||||
const body = <A, E, R>(value: Body<A, E, R>) => Effect.suspend(() => (typeof value === "function" ? value() : value))
|
||||
|
||||
@@ -38,7 +54,37 @@ const make = <R, E>(testLayer: Layer.Layer<R, E>, liveLayer: Layer.Layer<R, E>)
|
||||
live.skip = <A, E2>(name: string, value: Body<A, E2, R | Scope.Scope>, opts?: number | TestOptions) =>
|
||||
test.skip(name, () => run(value, liveLayer), opts)
|
||||
|
||||
return { effect, live }
|
||||
const instance = <A, E2>(
|
||||
name: string,
|
||||
value: Body<A, E2, R | TestInstance | Scope.Scope>,
|
||||
options?: InstanceOptions | number | TestOptions,
|
||||
opts?: number | TestOptions,
|
||||
) => {
|
||||
const args = instanceArgs(options, opts)
|
||||
return test(name, () => run(body(value).pipe(withTmpdirInstance(args.instanceOptions)), liveLayer), args.testOptions)
|
||||
}
|
||||
|
||||
instance.only = <A, E2>(
|
||||
name: string,
|
||||
value: Body<A, E2, R | TestInstance | Scope.Scope>,
|
||||
options?: InstanceOptions | number | TestOptions,
|
||||
opts?: number | TestOptions,
|
||||
) => {
|
||||
const args = instanceArgs(options, opts)
|
||||
return test.only(name, () => run(body(value).pipe(withTmpdirInstance(args.instanceOptions)), liveLayer), args.testOptions)
|
||||
}
|
||||
|
||||
instance.skip = <A, E2>(
|
||||
name: string,
|
||||
value: Body<A, E2, R | TestInstance | Scope.Scope>,
|
||||
options?: InstanceOptions | number | TestOptions,
|
||||
opts?: number | TestOptions,
|
||||
) => {
|
||||
const args = instanceArgs(options, opts)
|
||||
return test.skip(name, () => run(body(value).pipe(withTmpdirInstance(args.instanceOptions)), liveLayer), args.testOptions)
|
||||
}
|
||||
|
||||
return { effect, live, instance }
|
||||
}
|
||||
|
||||
// Test environment with TestClock and TestConsole
|
||||
|
||||
Reference in New Issue
Block a user