Skip to content

Commit 1dd6d5b

Browse files
ivogabesindresorhus
authored andcommitted
Auto generate TypeScript definition to allow chaining (#884)
1 parent 05f1890 commit 1dd6d5b

File tree

6 files changed

+260
-215
lines changed

6 files changed

+260
-215
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
.nyc_output
33
coverage
44
bench/.results
5+
types/generated.d.ts

index.d.ts

Lines changed: 0 additions & 212 deletions
This file was deleted.

lib/runner.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,5 @@ Runner.prototype.run = function (options) {
198198

199199
return Promise.resolve(this.tests.build(this._bail).run()).then(this._buildStats);
200200
};
201+
202+
Runner._chainableMethods = chainableMethods.chainableMethods;

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,21 @@
3333
}
3434
],
3535
"bin": "cli.js",
36+
"typings": "types/generated.d.ts",
3637
"engines": {
3738
"node": ">=0.10.0"
3839
},
3940
"scripts": {
4041
"test": "xo && nyc --cache --reporter=lcov --reporter=text tap --no-cov --timeout=150 test/*.js test/reporters/*.js",
4142
"test-win": "tap --no-cov --reporter=classic --timeout=150 test/*.js test/reporters/*.js",
42-
"visual": "node test/visual/run-visual-tests.js"
43+
"visual": "node test/visual/run-visual-tests.js",
44+
"prepublish": "npm run make-ts",
45+
"make-ts": "babel-node --presets=babel-preset-es2015 --plugins=transform-runtime types/make.js"
4346
},
4447
"files": [
4548
"lib",
4649
"*.js",
47-
"index.d.ts"
50+
"types/generated.d.ts"
4851
],
4952
"keywords": [
5053
"test",
@@ -153,6 +156,7 @@
153156
"update-notifier": "^1.0.0"
154157
},
155158
"devDependencies": {
159+
"babel-cli": "^6.10.1",
156160
"babel-preset-react": "^6.5.0",
157161
"cli-table2": "^0.2.0",
158162
"coveralls": "^2.11.4",
@@ -182,7 +186,9 @@
182186
},
183187
"overrides": [
184188
{
185-
"files": ["test/**/*.js"],
189+
"files": [
190+
"test/**/*.js"
191+
],
186192
"rules": {
187193
"max-lines": 0
188194
}

types/base.d.ts

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
export default test;
2+
3+
export type ErrorValidator
4+
= (new (...args: any[]) => any)
5+
| RegExp
6+
| string
7+
| ((error: any) => boolean);
8+
9+
export interface Observable {
10+
subscribe(observer: (value: {}) => void): void;
11+
}
12+
13+
export type Test = (t: TestContext) => PromiseLike<void> | Iterator<any> | Observable | void;
14+
export type ContextualTest = (t: ContextualTestContext) => PromiseLike<void> | Iterator<any> | Observable | void;
15+
export type CallbackTest = (t: CallbackTestContext) => void;
16+
export type ContextualCallbackTest = (t: ContextualCallbackTestContext) => void;
17+
18+
export interface AssertContext {
19+
/**
20+
* Passing assertion.
21+
*/
22+
pass(message?: string): void;
23+
/**
24+
* Failing assertion.
25+
*/
26+
fail(message?: string): void;
27+
/**
28+
* Assert that value is truthy.
29+
*/
30+
truthy(value: any, message?: string): void;
31+
/**
32+
* Assert that value is falsy.
33+
*/
34+
falsy(value: any, message?: string): void;
35+
/**
36+
* DEPRECATED, use `truthy`. Assert that value is truthy.
37+
*/
38+
ok(value: any, message?: string): void;
39+
/**
40+
* DEPRECATED, use `falsy`. Assert that value is falsy.
41+
*/
42+
notOk(value: any, message?: string): void;
43+
/**
44+
* Assert that value is true.
45+
*/
46+
true(value: boolean, message?: string): void;
47+
/**
48+
* Assert that value is false.
49+
*/
50+
false(value: boolean, message?: string): void;
51+
/**
52+
* Assert that value is equal to expected.
53+
*/
54+
is<U>(value: U, expected: U, message?: string): void;
55+
/**
56+
* Assert that value is not equal to expected.
57+
*/
58+
not<U>(value: U, expected: U, message?: string): void;
59+
/**
60+
* Assert that value is deep equal to expected.
61+
*/
62+
deepEqual<U>(value: U, expected: U, message?: string): void;
63+
/**
64+
* Assert that value is not deep equal to expected.
65+
*/
66+
notDeepEqual<U>(value: U, expected: U, message?: string): void;
67+
/**
68+
* Assert that function throws an error or promise rejects.
69+
* DEPRECATED, use `deepEqual`. Assert that value is deep equal to expected.
70+
* @param error Can be a constructor, regex, error message or validation function.
71+
*/
72+
same<U>(value: U, expected: U, message?: string): void;
73+
/**
74+
* DEPRECATED use `notDeepEqual`. Assert that value is not deep equal to expected.
75+
*/
76+
notSame<U>(value: U, expected: U, message?: string): void;
77+
/**
78+
* Assert that function throws an error or promise rejects.
79+
* @param error Can be a constructor, regex, error message or validation function.
80+
*/
81+
throws(value: PromiseLike<any>, error?: ErrorValidator, message?: string): Promise<any>;
82+
throws(value: () => void, error?: ErrorValidator, message?: string): any;
83+
/**
84+
* Assert that function doesn't throw an error or promise resolves.
85+
*/
86+
notThrows<U>(value: PromiseLike<U>, message?: string): Promise<U>;
87+
notThrows(value: () => void, message?: string): void;
88+
/**
89+
* Assert that contents matches regex.
90+
*/
91+
regex(contents: string, regex: RegExp, message?: string): void;
92+
/**
93+
* Assert that contents does not match regex.
94+
*/
95+
notRegex(contents, regex, message?: string): void;
96+
/**
97+
* Assert that error is falsy.
98+
*/
99+
ifError(error: any, message?: string): void;
100+
}
101+
export interface TestContext extends AssertContext {
102+
/**
103+
* Plan how many assertion there are in the test.
104+
* The test will fail if the actual assertion count doesn't match planned assertions.
105+
*/
106+
plan(count: number): void;
107+
108+
skip: AssertContext;
109+
}
110+
export interface CallbackTestContext extends TestContext {
111+
/**
112+
* End the test.
113+
*/
114+
end(): void;
115+
}
116+
export interface ContextualTestContext extends TestContext {
117+
context: any;
118+
}
119+
export interface ContextualCallbackTestContext extends CallbackTestContext {
120+
context: any;
121+
}
122+
123+
export function test(name: string, run: ContextualTest): void;
124+
export function test(run: ContextualTest): void;

0 commit comments

Comments
 (0)