feat: Add tape‑promise (#41268)

This commit is contained in:
ExE Boss
2019-12-27 09:49:14 -06:00
committed by Andrew Branch
parent 006d2106dd
commit 8556324f73
6 changed files with 198 additions and 0 deletions
+81
View File
@@ -0,0 +1,81 @@
// Type definitions for tape-promise 4.0
// Project: https://github.com/jprichardson/tape-promise#readme
// Definitions by: ExE Boss <https://github.com/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<void>;
}
// 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<any> | (() => PromiseLike<any>), msg?: string): Promise<void>;
rejects(
promise: PromiseLike<any> | (() => PromiseLike<any>),
expected?: RegExp | Function,
msg?: string,
): Promise<void>;
/**
* Assert that the promise resolves successfully.
*/
doesNotReject(promise: PromiseLike<any> | (() => PromiseLike<any>), msg?: string): Promise<void>;
doesNotReject(
promise: PromiseLike<any> | (() => PromiseLike<any>),
expected?: RegExp | Function,
msg?: string,
): Promise<void>;
}
// 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;
+19
View File
@@ -0,0 +1,19 @@
import tapePromise = require('./index');
declare const tape: ReturnType<typeof tapePromise.default>;
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;
@@ -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;
});
});
@@ -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;
});
});
+20
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }