diff --git a/types/test-listen/index.d.ts b/types/test-listen/index.d.ts new file mode 100644 index 0000000000..741ffa0695 --- /dev/null +++ b/types/test-listen/index.d.ts @@ -0,0 +1,13 @@ +// 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; + +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..c5bc189ee8 --- /dev/null +++ b/types/test-listen/test-listen-tests.ts @@ -0,0 +1,25 @@ +import * as http from 'http'; +import testListen = require('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" }