From 20dde569ba9f633ee862b7d834c5ef345a37482e Mon Sep 17 00:00:00 2001 From: Johnny Date: Sat, 25 Mar 2017 17:26:48 +0800 Subject: [PATCH 1/6] adding Frisby v0.8.5 typings --- types/frisby/frisby-tests.ts | 38 +++++++++++++++++++ types/frisby/index.d.ts | 73 ++++++++++++++++++++++++++++++++++++ types/frisby/tsconfig.json | 23 ++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 types/frisby/frisby-tests.ts create mode 100644 types/frisby/index.d.ts create mode 100644 types/frisby/tsconfig.json diff --git a/types/frisby/frisby-tests.ts b/types/frisby/frisby-tests.ts new file mode 100644 index 0000000000..801ea63be7 --- /dev/null +++ b/types/frisby/frisby-tests.ts @@ -0,0 +1,38 @@ +//Example from https://www.npmjs.com/package/frisby + +import frisby = require('frisby'); + +var URL = 'http://localhost:3000/'; +var URL_AUTH = 'http://username:password@localhost:3000/'; + +frisby.globalSetup({ // globalSetup is for ALL requests + request: { + headers: { 'X-Auth-Token': 'fa8426a0-8eaf-4d22-8e13-7c1b16a9370c' } + } +}); + +frisby.create('GET user johndoe') + .get(URL + '/users/3.json') + .expectStatus(200) + .expectJSONTypes({ + id: Number, + username: String, + is_admin: Boolean + }) + .expectJSON({ + id: 3, + username: 'johndoe', + is_admin: false + }) + // 'afterJSON' automatically parses response body as JSON and passes it as an argument + .afterJSON(function(user) { + // You can use any normal jasmine-style assertions here + expect(1+1).toEqual(2); + + // Use data from previous result in next test + frisby.create('Update user') + .put(URL_AUTH + '/users/' + user.id + '.json', {tags: ['jasmine', 'bdd']}) + .expectStatus(200) + .toss(); + }) +.toss(); \ No newline at end of file diff --git a/types/frisby/index.d.ts b/types/frisby/index.d.ts new file mode 100644 index 0000000000..b607574b7e --- /dev/null +++ b/types/frisby/index.d.ts @@ -0,0 +1,73 @@ +// Type definitions for Frisby v0.8.5 +// Project: https://github.com/vlucas/frisby +// Definitions by: Johnny Li +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare interface Frisby { + globalSetup(opts: any): any; + timeout(seconds?: number): Frisby; + reset(): Frisby; + not(): Frisby; + addHeader(key: string, content: string): Frisby; + addHeaders(headers: object): Frisby; + removeHeader(key: string): Frisby; + responseType(type: any): Frisby; + // HTTP Basic Auth + auth(username: string, password: string, digest: boolean): Frisby; + // HTTP Request + get(uri: string, params?: any): Frisby; + patch(uri: string, data?: any, params?: any): Frisby; + post(uri: string, data?: any, params?: any): Frisby; + put(uri: string, data?: any, params?: any): Frisby; + delete(uri: string, data?: any, params?: any): Frisby; + head(uri: string, params?: any): Frisby; + options(uri: string, params?: any): Frisby; + + expectMaxResponseTime(milliseconds: number): Frisby; + expectStatus(statusCode: number): Frisby; + expectHeader(header: string, content: string): Frisby; + expectHeaderContains(header: string, content: string): Frisby; + expectHeaderToMatch(header: string, pattern: RegExp): Frisby; + expectBodyContains(content: string): Frisby; + expectJSONTypes(json: any): Frisby; + expectJSONTypes(path: string, json: any): Frisby; + expectJSON(json: any): Frisby; + expectJSON(path: string, json: any): Frisby; + expectJSONSchema(path: string, jsonSchema: any): Frisby; + expectJSONLength(length: number): Frisby; + expectJSONLength(path: string, length: number): Frisby; + inspectRequest(): Frisby; + inspectResponse(): Frisby; + inspectHeaders(): Frisby; + inspectBody(): Frisby; + inspectJSON(): Frisby; + inspectStatus(): Frisby; + retry(count: number, delayInMilliseconds?: number): Frisby; + waits(delayInMilliseconds: number): Frisby; + after(callback: (...args: any[]) => void): Frisby; + afterJSON(callback: (...args: any[]) => void): Frisby; + exceptionHandler(fn: (...args: any[]) => void): Frisby; + toss(): void; + + create(msg: string): Frisby; + +} + +declare namespace jasmine { + interface Matchers { + toMatchOrBeNull(expected: any): boolean; + toMatchOrBeEmpty(expected: any): boolean; + toBeType(expected: any): boolean; + toBeTypeOrNull(expected: any): boolean; + toBeTypeOrUndefined(expected: any): boolean; + toContainJson(expected: any, isNot?: boolean): boolean; + toContainJsonTypes(expected: any, isNot?: boolean): boolean; + } +} + +declare const frisby: Frisby; +declare module "frisby" { + export = frisby; +} diff --git a/types/frisby/tsconfig.json b/types/frisby/tsconfig.json new file mode 100644 index 0000000000..5ff4c5d7f1 --- /dev/null +++ b/types/frisby/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "frisby-tests.ts" + ] +} \ No newline at end of file From 1d378f5353111893dd8d786aa0fdd8a8420730b9 Mon Sep 17 00:00:00 2001 From: Johnny Date: Sat, 25 Mar 2017 18:46:08 +0800 Subject: [PATCH 2/6] remove risby/index.d.ts bom --- types/frisby/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/frisby/index.d.ts b/types/frisby/index.d.ts index b607574b7e..ef7576b51c 100644 --- a/types/frisby/index.d.ts +++ b/types/frisby/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Frisby v0.8.5 +// Type definitions for Frisby v0.8.5 // Project: https://github.com/vlucas/frisby // Definitions by: Johnny Li // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped From f49c0e38910aaad9756583c0eb45b2d2c9c4a297 Mon Sep 17 00:00:00 2001 From: Johnny Date: Sat, 25 Mar 2017 19:07:02 +0800 Subject: [PATCH 3/6] test --- types/frisby/frisby-tests.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/types/frisby/frisby-tests.ts b/types/frisby/frisby-tests.ts index 801ea63be7..d5ac312b83 100644 --- a/types/frisby/frisby-tests.ts +++ b/types/frisby/frisby-tests.ts @@ -24,15 +24,4 @@ frisby.create('GET user johndoe') username: 'johndoe', is_admin: false }) - // 'afterJSON' automatically parses response body as JSON and passes it as an argument - .afterJSON(function(user) { - // You can use any normal jasmine-style assertions here - expect(1+1).toEqual(2); - - // Use data from previous result in next test - frisby.create('Update user') - .put(URL_AUTH + '/users/' + user.id + '.json', {tags: ['jasmine', 'bdd']}) - .expectStatus(200) - .toss(); - }) .toss(); \ No newline at end of file From f8660cbaceb610801789187b1131a952f8a8c8c9 Mon Sep 17 00:00:00 2001 From: Johnny Date: Sat, 25 Mar 2017 19:16:43 +0800 Subject: [PATCH 4/6] TypeScript Version: 2.2 --- types/frisby/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/frisby/index.d.ts b/types/frisby/index.d.ts index ef7576b51c..f9c413b2c4 100644 --- a/types/frisby/index.d.ts +++ b/types/frisby/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/vlucas/frisby // Definitions by: Johnny Li // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 /// From e605e6f3e36e78a526352da70e9c9a913819d57c Mon Sep 17 00:00:00 2001 From: Johnny Date: Mon, 27 Mar 2017 12:52:20 +0800 Subject: [PATCH 5/6] move const frisby into module --- types/frisby/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/frisby/index.d.ts b/types/frisby/index.d.ts index f9c413b2c4..2258568854 100644 --- a/types/frisby/index.d.ts +++ b/types/frisby/index.d.ts @@ -68,7 +68,7 @@ declare namespace jasmine { } } -declare const frisby: Frisby; declare module "frisby" { + const frisby: Frisby; export = frisby; } From 0c911a9ee737425c012df77d5e06d0bd22c53302 Mon Sep 17 00:00:00 2001 From: Johnny Date: Wed, 29 Mar 2017 00:34:11 +0800 Subject: [PATCH 6/6] 1. move jasmine namespace into global{} 2. put the const and the export = in the top-level. --- types/frisby/index.d.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/types/frisby/index.d.ts b/types/frisby/index.d.ts index 2258568854..449a73ead0 100644 --- a/types/frisby/index.d.ts +++ b/types/frisby/index.d.ts @@ -56,19 +56,20 @@ declare interface Frisby { } -declare namespace jasmine { - interface Matchers { - toMatchOrBeNull(expected: any): boolean; - toMatchOrBeEmpty(expected: any): boolean; - toBeType(expected: any): boolean; - toBeTypeOrNull(expected: any): boolean; - toBeTypeOrUndefined(expected: any): boolean; - toContainJson(expected: any, isNot?: boolean): boolean; - toContainJsonTypes(expected: any, isNot?: boolean): boolean; +declare global { + namespace jasmine { + interface Matchers { + toMatchOrBeNull(expected: any): boolean; + toMatchOrBeEmpty(expected: any): boolean; + toBeType(expected: any): boolean; + toBeTypeOrNull(expected: any): boolean; + toBeTypeOrUndefined(expected: any): boolean; + toContainJson(expected: any, isNot?: boolean): boolean; + toContainJsonTypes(expected: any, isNot?: boolean): boolean; + } } } -declare module "frisby" { - const frisby: Frisby; - export = frisby; -} +declare const frisby: Frisby; +export = frisby; +