From 8ce13f0c97cf56afb48f01ab2f66a63a9e8e9005 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Thu, 6 Apr 2017 16:11:19 +0100 Subject: [PATCH 1/2] Set up regression testing for TypeScript --- package.json | 3 ++- test/ts-types/.gitignore | 1 + test/ts-types/tsconfig.json | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/ts-types/.gitignore create mode 100644 test/ts-types/tsconfig.json diff --git a/package.json b/package.json index 3b771f2ea..6cd97b092 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "node": ">=4" }, "scripts": { - "test": "xo && flow check test/flow-types && nyc tap --no-cov --timeout=150 --jobs=4 test/*.js test/reporters/*.js", + "test": "xo && flow check test/flow-types && tsc -p test/ts-types && nyc tap --no-cov --timeout=150 --jobs=4 test/*.js test/reporters/*.js", "test-win": "tap --no-cov --reporter=classic --timeout=150 --jobs=4 test/*.js test/reporters/*.js", "visual": "node test/visual/run-visual-tests.js", "prepublish": "npm run make-ts", @@ -188,6 +188,7 @@ "tap": "^10.0.0", "temp-write": "^3.1.0", "touch": "^1.0.0", + "typescript": "^2.2.2", "xo": "^0.18.0", "zen-observable": "^0.5.1" }, diff --git a/test/ts-types/.gitignore b/test/ts-types/.gitignore new file mode 100644 index 000000000..a6c7c2852 --- /dev/null +++ b/test/ts-types/.gitignore @@ -0,0 +1 @@ +*.js diff --git a/test/ts-types/tsconfig.json b/test/ts-types/tsconfig.json new file mode 100644 index 000000000..600a425b7 --- /dev/null +++ b/test/ts-types/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": false, + "sourceMap": false + } +} From 33dcf44e6ef2bbf675437de6bbf427ba7484c4f1 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Thu, 6 Apr 2017 16:20:54 +0100 Subject: [PATCH 2/2] Fix TypeScript definition for callback tests Fixes #1347 --- test/ts-types/regression-1347.ts | 5 +++++ types/base.d.ts | 7 +++++++ types/make.js | 6 +++++- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/ts-types/regression-1347.ts diff --git a/test/ts-types/regression-1347.ts b/test/ts-types/regression-1347.ts new file mode 100644 index 000000000..4a864bbe6 --- /dev/null +++ b/test/ts-types/regression-1347.ts @@ -0,0 +1,5 @@ +import test from '../..' + +test.cb(t => { + t.end() +}) diff --git a/types/base.d.ts b/types/base.d.ts index c4faed073..b23afa0af 100644 --- a/types/base.d.ts +++ b/types/base.d.ts @@ -119,6 +119,13 @@ interface RegisterBase { (run: Macros>, ...args: any[]): void; } +interface CallbackRegisterBase { + (name: string, run: GenericCallbackTest): void; + (run: GenericCallbackTest): void; + (name: string, run: Macros>, ...args: any[]): void; + (run: Macros>, ...args: any[]): void; +} + export default test; export const test: RegisterContextual; export interface RegisterContextual extends Register> { diff --git a/types/make.js b/types/make.js index 46990fa88..9516fbb61 100644 --- a/types/make.js +++ b/types/make.js @@ -74,7 +74,11 @@ function generatePrefixed(prefix) { // 'todo' functions don't have a function argument, just a string output += `\t${part}: (name: string) => void;\n`; } else { - output += `\t${part}: RegisterBase`; + if (arrayHas(parts)('cb')) { + output += `\t${part}: CallbackRegisterBase`; + } else { + output += `\t${part}: RegisterBase`; + } if (hasChildren(parts)) { // This chain can be continued, make the property an intersection type with the chain continuation