Skip to content

Instantly share code, notes, and snippets.

@rumkin
Created October 20, 2021 02:20
Show Gist options
  • Save rumkin/2635982309381121d1ba8f606c776cb9 to your computer and use it in GitHub Desktop.
Save rumkin/2635982309381121d1ba8f606c776cb9 to your computer and use it in GitHub Desktop.
Testup typescript setup

Instruction

  1. Create test dir in the root of the project.
  2. Put tsconfig.json into test folder.
  3. Put testup.d.ts into test folder.
  4. Create test scenario like in index.spec.ts.
export default ({define, it}: Testup.ScriptScope) => {
}
export interface DescribeFn {
(label: string, handler: ScriptFn): void
}
export interface ItFn {
(label: string, ...spec: [...ModifierFn[], TestCaseFn]): void
}
export interface UseFn {
(modifier: ModifierFn): void
}
export interface EachFn {
(modifiers: ModifierFn): void
}
export interface Test {
delay(timeout: number): Promise<void>
end():void
}
export type TestCtx = Record<string|symbol, any>
export interface TestCaseFn {
(context: TestCtx, test: Test): void
}
export interface ModifierFn {
(context: TestCtx, next: () => Promise<void>): void|Promise<void>
}
export interface ScriptFn {
(scope: ScriptScope): void
}
export interface ScriptScope {
define: DescribeFn;
use: UseFn;
each: EachFn;
it: ItFn;
}
// Reexport ScriptScope
type _ScriptScope = ScriptScope
declare namespace Testup {
export interface ScriptScope extends _ScriptScope {}
}
{
"files": [
"./testup.d.ts",
],
"include": ["**/*.spec.ts"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment