diff --git a/package.json b/package.json index 602eb1e..65418cb 100644 --- a/package.json +++ b/package.json @@ -44,11 +44,11 @@ "repository": "jdxcode/fancy-test", "scripts": { "build": "rm -rf lib && tsc", - "version": "markdown-toc -i README.md && git add README.md", "lint": "tsc -p test --noEmit && tslint -p test -t stylish", "posttest": "yarn run lint", "prepublishOnly": "yarn run build", - "test": "mocha --forbid-only \"test/**/*.test.ts\"" + "test": "mocha --forbid-only \"test/**/*.test.ts\"", + "version": "markdown-toc -i README.md && git add README.md" }, "types": "lib/index.d.ts" } diff --git a/src/base.ts b/src/base.ts index 5154112..d268714 100644 --- a/src/base.ts +++ b/src/base.ts @@ -140,6 +140,6 @@ export default base(context) .register('only', () => ({ init: ctx => { ctx.test = it.only } })) - .register('retries', (count?: number) => ({ + .register('retries', (count: number) => ({ init: ctx => ctx.retries = count })) diff --git a/src/catch.ts b/src/catch.ts index 30a6c84..3659c0e 100644 --- a/src/catch.ts +++ b/src/catch.ts @@ -2,7 +2,7 @@ import * as _ from 'lodash' import {expect} from './chai' -export default (arg?: RegExp | string | ((err: Error) => any), opts: {raiseIfNotThrown?: boolean} = {}) => ({ +export default (arg: RegExp | string | ((err: Error) => any), opts: {raiseIfNotThrown?: boolean} = {}) => ({ run() { if (opts.raiseIfNotThrown !== false) { throw new Error('expected error to be thrown') diff --git a/src/env.ts b/src/env.ts index 0b1ecb2..569243b 100644 --- a/src/env.ts +++ b/src/env.ts @@ -2,7 +2,7 @@ import * as _ from 'lodash' import {EnvOptions} from './types' -export default (env?: {[k: string]: string | null | undefined}, opts: EnvOptions = {}) => { +export default (env: {[k: string]: string | null | undefined}, opts: EnvOptions = {}) => { const envs: (typeof process.env)[] = [] return { run() { diff --git a/src/nock.ts b/src/nock.ts index 96e4147..88136c2 100644 --- a/src/nock.ts +++ b/src/nock.ts @@ -2,8 +2,7 @@ import Nock = require('nock') import {NockCallback, NockOptions} from './types' -export function nock(host?: string, options?: NockCallback | NockOptions, cb?: NockCallback) { - if (host === undefined) throw new Error('host is undefined') +export function nock(host: string, options: NockCallback | NockOptions, cb?: NockCallback) { if (typeof options === 'function') { cb = options options = {} diff --git a/src/stdmock.ts b/src/stdmock.ts index 49691e2..6c7afe5 100644 --- a/src/stdmock.ts +++ b/src/stdmock.ts @@ -17,7 +17,7 @@ const create = (std: T) => (opts: {print?: boolea export const stdout = create('stdout') export const stderr = create('stderr') -export const stdin = (input?: string, delay = 0) => { +export const stdin = (input: string, delay = 0) => { let stdin: any return { run: () => { diff --git a/src/stub.ts b/src/stub.ts index bd6373f..a6f7ffe 100644 --- a/src/stub.ts +++ b/src/stub.ts @@ -3,7 +3,7 @@ import * as _ from 'lodash' /** * mocks an object's property */ -export default function (object?: any, path?: string, value?: any) { +export default function (object: T, path: K, value: () => T[K]) { if (object === undefined || path === undefined) throw new Error('should not be undefined') return { run(ctx: {stubs: any[]}) { diff --git a/src/types.ts b/src/types.ts index fefda19..bc8852f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,9 +1,9 @@ -export type PluginBuilder = (arg1?: A1, arg2?: A2, arg3?: A3, arg4?: A4) => Plugin +export type PluginBuilder = (...args: Args) => Plugin import Nock = require('nock') export interface Context { test: (typeof it | typeof it.skip) - plugins: {[k: string]: PluginBuilder} + plugins: {[k: string]: PluginBuilder} expectation?: string chain: Plugin[] error?: Error & {code?: string} @@ -20,10 +20,7 @@ export interface Plugin { export interface PluginDef { output: object - a1: any - a2: any - a3: any - a4: any + args: any[] } export interface Plugins {[k: string]: PluginDef} @@ -48,8 +45,8 @@ export type Base = { add(key: K, cb: ((context: I) => Promise | O) | Promise | O): Base do(cb: (context: I & O) => any): Base finally(cb: (context: I) => any): Base - register(key: K, plugin: (arg1?: A1, arg2?: A2, arg3?: A3, arg4?: A4) => Plugin): Base -} & {[P in keyof T]: (arg1?: T[P]['a1'], arg2?: T[P]['a2'], arg3?: T[P]['a3'], arg4?: T[P]['a4']) => Base} + register(key: K, plugin: (...args: A) => Plugin): Base +} & {[P in keyof T]: (...args: T[P]['args']) => Base} export interface EnvOptions { clear?: boolean diff --git a/test/catch.test.ts b/test/catch.test.ts index 4459371..ebbacc3 100644 --- a/test/catch.test.ts +++ b/test/catch.test.ts @@ -27,12 +27,12 @@ describe('catch', () => { fancy .do(() => { throw new Error('foobar') }) - .catch() + .catch(undefined as any) .catch('no arg provided to catch') .end('errors if no args passed') fancy - .catch() + .catch(undefined as any) .catch('expected error to be thrown') .end('errors if no error thrown')