From 38bbfa27cb55f8fc2864da4c6c83ae47d76ea356 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Fri, 26 Jan 2018 13:50:44 -0800 Subject: [PATCH] fix: consolidate types --- src/base.ts | 45 +++------------------------------------------ src/env.ts | 8 +------- src/index.ts | 10 +++------- src/nock.ts | 4 ++-- src/types.ts | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 55 insertions(+), 61 deletions(-) diff --git a/src/base.ts b/src/base.ts index f9d32a2..cf4d2c0 100644 --- a/src/base.ts +++ b/src/base.ts @@ -3,54 +3,15 @@ import * as _ from 'lodash' -export type PluginBuilder = (arg1?: A1, arg2?: A2, arg3?: A3, arg4?: A4) => Plugin +import * as Types from './types' -export interface Plugin { - run?(context: I): any - init?(context: I): any - finally?(context: I): any - catch?(context: I): any -} - -export interface Context { - test: (typeof it | typeof it.skip) - plugins: {[k: string]: PluginBuilder} - expectation?: string - chain: Plugin[] - error?: Error & {code?: string} -} - -const context: Context = { +const context: Types.Context = { test: it, plugins: {}, chain: [], } -export interface PluginDef { - output: object - a1: any - a2: any - a3: any - a4: any -} - -export interface Plugins {[k: string]: PluginDef} - -export type Base = { - it: { - (expectation: string, cb?: (context: I) => any): void - (cb?: (context: I) => any): void - } - end: { - (expectation: string, cb?: (context: I) => any): void - (cb?: (context: I) => any): void - } - add(key: K, cb: (context: I) => Promise | O): Base - do(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} - -const base = (context: I): Base => { +const base = (context: I): Types.Base => { const end = (arg1: any, cb: any) => { context = assignWithProps({}, context) if (_.isFunction(arg1)) { diff --git a/src/env.ts b/src/env.ts index 7025aeb..b421fd3 100644 --- a/src/env.ts +++ b/src/env.ts @@ -1,10 +1,4 @@ -import {Plugin} from './base' - -export interface EnvOptions { - clear?: boolean -} - -export interface Env extends Plugin<{envs: (typeof process.env)[]}> {} +import {Env, EnvOptions} from './types' export default (env: {[k: string]: string | undefined}, opts: EnvOptions = {}) => ({ run(ctx) { diff --git a/src/index.ts b/src/index.ts index 50c3dad..8dc1806 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ -import base, {Base, Context, Plugin} from './base' +import base from './base' import _catch from './catch' import {expect} from './chai' -import env, {EnvOptions} from './env' +import env from './env' import nock, {NockScope} from './nock' import {stderr, stdout} from './stdmock' import stub from './stub' @@ -19,12 +19,8 @@ export const fancy = base export type Fancy = typeof fancy export { + expect, FancyTypes, - Base, - Context, - EnvOptions, NockScope, - Plugin, - expect, } export default fancy diff --git a/src/nock.ts b/src/nock.ts index 88c8df4..04cd8bd 100644 --- a/src/nock.ts +++ b/src/nock.ts @@ -1,5 +1,7 @@ import * as Nock from 'nock' +export {Scope as NockScope} from 'nock' + export default (host: string, cb: (nock: Nock.Scope) => any) => { const nock: typeof Nock = require('nock') const intercepter = nock(host) @@ -16,5 +18,3 @@ export default (host: string, cb: (nock: Nock.Scope) => any) => { }, } } - -export {Scope as NockScope} from 'nock' diff --git a/src/types.ts b/src/types.ts index d455804..228235b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,46 @@ -export {Base, Context, Plugin} from './base' -export {EnvOptions} from './env' -export {NockScope} from './nock' +export type PluginBuilder = (arg1?: A1, arg2?: A2, arg3?: A3, arg4?: A4) => Plugin + +export interface Context { + test: (typeof it | typeof it.skip) + plugins: {[k: string]: PluginBuilder} + expectation?: string + chain: Plugin[] + error?: Error & {code?: string} +} + +export interface Plugin { + run?(context: I): any + init?(context: I): any + finally?(context: I): any + catch?(context: I): any +} + +export interface PluginDef { + output: object + a1: any + a2: any + a3: any + a4: any +} + +export interface Plugins {[k: string]: PluginDef} + +export type Base = { + it: { + (expectation: string, cb?: (context: I) => any): void + (cb?: (context: I) => any): void + } + end: { + (expectation: string, cb?: (context: I) => any): void + (cb?: (context: I) => any): void + } + add(key: K, cb: (context: I) => Promise | O): Base + do(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} + +export interface EnvOptions { + clear?: boolean +} + +export interface Env extends Plugin<{envs: (typeof process.env)[]}> {}