diff options
| author | 8cy <[email protected]> | 2020-04-03 02:48:28 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-04-03 02:48:28 -0700 |
| commit | f9159ea2d994e14180fb02ab562f0119513e67cf (patch) | |
| tree | 09d14cdf05456567156738b681379d4bccd64e5c /node_modules/then-request/test | |
| parent | 2020/04/03, 02:42, V1.2.1 (diff) | |
| download | s5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.tar.xz s5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.zip | |
2020/04/03, 02:47, V1.2.2
Diffstat (limited to 'node_modules/then-request/test')
| -rw-r--r-- | node_modules/then-request/test/browser.js | 53 | ||||
| -rw-r--r-- | node_modules/then-request/test/get-mock-response.js | 20 | ||||
| -rw-r--r-- | node_modules/then-request/test/index.js | 97 | ||||
| -rw-r--r-- | node_modules/then-request/test/server.js | 25 |
4 files changed, 0 insertions, 195 deletions
diff --git a/node_modules/then-request/test/browser.js b/node_modules/then-request/test/browser.js deleted file mode 100644 index cd586c2..0000000 --- a/node_modules/then-request/test/browser.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var assert = require('assert'); -var getResponse = require('./get-mock-response.js'); -var window = (global.window = {}); - -window.XMLHttpRequest = XMLHttpRequest; -function XMLHttpRequest() { - assert(arguments.length === 0); - this._headers = {}; - this._responseHeaders = ''; -}; -// XMLHttpRequest.prototype.onreadystatechange gets assigned by user -XMLHttpRequest.prototype.open = function (method, url, async) { - assert(async === true, 'All requests must be async'); - this._method = method; - this._url = url; -}; -XMLHttpRequest.prototype.setRequestHeader = function (name, value) { - this._headers[name] = value; -}; -XMLHttpRequest.prototype.send = function (body) { - assert(typeof body === 'string' || body === null, 'body must be a string or null'); - this.readyState = 3; - this.onreadystatechange(); - this.readyState = 4; - var res = getResponse(this._method, this._url, this._headers, body, {isClient: true}); - this.status = res.statusCode; - this._responseHeaders = Object.keys(res.headers).map(function (header) { - return header + ': ' + res.headers[header]; - }).join('\r\n'); - this.responseText = res.body; - this.onreadystatechange(); -}; -XMLHttpRequest.prototype.getAllResponseHeaders = function () { - return this._responseHeaders; -} -window.location = {}; -window.location.host = 'http://example.com'; - - -/* -if (xhr.readyState === 4) { - var headers = {}; - xhr.getAllResponseHeaders().split('\r\n').forEach(function (header) { - var h = header.split(':'); - if (h.length > 1) { - headers[h[0].toLowerCase()] = h.slice(1).join(':').trim(); - } - }); - resolve(new Response(xhr.status, headers, xhr.responseText)); -} -*/ diff --git a/node_modules/then-request/test/get-mock-response.js b/node_modules/then-request/test/get-mock-response.js deleted file mode 100644 index cb58c4d..0000000 --- a/node_modules/then-request/test/get-mock-response.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -var assert = require('assert'); -var Response = require('http-response-object'); - -module.exports = getResponse; -function getResponse(method, url, headers, body, options) { - var isClient = options.isClient; - if (method === 'GET' && url === 'http://example.com') { - return new Response(200, {FoO: 'bar'}, 'body'); - } - if (method === 'GET' && url === 'http://example.com?foo=baz') { - return new Response(200, {FoO: 'baz'}, 'body'); - } - if (method === 'POST' && url === 'http://example.com') { - assert(headers['Content-Type'] === 'application/json'); - assert(JSON.parse(body.toString()).foo === 'baz'); - return new Response(200, {}, 'json body'); - } -} diff --git a/node_modules/then-request/test/index.js b/node_modules/then-request/test/index.js deleted file mode 100644 index 019a2f8..0000000 --- a/node_modules/then-request/test/index.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - -var assert = require('assert'); -var test = require('testit'); -var Promise = require('promise'); - -test('./lib/handle-qs.js', function () { - var handleQs = require('../lib/handle-qs.js'); - - assert(handleQs('http://example.com/', {}) === 'http://example.com/'); - assert(handleQs('http://example.com/?foo=bar', {}) === 'http://example.com/?foo=bar'); - assert(handleQs('http://example.com/', {foo: 'bar'}) === 'http://example.com/?foo=bar'); - assert(handleQs('http://example.com/', {foo: {bar: 'baz'}}) === 'http://example.com/?foo%5Bbar%5D=baz'); - assert(handleQs('http://example.com/', {foo: 'bar', bing: 'bong'}) === 'http://example.com/?foo=bar&bing=bong'); - assert(handleQs('http://example.com/?foo=bar', {bing: 'bong'}) === 'http://example.com/?foo=bar&bing=bong'); - assert(handleQs('http://example.com/?foo=bar#ding', {bing: 'bong'}) === 'http://example.com/?foo=bar&bing=bong#ding'); -}); - - -require('./browser.js'); -require('./server.js'); - -function testEnv(env) { - var request = require(env === 'browser' ? '../browser.js' : '../index.js'); - test(env + ' - GET', function () { - return request('GET', 'http://example.com').then(function (res) { - assert(res.statusCode === 200); - assert(res.headers['foo'] === 'bar'); - assert(res.body.toString() === 'body'); - }); - }); - test(env + ' - GET query', function () { - return request('GET', 'http://example.com', {qs: {foo: 'baz'}}).then(function (res) { - assert(res.statusCode === 200); - assert(res.headers['foo'] === 'baz'); - assert(res.body.toString() === 'body'); - }); - }); - test(env + ' - GET -> .getBody("utf8")', function () { - return request('GET', 'http://example.com').getBody('utf8').then(function (body) { - assert(body === 'body'); - }); - }); - test(env + ' - POST json', function () { - return request('POST', 'http://example.com', {json: {foo: 'baz'}}).then(function (res) { - assert(res.statusCode === 200); - assert(res.body.toString() === 'json body'); - }); - }); - - - test(env + ' - invalid method', function () { - return request({}, 'http://example.com').then(function (res) { - throw new Error('Expected an error'); - }, function (err) { - assert(err instanceof TypeError); - }); - }); - test(env + ' - invalid url', function () { - return request('GET', {}).then(function (res) { - throw new Error('Expected an error'); - }, function (err) { - assert(err instanceof TypeError); - }); - }); - test(env + ' - invalid options', function () { - return request('GET', 'http://example.com', 'options').then(function (res) { - throw new Error('Expected an error'); - }, function (err) { - assert(err instanceof TypeError); - }); - }); - test(env + ' - Callbacks', function () { - return new Promise(function (resolve, reject) { - return request('GET', 'http://example.com', function (err, res) { - if (err) return reject(err); - assert(res.statusCode === 200); - assert(res.headers['foo'] === 'bar'); - assert(res.body.toString() === 'body'); - resolve(null); - }); - }); - }); - test(env + ' - Callbacks', function () { - return new Promise(function (resolve, reject) { - return request('GET', 'http://example.com', {}, function (err, res) { - if (err) return reject(err); - assert(res.statusCode === 200); - assert(res.headers['foo'] === 'bar'); - assert(res.body.toString() === 'body'); - resolve(null); - }); - }); - }); -} -testEnv('browser'); -testEnv('server'); diff --git a/node_modules/then-request/test/server.js b/node_modules/then-request/test/server.js deleted file mode 100644 index 614bb39..0000000 --- a/node_modules/then-request/test/server.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -var assert = require('assert'); -var PassThrough = require('stream').PassThrough; -var getResponse = require('./get-mock-response.js'); - -require('../index.js')._request = function (method, url, options, callback) { - assert(typeof callback === 'function'); - var duplex = !(method === 'GET' || method === 'DELETE' || method === 'HEAD'); - if (duplex) { - return { - end: function (body) { - gotResponse(getResponse(method, url, options.headers, body, {isClient: false})); - } - }; - } else { - gotResponse(getResponse(method, url, options.headers, null, {isClient: false})); - } - function gotResponse(res) { - var stream = new PassThrough(); - stream.end(res.body); - res.body = stream; - callback(null, res); - } -}; |