From 1ffbaa945294da3ace273b721b004122910c42f9 Mon Sep 17 00:00:00 2001 From: Stephen Mathieson Date: Tue, 26 Jun 2018 16:50:09 -0400 Subject: [PATCH 1/3] add types for test-listen https://github.com/zeit/test-listen --- types/test-listen/index.d.ts | 15 +++++++++++++++ types/test-listen/test-listen-tests.ts | 25 +++++++++++++++++++++++++ types/test-listen/tsconfig.json | 23 +++++++++++++++++++++++ types/test-listen/tslint.json | 1 + 4 files changed, 64 insertions(+) create mode 100644 types/test-listen/index.d.ts create mode 100644 types/test-listen/test-listen-tests.ts create mode 100644 types/test-listen/tsconfig.json create mode 100644 types/test-listen/tslint.json diff --git a/types/test-listen/index.d.ts b/types/test-listen/index.d.ts new file mode 100644 index 0000000000..0bf7c00dd8 --- /dev/null +++ b/types/test-listen/index.d.ts @@ -0,0 +1,15 @@ +// Type definitions for test-listen 1.1 +// Project: https://github.com/zeit/test-listen +// Definitions by: Stephen Mathieson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// + +import { Server } from "net"; + +declare function testListen(srv: Server, hostname?: string): Promise; + +declare namespace testListen {} + +export = testListen; diff --git a/types/test-listen/test-listen-tests.ts b/types/test-listen/test-listen-tests.ts new file mode 100644 index 0000000000..1161772e09 --- /dev/null +++ b/types/test-listen/test-listen-tests.ts @@ -0,0 +1,25 @@ +import * as http from 'http'; +import * as testListen from 'test-listen'; + +const test = async (): Promise => { + const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse): void => { + res.write('hello'); + res.end(); + }); + + const addr = await testListen(server); + console.log(addr); +}; + +const testWithHostname = async (): Promise => { + const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse): void => { + res.write('hello'); + res.end(); + }); + + const addr = await testListen(server, '127.0.0.1'); + console.log(addr); +}; + +test(); +testWithHostname(); diff --git a/types/test-listen/tsconfig.json b/types/test-listen/tsconfig.json new file mode 100644 index 0000000000..2a2d45987e --- /dev/null +++ b/types/test-listen/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "test-listen-tests.ts" + ] +} diff --git a/types/test-listen/tslint.json b/types/test-listen/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/test-listen/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From b72ddac07b722413a43dba577019184e7b859317 Mon Sep 17 00:00:00 2001 From: Stephen Mathieson Date: Wed, 27 Jun 2018 10:09:05 -0400 Subject: [PATCH 2/3] remove empty namespace hack --- types/test-listen/index.d.ts | 2 -- types/test-listen/test-listen-tests.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/types/test-listen/index.d.ts b/types/test-listen/index.d.ts index 0bf7c00dd8..741ffa0695 100644 --- a/types/test-listen/index.d.ts +++ b/types/test-listen/index.d.ts @@ -10,6 +10,4 @@ import { Server } from "net"; declare function testListen(srv: Server, hostname?: string): Promise; -declare namespace testListen {} - export = testListen; diff --git a/types/test-listen/test-listen-tests.ts b/types/test-listen/test-listen-tests.ts index 1161772e09..c5bc189ee8 100644 --- a/types/test-listen/test-listen-tests.ts +++ b/types/test-listen/test-listen-tests.ts @@ -1,5 +1,5 @@ import * as http from 'http'; -import * as testListen from 'test-listen'; +import testListen = require('test-listen'); const test = async (): Promise => { const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse): void => { From 7e86b2925f6bb8fdb0d7cb6346e6bb8a5bf0021e Mon Sep 17 00:00:00 2001 From: Stephen Mathieson Date: Wed, 27 Jun 2018 11:18:43 -0400 Subject: [PATCH 3/3] trigger travis build