Skip to content

Commit 035877d

Browse files
committed
[New] add types
1 parent 85ddba3 commit 035877d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1049
-172
lines changed

.eslintrc

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"no-underscore-dangle": "warn",
2424
"object-curly-newline": "off",
2525
"sort-keys": "off",
26+
27+
"no-extra-parens": "off",
2628
},
2729
"ignorePatterns": ["syntax-error.*"],
2830
"overrides": [

.github/workflows/node-aught.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ jobs:
99
range: '< 10'
1010
type: minors
1111
command: npm run tests-only
12+
skip-ls-check: true

bin/import-or-require.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { extname: extnamePath } = require('path');
44
const { pathToFileURL } = require('url');
55
const getPackageType = require('get-package-type');
66

7+
/** @type {(file: string) => undefined | Promise<unknown>} */
78
// eslint-disable-next-line consistent-return
89
module.exports = function importOrRequire(file) {
910
const ext = extnamePath(file);

bin/tape

+2
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ var hasImport = require('has-dynamic-import');
100100

101101
var tape = require('../');
102102

103+
/** @type {(hasSupport: boolean) => Promise<void> | void} */
103104
function importFiles(hasSupport) {
104105
tape.wait();
105106

107+
/** @type {null | undefined | Promise<unknown>} */
106108
var filesPromise;
107109
if (hasSupport) {
108110
var importOrRequire = require('./import-or-require');

example/array.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test('array', function (t) {
99
var src = '(' + function () {
1010
var xs = [1, 2, [3, 4]];
1111
var ys = [5, 6];
12+
// @ts-expect-error
1213
g([xs, ys]);
1314
} + ')()';
1415

@@ -26,11 +27,11 @@ test('array', function (t) {
2627
];
2728

2829
Function('fn', 'g', String(output))(
29-
function (xs) {
30+
/** @param {(number | number[])[]} xs */ function (xs) {
3031
t.same(arrays.shift(), xs);
3132
return xs;
3233
},
33-
function (xs) {
34+
/** @param {(number | number[])[]} xs */ function (xs) {
3435
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
3536
}
3637
);

example/fail.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test('array', function (t) {
99
var src = '(' + function () {
1010
var xs = [1, 2, [3, 4]];
1111
var ys = [5, 6];
12+
// @ts-expect-error
1213
g([xs, ys]);
1314
} + ')()';
1415

@@ -26,11 +27,11 @@ test('array', function (t) {
2627
];
2728

2829
Function('fn', 'g', String(output))(
29-
function (xs) {
30+
/** @param {(number | number[])[]} xs */ function (xs) {
3031
t.same(arrays.shift(), xs);
3132
return xs;
3233
},
33-
function (xs) {
34+
/** @param {(number | number[])[]} xs */ function (xs) {
3435
t.same(xs, [[1, 2, [3, 4444]], [5, 6]]);
3536
}
3637
);

example/nested.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test('nested array test', function (t) {
99
var src = '(' + function () {
1010
var xs = [1, 2, [3, 4]];
1111
var ys = [5, 6];
12+
// @ts-expect-error
1213
g([xs, ys]);
1314
} + ')()';
1415

@@ -35,11 +36,11 @@ test('nested array test', function (t) {
3536
];
3637

3738
Function('fn', 'g', String(output))(
38-
function (xs) {
39+
/** @param {(number | number[])[]} xs */ function (xs) {
3940
t.same(arrays.shift(), xs);
4041
return xs;
4142
},
42-
function (xs) {
43+
/** @param {(number | number[])[]} xs */ function (xs) {
4344
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
4445
}
4546
);

example/nested_fail.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test('nested array test', function (t) {
99
var src = '(' + function () {
1010
var xs = [1, 2, [3, 4]];
1111
var ys = [5, 6];
12+
// @ts-expect-error
1213
g([xs, ys]);
1314
} + ')()';
1415

@@ -35,11 +36,11 @@ test('nested array test', function (t) {
3536
];
3637

3738
Function('fn', 'g', String(output))(
38-
function (xs) {
39+
/** @param {(number | number[])[]} xs */ function (xs) {
3940
t.same(arrays.shift(), xs);
4041
return xs;
4142
},
42-
function (xs) {
43+
/** @param {(number | number[])[]} xs */ function (xs) {
4344
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
4445
}
4546
);

example/not_enough_fail.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test('array', function (t) {
99
var src = '(' + function () {
1010
var xs = [1, 2, [3, 4]];
1111
var ys = [5, 6];
12+
// @ts-expect-error
1213
g([xs, ys]);
1314
} + ')()';
1415

@@ -26,11 +27,11 @@ test('array', function (t) {
2627
];
2728

2829
Function('fn', 'g', String(output))(
29-
function (xs) {
30+
/** @param {(number | number[])[]} xs */ function (xs) {
3031
t.same(arrays.shift(), xs);
3132
return xs;
3233
},
33-
function (xs) {
34+
/** @param {(number | number[])[]} xs */ function (xs) {
3435
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
3536
}
3637
);

example/too_many_fail.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test('array', function (t) {
99
var src = '(' + function () {
1010
var xs = [1, 2, [3, 4]];
1111
var ys = [5, 6];
12+
// @ts-expect-error
1213
g([xs, ys]);
1314
} + ')()';
1415

@@ -26,11 +27,11 @@ test('array', function (t) {
2627
];
2728

2829
Function('fn', 'g', String(output))(
29-
function (xs) {
30+
/** @param {(number | number[])[]} xs */ function (xs) {
3031
t.same(arrays.shift(), xs);
3132
return xs;
3233
},
33-
function (xs) {
34+
/** @param {(number | number[])[]} xs */ function (xs) {
3435
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
3536
}
3637
);

index.d.ts

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import type { ThroughStream } from '@ljharb/through';
2+
3+
import type Test from './lib/test';
4+
import type Results from './lib/results';
5+
6+
declare function harnessFunction(this: Test, name: string, opts: tape.TestOptions, cb: Test.TestCase): Test;
7+
declare function harnessFunction(this: Test, name: string, opts: tape.TestOptions): Test;
8+
declare function harnessFunction(this: Test, name: string, cb: Test.TestCase): Test;
9+
declare function harnessFunction(this: Test, name: string): Test;
10+
declare function harnessFunction(this: Test, opts: tape.TestOptions, cb: Test.TestCase): Test;
11+
declare function harnessFunction(this: Test, opts: tape.TestOptions): Test;
12+
declare function harnessFunction(this: Test, cb: Test.TestCase): Test;
13+
14+
declare function harnessFunction(this: void, name: string, opts: tape.TestOptions, cb: Test.TestCase): Test;
15+
declare function harnessFunction(this: void, name: string, opts: tape.TestOptions): Test;
16+
declare function harnessFunction(this: void, name: string, cb: Test.TestCase): Test;
17+
declare function harnessFunction(this: void, name: string): Test;
18+
declare function harnessFunction(this: void, opts: tape.TestOptions, cb: Test.TestCase): Test;
19+
declare function harnessFunction(this: void, opts: tape.TestOptions): Test;
20+
declare function harnessFunction(this: void, cb: Test.TestCase): Test;
21+
22+
declare namespace tape {
23+
export type TestOptions = {
24+
objectPrintDepth?: number | undefined;
25+
skip?: boolean | string | undefined;
26+
timeout?: number | undefined;
27+
todo?: boolean | string | undefined;
28+
};
29+
30+
export interface AssertOptions {
31+
skip?: boolean | string | undefined;
32+
todo?: boolean | string | undefined;
33+
message?: string | undefined;
34+
actual?: unknown;
35+
expected?: unknown;
36+
exiting?: boolean;
37+
}
38+
39+
export interface StreamOptions {
40+
objectMode?: boolean | undefined;
41+
}
42+
43+
function createStream(opts?: StreamOptions): ThroughStream;
44+
45+
export type CreateStream = typeof createStream;
46+
47+
export type HarnessEventHandler = (cb: Test.SyncCallback, ...rest: unknown[]) => void;
48+
49+
function only(name: string, cb: Test.TestCase): void;
50+
function only(name: string, opts: tape.TestOptions, cb: Test.TestCase): void;
51+
function only(cb: Test.TestCase): void;
52+
function only(opts: tape.TestOptions, cb?: Test.TestCase): void;
53+
54+
export type Harness = typeof harnessFunction & {
55+
run?: () => void;
56+
only: typeof only;
57+
_exitCode: number;
58+
_results: Results;
59+
_tests: Test[];
60+
close: () => void;
61+
createStream: CreateStream;
62+
onFailure: HarnessEventHandler;
63+
onFinish: HarnessEventHandler;
64+
}
65+
66+
export type HarnessConfig = {
67+
autoclose?: boolean;
68+
noOnly?: boolean;
69+
stream?: NodeJS.WritableStream | ThroughStream;
70+
exit?: boolean;
71+
} & StreamOptions;
72+
73+
function createHarness(conf_?: HarnessConfig): Harness;
74+
const Test: Test;
75+
const test: Harness;
76+
const skip: Test['skip'];
77+
78+
function getHarness(opts?: HarnessConfig): Harness;
79+
function run(): void;
80+
function onFailure(cb: Test.SyncCallback, ...rest: unknown[]): void;
81+
function onFinish(cb: Test.SyncCallback, ...rest: unknown[]): void
82+
function wait(): void;
83+
}
84+
85+
declare function tape(this: void | tape.Harness, name: string, opts: tape.TestOptions, cb: Test.TestCase): Test;
86+
declare function tape(this: void | tape.Harness, name: string, cb: Test.TestCase): Test;
87+
declare function tape(this: void | tape.Harness, opts?: tape.TestOptions): Test;
88+
declare function tape(this: void | tape.Harness, opts: tape.TestOptions, cb: Test.TestCase): Test;
89+
declare function tape(this: void | tape.Harness, cb: Test.TestCase): Test;
90+
declare function tape(this: void | tape.Harness, name: string): Test;
91+
92+
export = tape;

0 commit comments

Comments
 (0)