Permalink
Browse files

Auto generate TypeScript definition to allow chaining (#884)

  • Loading branch information...
1 parent 05f1890 commit 1dd6d5b9127a6850d9a03c242e677ea359d67053 @ivogabe ivogabe committed with sindresorhus Jul 13, 2016
Showing with 260 additions and 215 deletions.
  1. +1 −0 .gitignore
  2. +0 −212 index.d.ts
  3. +2 −0 lib/runner.js
  4. +9 −3 package.json
  5. +124 −0 types/base.d.ts
  6. +124 −0 types/make.js
View
@@ -2,3 +2,4 @@ node_modules
.nyc_output
coverage
bench/.results
+types/generated.d.ts
View
@@ -1,212 +0,0 @@
-export interface Observable {
- subscribe(observer: (value: {}) => void): void;
-}
-
-export type Test = (t: TestContext) => Promise<void> | Iterator<any> | Observable | void;
-export type ContextualTest = (t: ContextualTestContext) => Promise<void> | Iterator<any> | Observable | void;
-export type SerialTest = (t: TestContext) => void;
-export type ContextualSerialTest = (t: ContextualTestContext) => void;
-export type CallbackTest = (t: CallbackTestContext) => void;
-export type ContextualCallbackTest = (t: ContextualCallbackTestContext) => void;
-
-export interface Runner {
- (name: string, run: Test): void;
- (run: Test): void;
- skip: Runner;
- cb: CallbackRunner;
-}
-export interface AfterRunner extends Runner {
- always: Runner;
-}
-export interface ContextualRunner {
- (name: string, run: ContextualTest): void;
- (run: ContextualTest): void;
- skip: ContextualRunner;
- cb: ContextualCallbackRunner;
-}
-export interface ContextualAfterRunner extends ContextualRunner {
- always: ContextualRunner;
-}
-export interface SerialRunner {
- (name: string, run: SerialTest): void;
- (run: SerialTest): void;
- skip: SerialRunner;
-}
-export interface ContextualSerialRunner {
- (name: string, run: ContextualSerialTest): void;
- (run: ContextualSerialTest): void;
- skip: ContextualSerialRunner;
-}
-export interface CallbackRunner {
- (name: string, run: CallbackTest): void;
- (run: CallbackTest): void;
- skip: CallbackRunner;
-}
-export interface ContextualCallbackRunner {
- (name: string, run: ContextualCallbackTest): void;
- (run: ContextualCallbackTest): void;
- skip: ContextualCallbackRunner;
-}
-
-export function test(name: string, run: ContextualTest): void;
-export function test(run: ContextualTest): void;
-export namespace test {
- export const before: Runner;
- export const after: AfterRunner;
- export const beforeEach: ContextualRunner;
- export const afterEach: ContextualAfterRunner;
-
- export const skip: typeof test;
- export const only: typeof test;
-
- export function serial(name: string, run: ContextualSerialTest): void;
- export function serial(run: ContextualSerialTest): void;
- export function failing(name: string, run: ContextualCallbackTest): void;
- export function failing(run: ContextualCallbackTest): void;
- export function cb(name: string, run: ContextualCallbackTest): void;
- export function cb(run: ContextualCallbackTest): void;
- export function todo(name: string): void;
-}
-export namespace test.serial {
- export const before: SerialRunner;
- export const after: SerialRunner;
- export const beforeEach: ContextualSerialRunner;
- export const afterEach: ContextualSerialRunner;
-
- export const skip: typeof test.serial;
- export const only: typeof test.serial;
-
- export function cb(name: string, run: ContextualCallbackTest): void;
- export function cb(run: ContextualCallbackTest): void;
-}
-export namespace test.failing {
- export const before: CallbackRunner;
- export const after: CallbackRunner;
- export const beforeEach: ContextualCallbackRunner;
- export const afterEach: ContextualCallbackRunner;
-
- export const skip: typeof test.cb;
- export const only: typeof test.cb;
-
- export function cb(name: string, run: ContextualCallbackTest): void;
- export function cb(run: ContextualCallbackTest): void;
-}
-export namespace test.cb {
- export const before: CallbackRunner;
- export const after: CallbackRunner;
- export const beforeEach: ContextualCallbackRunner;
- export const afterEach: ContextualCallbackRunner;
-
- export const skip: typeof test.cb;
- export const only: typeof test.cb;
-}
-export default test;
-
-export type ErrorValidator
- = (new (...args: any[]) => any)
- | RegExp
- | string
- | ((error: any) => boolean);
-
-export interface AssertContext {
- /**
- * Passing assertion.
- */
- pass(message?: string): void;
- /**
- * Failing assertion.
- */
- fail(message?: string): void;
- /**
- * Assert that value is truthy.
- */
- truthy(value: any, message?: string): void;
- /**
- * Assert that value is falsy.
- */
- falsy(value: any, message?: string): void;
- /**
- * DEPRECATED, use `truthy`. Assert that value is truthy.
- */
- ok(value: any, message?: string): void;
- /**
- * DEPRECATED, use `falsy`. Assert that value is falsy.
- */
- notOk(value: any, message?: string): void;
- /**
- * Assert that value is true.
- */
- true(value: boolean, message?: string): void;
- /**
- * Assert that value is false.
- */
- false(value: boolean, message?: string): void;
- /**
- * Assert that value is equal to expected.
- */
- is<U>(value: U, expected: U, message?: string): void;
- /**
- * Assert that value is not equal to expected.
- */
- not<U>(value: U, expected: U, message?: string): void;
- /**
- * Assert that value is deep equal to expected.
- */
- deepEqual<U>(value: U, expected: U, message?: string): void;
- /**
- * Assert that value is not deep equal to expected.
- */
- notDeepEqual<U>(value: U, expected: U, message?: string): void;
- /**
- * Assert that function throws an error or promise rejects.
- * @param error Can be a constructor, regex, error message or validation function.
- */
- /**
- * DEPRECATED, use `deepEqual`. Assert that value is deep equal to expected.
- */
- same<U>(value: U, expected: U, message?: string): void;
- /**
- * DEPRECATED use `notDeepEqual`. Assert that value is not deep equal to expected.
- */
- notSame<U>(value: U, expected: U, message?: string): void;
- /**
- * Assert that function throws an error or promise rejects.
- * @param error Can be a constructor, regex, error message or validation function.
- */
- throws(value: Promise<{}>, error?: ErrorValidator, message?: string): Promise<any>;
- throws(value: () => void, error?: ErrorValidator, message?: string): any;
- /**
- * Assert that function doesn't throw an error or promise resolves.
- */
- notThrows<U>(value: Promise<U>, message?: string): Promise<U>;
- notThrows(value: () => void, message?: string): void;
- /**
- * Assert that contents matches regex.
- */
- regex(contents: string, regex: RegExp, message?: string): void;
- /**
- * Assert that error is falsy.
- */
- ifError(error: any, message?: string): void;
-}
-export interface TestContext extends AssertContext {
- /**
- * Plan how many assertion there are in the test.
- * The test will fail if the actual assertion count doesn't match planned assertions.
- */
- plan(count: number): void;
-
- skip: AssertContext;
-}
-export interface CallbackTestContext extends TestContext {
- /**
- * End the test.
- */
- end(): void;
-}
-export interface ContextualTestContext extends TestContext {
- context: any;
-}
-export interface ContextualCallbackTestContext extends CallbackTestContext {
- context: any;
-}
View
@@ -198,3 +198,5 @@ Runner.prototype.run = function (options) {
return Promise.resolve(this.tests.build(this._bail).run()).then(this._buildStats);
};
+
+Runner._chainableMethods = chainableMethods.chainableMethods;
View
@@ -33,18 +33,21 @@
}
],
"bin": "cli.js",
+ "typings": "types/generated.d.ts",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && nyc --cache --reporter=lcov --reporter=text tap --no-cov --timeout=150 test/*.js test/reporters/*.js",
"test-win": "tap --no-cov --reporter=classic --timeout=150 test/*.js test/reporters/*.js",
- "visual": "node test/visual/run-visual-tests.js"
+ "visual": "node test/visual/run-visual-tests.js",
+ "prepublish": "npm run make-ts",
+ "make-ts": "babel-node --presets=babel-preset-es2015 --plugins=transform-runtime types/make.js"
},
"files": [
"lib",
"*.js",
- "index.d.ts"
+ "types/generated.d.ts"
],
"keywords": [
"test",
@@ -153,6 +156,7 @@
"update-notifier": "^1.0.0"
},
"devDependencies": {
+ "babel-cli": "^6.10.1",
"babel-preset-react": "^6.5.0",
"cli-table2": "^0.2.0",
"coveralls": "^2.11.4",
@@ -182,7 +186,9 @@
},
"overrides": [
{
- "files": ["test/**/*.js"],
+ "files": [
+ "test/**/*.js"
+ ],
"rules": {
"max-lines": 0
}
View
@@ -0,0 +1,124 @@
+export default test;
+
+export type ErrorValidator
+ = (new (...args: any[]) => any)
+ | RegExp
+ | string
+ | ((error: any) => boolean);
+
+export interface Observable {
+ subscribe(observer: (value: {}) => void): void;
+}
+
+export type Test = (t: TestContext) => PromiseLike<void> | Iterator<any> | Observable | void;
+export type ContextualTest = (t: ContextualTestContext) => PromiseLike<void> | Iterator<any> | Observable | void;
+export type CallbackTest = (t: CallbackTestContext) => void;
+export type ContextualCallbackTest = (t: ContextualCallbackTestContext) => void;
+
+export interface AssertContext {
+ /**
+ * Passing assertion.
+ */
+ pass(message?: string): void;
+ /**
+ * Failing assertion.
+ */
+ fail(message?: string): void;
+ /**
+ * Assert that value is truthy.
+ */
+ truthy(value: any, message?: string): void;
+ /**
+ * Assert that value is falsy.
+ */
+ falsy(value: any, message?: string): void;
+ /**
+ * DEPRECATED, use `truthy`. Assert that value is truthy.
+ */
+ ok(value: any, message?: string): void;
+ /**
+ * DEPRECATED, use `falsy`. Assert that value is falsy.
+ */
+ notOk(value: any, message?: string): void;
+ /**
+ * Assert that value is true.
+ */
+ true(value: boolean, message?: string): void;
+ /**
+ * Assert that value is false.
+ */
+ false(value: boolean, message?: string): void;
+ /**
+ * Assert that value is equal to expected.
+ */
+ is<U>(value: U, expected: U, message?: string): void;
+ /**
+ * Assert that value is not equal to expected.
+ */
+ not<U>(value: U, expected: U, message?: string): void;
+ /**
+ * Assert that value is deep equal to expected.
+ */
+ deepEqual<U>(value: U, expected: U, message?: string): void;
+ /**
+ * Assert that value is not deep equal to expected.
+ */
+ notDeepEqual<U>(value: U, expected: U, message?: string): void;
+ /**
+ * Assert that function throws an error or promise rejects.
+ * DEPRECATED, use `deepEqual`. Assert that value is deep equal to expected.
+ * @param error Can be a constructor, regex, error message or validation function.
+ */
+ same<U>(value: U, expected: U, message?: string): void;
+ /**
+ * DEPRECATED use `notDeepEqual`. Assert that value is not deep equal to expected.
+ */
+ notSame<U>(value: U, expected: U, message?: string): void;
+ /**
+ * Assert that function throws an error or promise rejects.
+ * @param error Can be a constructor, regex, error message or validation function.
+ */
+ throws(value: PromiseLike<any>, error?: ErrorValidator, message?: string): Promise<any>;
+ throws(value: () => void, error?: ErrorValidator, message?: string): any;
+ /**
+ * Assert that function doesn't throw an error or promise resolves.
+ */
+ notThrows<U>(value: PromiseLike<U>, message?: string): Promise<U>;
+ notThrows(value: () => void, message?: string): void;
+ /**
+ * Assert that contents matches regex.
+ */
+ regex(contents: string, regex: RegExp, message?: string): void;
+ /**
+ * Assert that contents does not match regex.
+ */
+ notRegex(contents, regex, message?: string): void;
+ /**
+ * Assert that error is falsy.
+ */
+ ifError(error: any, message?: string): void;
+}
+export interface TestContext extends AssertContext {
+ /**
+ * Plan how many assertion there are in the test.
+ * The test will fail if the actual assertion count doesn't match planned assertions.
+ */
+ plan(count: number): void;
+
+ skip: AssertContext;
+}
+export interface CallbackTestContext extends TestContext {
+ /**
+ * End the test.
+ */
+ end(): void;
+}
+export interface ContextualTestContext extends TestContext {
+ context: any;
+}
+export interface ContextualCallbackTestContext extends CallbackTestContext {
+ context: any;
+}
+
+export function test(name: string, run: ContextualTest): void;
+export function test(run: ContextualTest): void;
Oops, something went wrong.

0 comments on commit 1dd6d5b

Please sign in to comment.