diff --git a/eltro.d.ts b/eltro.d.ts new file mode 100644 index 0000000..92ba843 --- /dev/null +++ b/eltro.d.ts @@ -0,0 +1,63 @@ +import NodeAssert from 'assert'; + +type ExtendedAssert = { + notOk(value: unknown, message?: string | Error): void, + match(value: string, test: RegExp, message?: string | Error): void, + notMatch(value: string, test: RegExp, message?: string | Error): void, + throwsAndCatch(fn: () => unknown, message?: string | Error): Error, + equalWithMargin(value: number, test: number, margin?: number, message?: string | Error): void, + isFulfilled(promise: Promise, message?: string | Error): Promise, + isRejected(promise: Promise, message?: string | Error): Promise, +} + +export const assert: typeof NodeAssert & ExtendedAssert + +type Spy = { + (): unknown + lastCall: null | Array + called: boolean + callCount: number + calls: Array> + findCall(fn: (args: Array) => boolean): null | Array + getCall(index: number): null | Array + getCallN(index: number): null | Array + onCall(index: number): Spy + onCallN(index: number): Spy + reset(): Spy + returns(data: unknown): Spy + throws(data: unknown): Spy + resolves(data: unknown): Spy + rejects(data: unknown): Spy + returnWith(fn: (...args: unknown[]) => unknown): Spy +} + +export function spy(): Spy +export function stub(fun?: (...args: unknown[]) => unknown): Spy + +type Test = { + timeout(timeout: number): void + skip(): void + only(): void +} + +type TestResult = void | Promise + +type Callback = { + (): void + wrap(fn: () => unknown): void + finish(fn: () => unknown): void +} + +type Eltro = { + before(fn: () => TestResult): Test + after(fn: () => TestResult): Test + beforeEach(fn: () => TestResult): Test + afterEachEach(fn: () => TestResult): Test + describe(name: string, fn: () => void) + timeout(timeout: number): Eltro + skip(): Eltro + only(): Eltro + test(name: string, func: (cb?: Callback) => TestResult): Test +} + +export const Eltro: Eltro diff --git a/package.json b/package.json index 1a1f67e..86c0dc4 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "eltro", - "version": "1.5.0", + "version": "1.6.0", "description": "Eltro is a tiny no-dependancy test framework for node", "main": "index.mjs", + "types": "eltro.d.ts", "scripts": { "echo": "echo helloworld", "echo:watch": "node cli.mjs --watch test --npm echo",