Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
fix: made syntax typedoc compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 21, 2018
1 parent 392e497 commit ec27d0b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
27 changes: 23 additions & 4 deletions src/stdmock.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
import * as mock from 'stdout-stderr'

export interface Stdout {
before(): {stdout: string}
after(): void
catch(): void
finally(): void
}

export interface Stderr {
before(): {stderr: string}
after(): void
catch(): void
finally(): void
}

const create = <T extends 'stdout' | 'stderr'>(std: T) => () => {
const _finally = () => mock[std].stop()
return {
before() {
mock[std].start()
if (std === 'stdout') {
return {
get stdout() { return mock.stdout.output }
}
}
return {
get [std]() { return mock[std].output }
} as {[P in T]: string}
get stderr() { return mock.stderr.output }
}
},
after: _finally,
catch: _finally,
finally: _finally,
}
}

export const stdout = create('stdout')
export const stderr = create('stderr')
export const stdout = create('stdout') as () => Stdout
export const stderr = create('stderr') as () => Stderr
10 changes: 5 additions & 5 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import env from './env'
import mock from './mock'
import {stderr, stdout} from './stdmock'

export type Extension<O extends object, A1, A2, A3, A4> = (a1: A1, a2: A2, a3: A3, a4: A4) => Filters<O>
export type Extension<O extends object, A1 = void, A2 = void, A3 = void, A4 = void> = (a1: A1, a2: A2, a3: A3, a4: A4) => Filters<O>
export interface Filters<C extends object> {
before?(input: any): Promise<C> | C | void
after?(context: C): Promise<any> | any
Expand Down Expand Up @@ -62,10 +62,10 @@ export interface TestBase<E extends Extensions, C = {}> {
* }
* })
*/
extend<K extends string, O extends object>(key: K, filter: Extension<O, void, void, void, void>): Test<AddExtension0<E, K, O>, C>
extend<K extends string, O extends object, A1>(key: K, filter: Extension<O, A1, void, void, void>): Test<AddExtension1<E, K, O, A1>, C>
extend<K extends string, O extends object, A1, A2>(key: K, filter: Extension<O, A1, A2, void, void>): Test<AddExtension2<E, K, O, A1, A2>, C>
extend<K extends string, O extends object, A1, A2, A3>(key: K, filter: Extension<O, A1, A2, A3, void>): Test<AddExtension3<E, K, O, A1, A2, A3>, C>
extend<K extends string, O extends object>(key: K, filter: Extension<O>): Test<AddExtension0<E, K, O>, C>
extend<K extends string, O extends object, A1>(key: K, filter: Extension<O, A1>): Test<AddExtension1<E, K, O, A1>, C>
extend<K extends string, O extends object, A1, A2>(key: K, filter: Extension<O, A1, A2>): Test<AddExtension2<E, K, O, A1, A2>, C>
extend<K extends string, O extends object, A1, A2, A3>(key: K, filter: Extension<O, A1, A2, A3>): Test<AddExtension3<E, K, O, A1, A2, A3>, C>
extend<K extends string, O extends object, A1, A2, A3, A4>(key: K, filter: Extension<O, A1, A2, A3, A4>): Test<AddExtension4<E, K, O, A1, A2, A3, A4>, C>
}
export type Test<E extends Extensions, C> = TestBase<E, C> &
Expand Down

0 comments on commit ec27d0b

Please sign in to comment.