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

Commit

Permalink
fix: allow do to modify context
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 26, 2018
1 parent 9069fd4 commit d997f3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type Base<I extends Context, T extends Plugins> = {
(cb?: (context: I) => any): void
}
add<K extends string, O>(key: K, cb: (context: I) => Promise<O> | O): Base<I & {[P in K]: O}, T>
do(cb: (context: I) => any): Base<I, T>
do<O>(cb: (context: I & O) => any): Base<O & I, T>
register<K extends string, O, A1, A2, A3, A4>(key: K, plugin: (arg1?: A1, arg2?: A2, arg3?: A3, arg4?: A4) => Plugin<O & I>): Base<I, T & {[P in K]: {output: O, a1: A1, a2: A2, a3: A3, a4: A4}}>
} & {[P in keyof T]: (arg1?: T[P]['a1'], arg2?: T[P]['a2'], arg3?: T[P]['a3'], arg4?: T[P]['a4']) => Base<T[P]['output'] & I, T>}

Expand Down
9 changes: 8 additions & 1 deletion test/run.test.ts → test/do.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

import {expect, fancy} from '../src'

describe('run', () => {
describe('do', () => {
fancy
.stdout()
.do(() => console.log('foo'))
.do(({stdout}) => expect(stdout).to.equal('foo\n'))
.end('runs this callback last', () => {
// test code
})

fancy
.stdout()
.do((ctx: {n: number}) => {ctx.n = 101})
.do(ctx => console.log(ctx.n))
.do(ctx => expect(ctx.stdout).to.equal('101\n'))
.end('runs this callback last')
})

describe('add', () => {
Expand Down

0 comments on commit d997f3a

Please sign in to comment.