From 52ee72c24ca35d99bd876d20de674aef840b2b0b Mon Sep 17 00:00:00 2001 From: Danny Cochran Date: Fri, 8 Jun 2018 09:58:35 -0700 Subject: [PATCH 1/4] plugin function expects SuperAgentRequest the plugin function actually takes a SuperAgentRequest, which includes properties like url, method, cookies, and agent. --- types/superagent/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/superagent/index.d.ts b/types/superagent/index.d.ts index 7daf5f47dc..e5a52ce3cd 100644 --- a/types/superagent/index.d.ts +++ b/types/superagent/index.d.ts @@ -150,7 +150,7 @@ declare namespace request { write(data: string | Buffer, encoding?: string): this; } - type Plugin = (req: Request) => void; + type Plugin = (req: SuperAgentRequest) => void; interface ProgressEvent { direction: 'download' | 'upload'; From e628172bc5d322666e6f0837ba1adf7849bb6594 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 12 Jun 2018 12:34:24 -0700 Subject: [PATCH 2/4] add tests for SuperAgent request --- types/superagent/superagent-tests.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/types/superagent/superagent-tests.ts b/types/superagent/superagent-tests.ts index 66046759f1..46766f8d9e 100644 --- a/types/superagent/superagent-tests.ts +++ b/types/superagent/superagent-tests.ts @@ -390,3 +390,18 @@ request .then(response => { // reads 404 page as a successful response }); + +// Test that the "Plugin" type from "use" provides a SuperAgentRequest rather than a Request, +// which has additional properties. +const echoPlugin = (request: request.SuperAgentRequest) => { + req.url = '' + req.url; + req.cookies = '' + req.cookies; + if (req.method) { + req.url = '/echo' + } +}; + +request + .get('/echo') + .use(echoPlugin) + .end(); \ No newline at end of file From 7bf6b02b0e9a1139967ecb5079eacbe25465a4db Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 12 Jun 2018 12:38:22 -0700 Subject: [PATCH 3/4] add trailing newline --- types/superagent/superagent-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/superagent/superagent-tests.ts b/types/superagent/superagent-tests.ts index 46766f8d9e..b2e00c6698 100644 --- a/types/superagent/superagent-tests.ts +++ b/types/superagent/superagent-tests.ts @@ -404,4 +404,4 @@ const echoPlugin = (request: request.SuperAgentRequest) => { request .get('/echo') .use(echoPlugin) - .end(); \ No newline at end of file + .end(); From 031a3356f65a8f009e774bd112daf27552e28a68 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 18 Jun 2018 14:19:52 -0700 Subject: [PATCH 4/4] add semicolon --- types/superagent/superagent-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/superagent/superagent-tests.ts b/types/superagent/superagent-tests.ts index b2e00c6698..0c4b51f31e 100644 --- a/types/superagent/superagent-tests.ts +++ b/types/superagent/superagent-tests.ts @@ -397,7 +397,7 @@ const echoPlugin = (request: request.SuperAgentRequest) => { req.url = '' + req.url; req.cookies = '' + req.cookies; if (req.method) { - req.url = '/echo' + req.url = '/echo'; } };