From edd97d5bd52dc96042d715c83d82a8e6a70749fc Mon Sep 17 00:00:00 2001 From: Alex Varju Date: Thu, 5 Sep 2013 14:56:28 -0700 Subject: [PATCH] Add superagent and supertest definitions --- superagent/superagent-tests.ts | 12 +++++ superagent/superagent.d.ts | 84 ++++++++++++++++++++++++++++++++++ supertest/supertest-tests.ts | 16 +++++++ supertest/supertest.d.ts | 53 +++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 superagent/superagent-tests.ts create mode 100644 superagent/superagent.d.ts create mode 100644 supertest/supertest-tests.ts create mode 100644 supertest/supertest.d.ts diff --git a/superagent/superagent-tests.ts b/superagent/superagent-tests.ts new file mode 100644 index 0000000000..23961b30ab --- /dev/null +++ b/superagent/superagent-tests.ts @@ -0,0 +1,12 @@ +/// + +import superagent = require('superagent') + +var agent = superagent.agent(); +agent + .post('http://localhost:3000/signin') + .send({ email: 'test@dummy.com', password: 'bacon' }) + .end((err, res) => { + if (err) throw err; + if (res.status !== 200) throw new Error('bad status ' + res.status); + }); diff --git a/superagent/superagent.d.ts b/superagent/superagent.d.ts new file mode 100644 index 0000000000..ee2aaa5f48 --- /dev/null +++ b/superagent/superagent.d.ts @@ -0,0 +1,84 @@ +// Type definitions for SuperAgent 0.15.4 +// Project: https://github.com/visionmedia/superagent +// Definitions by: Alex Varju +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "superagent" { + export interface Response { + text: string; + body: Object; + header: Object; + type: string; + charset: string; + status: number; + statusType: number; + info: boolean; + ok: boolean; + redirect: boolean; + clientError: boolean; + serverError: boolean; + error: any; + accepted: boolean; + noContent: boolean; + badRequest: boolean; + unauthorized: boolean; + notAcceptable: boolean; + notFound: boolean; + forbidden: boolean; + get(header: string): string; + } + + export interface Request { + attach(field: string, file: string, filename: string): Request; + redirects(n: number): Request; + part(): Request; + set(field: string, val: string): Request; + set(field: Object): Request; + get(field: string): string; + type(val: string): Request; + query(val: Object): Request; + send(data: string): Request; + send(data: Object): Request; + write(data: string, encoding: string): boolean; + write(data: NodeBuffer, encoding: string): boolean; + pipe(stream: WritableStream, options?: Object): WritableStream; + buffer(val: boolean): Request; + timeout(ms: number): Request; + clearTimeout(): Request; + abort(): void; + auth(user: string, name: string): Request; + field(name: string, val: string): Request; + end(callback?: (err: Error, res: Response) => void): Request; + } + + export interface Agent { + get(url: string, callback?: (err: Error, res: Response) => void): Request; + post(url: string, callback?: (err: Error, res: Response) => void): Request; + put(url: string, callback?: (err: Error, res: Response) => void): Request; + head(url: string, callback?: (err: Error, res: Response) => void): Request; + del(url: string, callback?: (err: Error, res: Response) => void): Request; + options(url: string, callback?: (err: Error, res: Response) => void): Request; + trace(url: string, callback?: (err: Error, res: Response) => void): Request; + copy(url: string, callback?: (err: Error, res: Response) => void): Request; + lock(url: string, callback?: (err: Error, res: Response) => void): Request; + mkcol(url: string, callback?: (err: Error, res: Response) => void): Request; + move(url: string, callback?: (err: Error, res: Response) => void): Request; + propfind(url: string, callback?: (err: Error, res: Response) => void): Request; + proppatch(url: string, callback?: (err: Error, res: Response) => void): Request; + unlock(url: string, callback?: (err: Error, res: Response) => void): Request; + report(url: string, callback?: (err: Error, res: Response) => void): Request; + mkactivity(url: string, callback?: (err: Error, res: Response) => void): Request; + checkout(url: string, callback?: (err: Error, res: Response) => void): Request; + merge(url: string, callback?: (err: Error, res: Response) => void): Request; + //m-search(url: string, callback?: (err: Error, res: Response) => void): Request; + notify(url: string, callback?: (err: Error, res: Response) => void): Request; + subscribe(url: string, callback?: (err: Error, res: Response) => void): Request; + unsubscribe(url: string, callback?: (err: Error, res: Response) => void): Request; + patch(url: string, callback?: (err: Error, res: Response) => void): Request; + parse(fn: Function): Request; + } + + export function agent(): Agent; +} diff --git a/supertest/supertest-tests.ts b/supertest/supertest-tests.ts new file mode 100644 index 0000000000..1a1d60db79 --- /dev/null +++ b/supertest/supertest-tests.ts @@ -0,0 +1,16 @@ +/// +/// + +import supertest = require('supertest') +import express = require('express'); + +var app = express(); + +supertest(app) + .get('/user') + .expect('Content-Type', /json/) + .expect('Content-Length', '20') + .expect(201) + .end((err, res) => { + if (err) throw err; + }); diff --git a/supertest/supertest.d.ts b/supertest/supertest.d.ts new file mode 100644 index 0000000000..8a2069d336 --- /dev/null +++ b/supertest/supertest.d.ts @@ -0,0 +1,53 @@ +// Type definitions for SuperTest 0.8.0 +// Project: https://github.com/visionmedia/supertest +// Definitions by: Alex Varju +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "supertest" { + import superagent = require('superagent'); + + module supertest { + interface Test extends superagent.Request { + url: string; + serverAddress(app: any, path: string): string; + expect(status: number, callback?: (err: Error, res: superagent.Response) => void): Test; + expect(status: number, body: string, callback?: (err: Error, res: superagent.Response) => void): Test; + expect(body: string, callback?: (err: Error, res: superagent.Response) => void): Test; + expect(body: RegExp, callback?: (err: Error, res: superagent.Response) => void): Test; + expect(body: Object, callback?: (err: Error, res: superagent.Response) => void): Test; + expect(field: string, val: string, callback?: (err: Error, res: superagent.Response) => void): Test; + expect(field: string, val: RegExp, callback?: (err: Error, res: superagent.Response) => void): Test; + } + + interface SuperTest { + get(url: string): Test; + post(url: string): Test; + put(url: string): Test; + head(url: string): Test; + del(url: string): Test; + options(url: string): Test; + trace(url: string): Test; + copy(url: string): Test; + lock(url: string): Test; + mkcol(url: string): Test; + move(url: string): Test; + propfind(url: string): Test; + proppatch(url: string): Test; + unlock(url: string): Test; + report(url: string): Test; + mkactivity(url: string): Test; + checkout(url: string): Test; + merge(url: string): Test; + //m-search(url: string): Test; + notify(url: string): Test; + subscribe(url: string): Test; + unsubscribe(url: string): Test; + patch(url: string): Test; + } + } + + function supertest(app: any): supertest.SuperTest; + export = supertest; +}