[tape] Update types to 4.13.2 (#43984)

* Definitions created and updated for extra skip and todo opts that can be passed to assert functions.
* todo has been added to TestOptions.
* Definition created for onFailure() handler.
* Definitions created for match() and doesNotMatch() assertions
* Comments have been updated to reflect phrasing used in tape's README.

Missing:
* getHarness(opts). autoclose and exit options in getHarness.
* opts in createHarness(opts). autoclose and exit options in createHarness.
* exit in TestOptions.
* test.close().

Co-authored-by: relaxolotl <relaxolotl@users.noreply.github.com>
This commit is contained in:
relaxolotl 2020-04-17 18:58:32 -04:00 committed by GitHub
parent 64b80469ac
commit 753525d1fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 262 additions and 183 deletions

126
types/tape/index.d.ts vendored
View File

@ -1,4 +1,4 @@
// Type definitions for tape v4.2.30
// Type definitions for tape v4.13.2
// Project: https://github.com/substack/tape
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// Haoqun Jiang <https://github.com/sodatea>
@ -10,7 +10,6 @@
/// <reference types="node" />
export = tape;
/**
@ -24,7 +23,6 @@ declare function tape(cb: tape.TestCase): void;
declare function tape(opts: tape.TestOptions, cb: tape.TestCase): void;
declare namespace tape {
interface TestCase {
(test: Test): void;
}
@ -33,8 +31,18 @@ declare namespace tape {
* Available opts options for the tape function.
*/
interface TestOptions {
skip?: boolean; // See tape.skip.
timeout?: number; // Set a timeout for the test, after which it will fail. See tape.timeoutAfter.
skip?: boolean; // true/false. See test.skip.
todo?: boolean; // true/false. Test will be allowed to fail.
timeout?: number; // Set a timeout for the test, after which it will fail. See tape.timeoutAfter.
}
/**
* Available options for tape assertions.
*/
interface AssertOptions {
skip?: boolean | string; // Skip the assertion. Can also be a message explaining why the test is skipped.
todo?: boolean | string; // Allows the assertion to fail.
message?: string; // An optional description of the assertion.
}
/**
@ -57,6 +65,11 @@ declare namespace tape {
*/
export function onFinish(cb: () => void): void;
/**
* The onFailure hook will get invoked whenever any tape tests have failed.
*/
export function onFailure(cb: () => void): 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.
*/
@ -69,6 +82,7 @@ declare namespace tape {
* Create a new test harness instance, which is a function like test(), but with a new pending stack and test state.
*/
export function createHarness(): typeof tape;
/**
* Create a stream of output, bypassing the default output stream that writes messages to console.log().
* By default stream will be a text stream of TAP output, but you can get an object stream instead by setting opts.objectMode to true.
@ -99,12 +113,12 @@ declare namespace tape {
/**
* Generate a failing assertion with a message msg.
*/
fail(msg?: string): void;
fail(msg?: string, extra?: AssertOptions): void;
/**
* Generate a passing assertion with a message msg.
*/
pass(msg?: string): void;
pass(msg?: string, extra?: AssertOptions): void;
/**
* Automatically timeout the test after X ms.
@ -114,87 +128,87 @@ declare namespace tape {
/**
* Generate an assertion that will be skipped over.
*/
skip(msg?: string): void;
skip(msg?: string, extra?: AssertOptions): void;
/**
* Assert that value is truthy with an optional description message msg.
*/
ok(value: any, msg?: string): void;
true(value: any, msg?: string): void;
assert(value: any, msg?: string): void;
ok(value: any, msg?: string, extra?: AssertOptions): void;
true(value: any, msg?: string, extra?: AssertOptions): void;
assert(value: any, msg?: string, extra?: AssertOptions): void;
/**
* Assert that value is falsy with an optional description message msg.
*/
notOk(value: any, msg?: string): void;
false(value: any, msg?: string): void;
notok(value: any, msg?: string): void;
notOk(value: any, msg?: string, extra?: AssertOptions): void;
false(value: any, msg?: string, extra?: AssertOptions): void;
notok(value: any, msg?: string, extra?: AssertOptions): void;
/**
* Assert that err is falsy.
* If err is non-falsy, use its err.message as the description message.
*/
error(err: any, msg?: string): void;
ifError(err: any, msg?: string): void;
ifErr(err: any, msg?: string): void;
iferror(err: any, msg?: string): void;
error(err: any, msg?: string, extra?: AssertOptions): void;
ifError(err: any, msg?: string, extra?: AssertOptions): void;
ifErr(err: any, msg?: string, extra?: AssertOptions): void;
iferror(err: any, msg?: string, extra?: AssertOptions): void;
/**
* Assert that a === b with an optional description msg.
*/
equal(actual: any, expected: any, msg?: string): void;
equals(actual: any, expected: any, msg?: string): void;
isEqual(actual: any, expected: any, msg?: string): void;
is(actual: any, expected: any, msg?: string): void;
strictEqual(actual: any, expected: any, msg?: string): void;
strictEquals(actual: any, expected: any, msg?: string): void;
equal(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
equals(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
isEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
is(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
strictEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
strictEquals(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
/**
* Assert that a !== b with an optional description msg.
*/
notEqual(actual: any, expected: any, msg?: string): void;
notEquals(actual: any, expected: any, msg?: string): void;
notStrictEqual(actual: any, expected: any, msg?: string): void;
notStrictEquals(actual: any, expected: any, msg?: string): void;
isNotEqual(actual: any, expected: any, msg?: string): void;
isNot(actual: any, expected: any, msg?: string): void;
not(actual: any, expected: any, msg?: string): void;
doesNotEqual(actual: any, expected: any, msg?: string): void;
isInequal(actual: any, expected: any, msg?: string): void;
notEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
notEquals(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
notStrictEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
notStrictEquals(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
isNotEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
isNot(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
not(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
doesNotEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
isInequal(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
/**
* Assert that a and b have the same structure and nested values using node's deepEqual() algorithm with strict comparisons (===) on leaf nodes and an optional description msg.
*/
deepEqual(actual: any, expected: any, msg?: string): void;
deepEquals(actual: any, expected: any, msg?: string): void;
isEquivalent(actual: any, expected: any, msg?: string): void;
same(actual: any, expected: any, msg?: string): void;
deepEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
deepEquals(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
isEquivalent(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
same(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
/**
* Assert that a and b do not have the same structure and nested values using node's deepEqual() algorithm with strict comparisons (===) on leaf nodes and an optional description msg.
*/
notDeepEqual(actual: any, expected: any, msg?: string): void;
notEquivalent(actual: any, expected: any, msg?: string): void;
notDeeply(actual: any, expected: any, msg?: string): void;
notSame(actual: any, expected: any, msg?: string): void;
isNotDeepEqual(actual: any, expected: any, msg?: string): void;
isNotDeeply(actual: any, expected: any, msg?: string): void;
isNotEquivalent(actual: any, expected: any, msg?: string): void;
isInequivalent(actual: any, expected: any, msg?: string): void;
notDeepEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
notEquivalent(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
notDeeply(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
notSame(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
isNotDeepEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
isNotDeeply(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
isNotEquivalent(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
isInequivalent(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
/**
* Assert that a and b have the same structure and nested values using node's deepEqual() algorithm with loose comparisons (==) on leaf nodes and an optional description msg.
*/
deepLooseEqual(actual: any, expected: any, msg?: string): void;
looseEqual(actual: any, expected: any, msg?: string): void;
looseEquals(actual: any, expected: any, msg?: string): void;
deepLooseEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
looseEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
looseEquals(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
/**
* Assert that a and b do not have the same structure and nested values using node's deepEqual() algorithm with loose comparisons (==) on leaf nodes and an optional description msg.
*/
notDeepLooseEqual(actual: any, expected: any, msg?: string): void;
notLooseEqual(actual: any, expected: any, msg?: string): void;
notLooseEquals(actual: any, expected: any, msg?: string): void;
notDeepLooseEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
notLooseEqual(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
notLooseEquals(actual: any, expected: any, msg?: string, extra?: AssertOptions): void;
/**
* Assert that the function call fn() throws an exception.
@ -214,5 +228,15 @@ declare namespace tape {
* (Useful when using e.g. tap-colorize where output is buffered & console.log will print in incorrect order vis-a-vis tap output.)
*/
comment(msg: string): void;
/**
* Assert that string matches the RegExp regexp. Will throw (not just fail) when the first two arguments are the wrong type.
*/
match(actual: string, expected: RegExp, msg?: string, extra?: AssertOptions): void;
/**
* Assert that string does not match the RegExp regexp. Will throw (not just fail) when the first two arguments are the wrong type.
*/
doesNotMatch(actual: string, expected: RegExp, msg?: string, extra?: AssertOptions): void;
}
}

View File

@ -1,182 +1,237 @@
import tape = require("tape");
import tape = require('tape');
var name: string;
var cb: tape.TestCase;
var opts: tape.TestOptions;
var topts: tape.TestOptions;
var t: tape.Test;
tape(cb);
tape(name, cb);
tape(opts, cb);
tape(name, opts, cb);
tape(topts, cb);
tape(name, topts, cb);
tape(name, (test: tape.Test) => {
t = test;
t = test;
});
tape.skip(cb);
tape.skip(name, cb);
tape.skip(opts, cb);
tape.skip(name, opts, cb);
tape.skip(topts, cb);
tape.skip(name, topts, cb);
tape.only(cb);
tape.only(name, cb);
tape.only(opts, cb);
tape.only(name, opts, cb);
tape.only(topts, cb);
tape.only(name, topts, cb);
tape.onFinish(() => {});
tape.onFailure(() => {});
var sopts: tape.StreamOptions;
var rs: NodeJS.ReadableStream;
rs = tape.createStream();
rs = tape.createStream(sopts);
var htest: typeof tape;
htest = tape.createHarness();
class CustomException extends Error {
constructor(message?: string) {
super(message);
}
constructor(message?: string) {
super(message);
}
}
tape(name, (test: tape.Test) => {
var num: number;
var ms: number;
var value: any;
var actual: any;
var expected: any;
var err: any;
var fn = function() {};
var msg: string;
var extra: tape.AssertOptions;
var regex: RegExp;
var num: number;
var ms: number;
var value: any;
var actual: any;
var expected: any;
var err: any;
var fn = function() {};
var msg: string;
var exceptionExpected: RegExp | (() => void);
var exceptionExpected: RegExp | (() => void);
test.plan(num);
test.end();
test.end(err);
test.plan(num);
test.end();
test.end(err);
test.fail(msg);
test.fail(msg, extra);
test.pass(msg);
test.pass(msg, extra);
test.timeoutAfter(ms);
test.skip(msg);
test.skip(msg, extra);
test.fail(msg);
test.pass(msg);
test.timeoutAfter(ms);
test.skip(msg);
test.ok(value);
test.ok(value, msg);
test.ok(value, msg, extra);
test.true(value);
test.true(value, msg);
test.true(value, msg, extra);
test.assert(value);
test.assert(value, msg);
test.assert(value, msg, extra);
test.ok(value);
test.ok(value, msg);
test.true(value);
test.true(value, msg);
test.assert(value);
test.assert(value, msg);
test.notOk(value);
test.notOk(value, msg);
test.notOk(value, msg, extra);
test.false(value);
test.false(value, msg);
test.false(value, msg, extra);
test.notok(value);
test.notok(value, msg);
test.notok(value, msg, extra);
test.notOk(value);
test.notOk(value, msg);
test.false(value);
test.false(value, msg);
test.notok(value);
test.notok(value, msg);
test.error(err, msg);
test.error(err, msg, extra);
test.ifError(err, msg);
test.ifError(err, msg, extra);
test.ifErr(err, msg);
test.ifErr(err, msg, extra);
test.iferror(err, msg);
test.iferror(err, msg, extra);
test.error(err, msg);
test.ifError(err, msg);
test.ifErr(err, msg);
test.iferror(err, msg);
test.equal(actual, expected);
test.equal(actual, expected, msg);
test.equal(actual, expected, msg, extra);
test.equals(actual, expected);
test.equals(actual, expected, msg);
test.equals(actual, expected, msg, extra);
test.isEqual(actual, expected);
test.isEqual(actual, expected, msg);
test.isEqual(actual, expected, msg, extra);
test.is(actual, expected);
test.is(actual, expected, msg);
test.is(actual, expected, msg, extra);
test.strictEqual(actual, expected);
test.strictEqual(actual, expected, msg);
test.strictEqual(actual, expected, msg, extra);
test.strictEquals(actual, expected);
test.strictEquals(actual, expected, msg);
test.strictEquals(actual, expected, msg, extra);
test.equal(actual, expected);
test.equal(actual, expected, msg);
test.equals(actual, expected);
test.equals(actual, expected, msg);
test.isEqual(actual, expected);
test.isEqual(actual, expected, msg);
test.is(actual, expected);
test.is(actual, expected, msg);
test.strictEqual(actual, expected);
test.strictEqual(actual, expected, msg);
test.strictEquals(actual, expected);
test.strictEquals(actual, expected, msg);
test.notEqual(actual, expected);
test.notEqual(actual, expected, msg);
test.notEqual(actual, expected, msg, extra);
test.notEquals(actual, expected);
test.notEquals(actual, expected, msg);
test.notEquals(actual, expected, msg, extra);
test.notStrictEqual(actual, expected);
test.notStrictEqual(actual, expected, msg);
test.notStrictEqual(actual, expected, msg, extra);
test.notStrictEquals(actual, expected);
test.notStrictEquals(actual, expected, msg);
test.notStrictEquals(actual, expected, msg, extra);
test.isNotEqual(actual, expected);
test.isNotEqual(actual, expected, msg);
test.isNotEqual(actual, expected, msg, extra);
test.isNot(actual, expected);
test.isNot(actual, expected, msg);
test.isNot(actual, expected, msg, extra);
test.not(actual, expected);
test.not(actual, expected, msg);
test.not(actual, expected, msg, extra);
test.doesNotEqual(actual, expected);
test.doesNotEqual(actual, expected, msg);
test.doesNotEqual(actual, expected, msg, extra);
test.isInequal(actual, expected);
test.isInequal(actual, expected, msg);
test.isInequal(actual, expected, msg, extra);
test.notEqual(actual, expected);
test.notEqual(actual, expected, msg);
test.notEquals(actual, expected);
test.notEquals(actual, expected, msg);
test.notStrictEqual(actual, expected);
test.notStrictEqual(actual, expected, msg);
test.notStrictEquals(actual, expected);
test.notStrictEquals(actual, expected, msg);
test.isNotEqual(actual, expected);
test.isNotEqual(actual, expected, msg);
test.isNot(actual, expected);
test.isNot(actual, expected, msg);
test.not(actual, expected);
test.not(actual, expected, msg);
test.doesNotEqual(actual, expected);
test.doesNotEqual(actual, expected, msg);
test.isInequal(actual, expected);
test.isInequal(actual, expected, msg);
test.deepEqual(actual, expected);
test.deepEqual(actual, expected, msg);
test.deepEqual(actual, expected, msg, extra);
test.deepEquals(actual, expected);
test.deepEquals(actual, expected, msg);
test.deepEquals(actual, expected, msg, extra);
test.isEquivalent(actual, expected);
test.isEquivalent(actual, expected, msg);
test.isEquivalent(actual, expected, msg, extra);
test.same(actual, expected);
test.same(actual, expected, msg);
test.same(actual, expected, msg, extra);
test.deepEqual(actual, expected);
test.deepEqual(actual, expected, msg);
test.deepEquals(actual, expected);
test.deepEquals(actual, expected, msg);
test.isEquivalent(actual, expected);
test.isEquivalent(actual, expected, msg);
test.same(actual, expected);
test.same(actual, expected, msg);
test.notDeepEqual(actual, expected);
test.notDeepEqual(actual, expected, msg);
test.notDeepEqual(actual, expected, msg, extra);
test.notEquivalent(actual, expected);
test.notEquivalent(actual, expected, msg);
test.notEquivalent(actual, expected, msg, extra);
test.notDeeply(actual, expected);
test.notDeeply(actual, expected, msg);
test.notDeeply(actual, expected, msg, extra);
test.notSame(actual, expected);
test.notSame(actual, expected, msg);
test.notSame(actual, expected, msg, extra);
test.isNotDeepEqual(actual, expected);
test.isNotDeepEqual(actual, expected, msg);
test.isNotDeepEqual(actual, expected, msg, extra);
test.isNotDeeply(actual, expected);
test.isNotDeeply(actual, expected, msg);
test.isNotDeeply(actual, expected, msg, extra);
test.isNotEquivalent(actual, expected);
test.isNotEquivalent(actual, expected, msg);
test.isNotEquivalent(actual, expected, msg, extra);
test.isInequivalent(actual, expected);
test.isInequivalent(actual, expected, msg);
test.isInequivalent(actual, expected, msg, extra);
test.notDeepEqual(actual, expected);
test.notDeepEqual(actual, expected, msg);
test.notEquivalent(actual, expected);
test.notEquivalent(actual, expected, msg);
test.notDeeply(actual, expected);
test.notDeeply(actual, expected, msg);
test.notSame(actual, expected);
test.notSame(actual, expected, msg);
test.isNotDeepEqual(actual, expected);
test.isNotDeepEqual(actual, expected, msg);
test.isNotDeeply(actual, expected);
test.isNotDeeply(actual, expected, msg);
test.isNotEquivalent(actual, expected);
test.isNotEquivalent(actual, expected, msg);
test.isInequivalent(actual, expected);
test.isInequivalent(actual, expected, msg);
test.deepLooseEqual(actual, expected);
test.deepLooseEqual(actual, expected, msg);
test.deepLooseEqual(actual, expected, msg, extra);
test.looseEqual(actual, expected);
test.looseEqual(actual, expected, msg);
test.looseEqual(actual, expected, msg, extra);
test.looseEquals(actual, expected);
test.looseEquals(actual, expected, msg);
test.looseEquals(actual, expected, msg, extra);
test.deepLooseEqual(actual, expected);
test.deepLooseEqual(actual, expected, msg);
test.looseEqual(actual, expected);
test.looseEqual(actual, expected, msg);
test.looseEquals(actual, expected);
test.looseEquals(actual, expected, msg);
test.notDeepLooseEqual(actual, expected);
test.notDeepLooseEqual(actual, expected, msg);
test.notDeepLooseEqual(actual, expected, msg, extra);
test.notLooseEqual(actual, expected);
test.notLooseEqual(actual, expected, msg);
test.notLooseEqual(actual, expected, msg, extra);
test.notLooseEquals(actual, expected);
test.notLooseEquals(actual, expected, msg);
test.notLooseEquals(actual, expected, msg, extra);
test.notDeepLooseEqual(actual, expected);
test.notDeepLooseEqual(actual, expected, msg);
test.notLooseEqual(actual, expected);
test.notLooseEqual(actual, expected, msg);
test.notLooseEquals(actual, expected);
test.notLooseEquals(actual, expected, msg);
test.throws(fn);
test.throws(fn, msg);
test.throws(fn, exceptionExpected);
test.throws(fn, exceptionExpected, msg);
test.throws(fn, exceptionExpected, msg);
test.throws(fn, CustomException);
test.throws(fn, CustomException, msg);
test.throws(fn, CustomException, msg);
test.throws(fn);
test.throws(fn, msg);
test.throws(fn, exceptionExpected);
test.throws(fn, exceptionExpected, msg);
test.throws(fn, CustomException);
test.throws(fn, CustomException, msg);
test.doesNotThrow(fn);
test.doesNotThrow(fn, msg);
test.doesNotThrow(fn, exceptionExpected);
test.doesNotThrow(fn, exceptionExpected, msg);
test.doesNotThrow(fn, CustomException);
test.doesNotThrow(fn, CustomException, msg);
test.doesNotThrow(fn);
test.doesNotThrow(fn, msg);
test.doesNotThrow(fn, exceptionExpected);
test.doesNotThrow(fn, exceptionExpected, msg);
test.doesNotThrow(fn, CustomException);
test.doesNotThrow(fn, CustomException, msg);
test.test(name, st => {
t = st;
});
test.test(name, (st) => {
t = st;
});
test.test(name, topts, st => {
t = st;
});
test.test(name, opts, (st) => {
t = st;
});
test.comment(msg);
test.comment(msg);
test.match(actual, regex);
test.match(actual, regex, msg);
test.match(actual, regex, msg, extra);
test.doesNotMatch(actual, regex);
test.doesNotMatch(actual, regex, msg);
test.doesNotMatch(actual, regex, msg, extra);
});