diff --git a/types/tape-promise/index.d.ts b/types/tape-promise/index.d.ts new file mode 100644 index 0000000000..58e94d7f61 --- /dev/null +++ b/types/tape-promise/index.d.ts @@ -0,0 +1,81 @@ +// Type definitions for tape-promise 4.0 +// Project: https://github.com/jprichardson/tape-promise#readme +// Definitions by: ExE Boss +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import tape = require('tape'); +import { TestOptions, StreamOptions } from 'tape'; +export { TestOptions, StreamOptions }; + +export interface TestCase { + (test: Test): void | PromiseLike; +} + +// tslint:disable: ban-types +export interface Test extends tape.Test { + test(name: string, cb: TestCase): void; + test(name: string, opts: TestOptions, cb: TestCase): void; + + /** + * Assert that the promise settles with a rejection result. + * + * @param expected if present, must be a RegExp or Function, which is used to test the exception object. + */ + rejects(promise: PromiseLike | (() => PromiseLike), msg?: string): Promise; + rejects( + promise: PromiseLike | (() => PromiseLike), + expected?: RegExp | Function, + msg?: string, + ): Promise; + + /** + * Assert that the promise resolves successfully. + */ + doesNotReject(promise: PromiseLike | (() => PromiseLike), msg?: string): Promise; + doesNotReject( + promise: PromiseLike | (() => PromiseLike), + expected?: RegExp | Function, + msg?: string, + ): Promise; +} +// tslint:enable: ban-types + +// tslint:disable: unified-signatures +interface AsyncTapeFunction { + /** + * Create a new test with an optional name string and optional opts object. + * cb(t) fires with the new test object t once all preceding tests have finished. + * Tests execute serially. + */ + (name: string, cb: TestCase): void; + (name: string, opts: TestOptions, cb: TestCase): void; + (cb: TestCase): void; + (opts: TestOptions, cb: TestCase): void; + + /** + * Generate a new test that will be skipped over. + */ + skip(name: string, cb: TestCase): void; + skip(name: string, opts: TestOptions, cb: TestCase): void; + skip(cb: TestCase): void; + skip(opts: TestOptions, cb: TestCase): void; + + /** + * Like test(name?, opts?, cb) except if you use .only this + * is the only test case that will run for the entire process, + * all other test cases using tape will be ignored. + */ + only(name: string, cb: TestCase): void; + only(name: string, opts: TestOptions, cb: TestCase): void; + only(cb: TestCase): void; + only(opts: TestOptions, cb: TestCase): void; + + /** + * Create a new test harness instance, which is a function like test(), + * but with a new pending stack and test state. + */ + createHarness(): AsyncTapeFunction & typeof tape; +} +// tslint:enable: unified-signatures + +export default function tapePromiseFactory(tapeTest: any): AsyncTapeFunction & typeof tape; diff --git a/types/tape-promise/tape.d.ts b/types/tape-promise/tape.d.ts new file mode 100644 index 0000000000..110a407f36 --- /dev/null +++ b/types/tape-promise/tape.d.ts @@ -0,0 +1,19 @@ +import tapePromise = require('./index'); + +declare const tape: ReturnType; +declare namespace tape { + type Test = tapePromise.Test; + type TestCase = tapePromise.TestCase; + + /** + * Available opts options for the tape function. + */ + type TestOptions = tapePromise.TestOptions; + + /** + * Options for the createStream function. + */ + type StreamOptions = tapePromise.StreamOptions; +} + +export = tape; diff --git a/types/tape-promise/test/tape-promise.byot.ts b/types/tape-promise/test/tape-promise.byot.ts new file mode 100644 index 0000000000..f04a27c37f --- /dev/null +++ b/types/tape-promise/test/tape-promise.byot.ts @@ -0,0 +1,40 @@ +// tslint:disable: no-async-without-await +import tapeSync = require('tape'); +import tapePromise = require('tape-promise'); + +// Bring Your Own Tape: +const tape = tapePromise.default(tapeSync); + +const name = String(); +const cb = async (test: tapePromise.Test) => {}; +const opts: tapePromise.TestOptions = {}; +let t: tapePromise.Test; + +tape(cb); +tape(name, cb); +tape(opts, cb); +tape(name, opts, cb); + +tape(name, async (test: tapePromise.Test) => { + t = test; +}); + +tape.skip(cb); +tape.skip(name, cb); +tape.skip(opts, cb); +tape.skip(name, opts, cb); + +tape.only(cb); +tape.only(name, cb); +tape.only(opts, cb); +tape.only(name, opts, cb); + +tape(name, async (test: tapePromise.Test) => { + test.test(name, async st => { + t = st; + }); + + test.test(name, opts, async st => { + t = st; + }); +}); diff --git a/types/tape-promise/test/tape-promise.peer-dep.ts b/types/tape-promise/test/tape-promise.peer-dep.ts new file mode 100644 index 0000000000..948497b0cb --- /dev/null +++ b/types/tape-promise/test/tape-promise.peer-dep.ts @@ -0,0 +1,37 @@ +// tslint:disable: no-async-without-await +// peerDependencies: { tape: '*' } +import tape = require('tape-promise/tape'); + +const name = String(); +const cb = async (test: tape.Test) => {}; +const opts: tape.TestOptions = {}; +let t: tape.Test; + +tape(cb); +tape(name, cb); +tape(opts, cb); +tape(name, opts, cb); + +tape(name, async (test: tape.Test) => { + t = test; +}); + +tape.skip(cb); +tape.skip(name, cb); +tape.skip(opts, cb); +tape.skip(name, opts, cb); + +tape.only(cb); +tape.only(name, cb); +tape.only(opts, cb); +tape.only(name, opts, cb); + +tape(name, async (test: tape.Test) => { + test.test(name, async st => { + t = st; + }); + + test.test(name, opts, async st => { + t = st; + }); +}); diff --git a/types/tape-promise/tsconfig.json b/types/tape-promise/tsconfig.json new file mode 100644 index 0000000000..217de16243 --- /dev/null +++ b/types/tape-promise/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "test/tape-promise.byot.ts", + "test/tape-promise.peer-dep.ts", + "index.d.ts" + ] +} diff --git a/types/tape-promise/tslint.json b/types/tape-promise/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/tape-promise/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }