supertest-fetch
Advanced tools
Comparing version 1.4.3 to 1.5.0
@@ -26,3 +26,3 @@ "use strict"; | ||
* @returns - a Test, which is like a Promise<Response>, but it also | ||
* has 'exepect' methods on it. | ||
* has 'expect' methods on it. | ||
*/ | ||
@@ -53,3 +53,3 @@ function fetch(server, url, init) { | ||
var server = target && target.route | ||
? http_1.createServer(target) | ||
? (0, http_1.createServer)(target) | ||
: target; | ||
@@ -56,0 +56,0 @@ if (!server || !server.listen || !server.address || !server.close) { |
@@ -8,3 +8,5 @@ "use strict"; | ||
this._startedServer = started; | ||
this.url = "http://localhost:" + address.port; | ||
// Check if server is an instance of tls.Server. | ||
var https = 'getTicketKeys' in server; | ||
this.url = (https ? 'https' : 'http') + "://localhost:" + address.port; | ||
} | ||
@@ -11,0 +13,0 @@ Server.create = function (server) { |
{ | ||
"name": "supertest-fetch", | ||
"version": "1.4.3", | ||
"version": "1.5.0", | ||
"description": "Supertest with WHATWG fetch like interface.", | ||
@@ -21,12 +21,6 @@ "main": "lib/index.js", | ||
"lint:tests": "tslint -c test/tslint.json -t stylish 'test/**/*.ts'", | ||
"prepare": "npm run build", | ||
"prepare": "husky install && npm run build", | ||
"prepublishOnly": "npm run build && npm test", | ||
"semantic-release": "semantic-release" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "validate-commit-msg", | ||
"pre-commit": "pretty-quick --staged && npm run precommit:test" | ||
} | ||
}, | ||
"lint-staged": { | ||
@@ -59,4 +53,5 @@ "src/**/*.ts": [ | ||
"@types/chai-as-promised": "^7.1.0", | ||
"@types/mocha": "^8.0.0", | ||
"@types/node": "^14.0.6", | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "^16.0.0", | ||
"@types/pem": "^1.9.6", | ||
"chai": "^4.2.0", | ||
@@ -66,13 +61,13 @@ "chai-as-promised": "^7.1.1", | ||
"express": "^4.16.4", | ||
"husky": "^4.0.0", | ||
"lint-staged": "^10.0.0", | ||
"mocha": "^8.1.1", | ||
"husky": "^7.0.0", | ||
"lint-staged": "^11.0.0", | ||
"mocha": "^9.1.1", | ||
"nyc": "^15.0.0", | ||
"pem": "^1.14.4", | ||
"prettier": "^2.0.1", | ||
"pretty-quick": "^3.0.0", | ||
"semantic-release": "^17.0.0", | ||
"ts-node": "^9.0.0", | ||
"semantic-release": "^18.0.0", | ||
"ts-node": "^10.0.0", | ||
"tslint": "^6.0.0", | ||
"typescript": "^4.0.2", | ||
"validate-commit-msg": "^2.14.0" | ||
"typescript": "^4.0.2" | ||
}, | ||
@@ -79,0 +74,0 @@ "dependencies": { |
# supertest-fetch | ||
[![NPM version](https://badge.fury.io/js/supertest-fetch.svg)](https://npmjs.org/package/supertest-fetch) | ||
[![Build Status](https://travis-ci.org/jwalton/node-supertest-fetch.svg)](https://travis-ci.org/jwalton/node-supertest-fetch) | ||
![Build Status](https://github.com/jwalton/node-supertest-fetch/workflows/GitHub%20CI/badge.svg) | ||
[![Coverage Status](https://coveralls.io/repos/jwalton/node-supertest-fetch/badge.svg)](https://coveralls.io/r/jwalton/node-supertest-fetch) | ||
@@ -41,4 +41,4 @@ [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) | ||
describe('my server tests', function() { | ||
it('should return a response', async function() { | ||
describe('my server tests', function () { | ||
it('should return a response', async function () { | ||
await fetch('/hello') | ||
@@ -50,3 +50,3 @@ .expect(200) | ||
it('will work just like fetch if you need to do more advanced things', async function() { | ||
it('will work just like fetch if you need to do more advanced things', async function () { | ||
const response = await fetch('/hello') | ||
@@ -59,3 +59,3 @@ .expect(200) | ||
it('should post data', async function() { | ||
it('should post data', async function () { | ||
await fetch('/hello', { | ||
@@ -72,2 +72,10 @@ method: 'post', | ||
### makeFetch(server) | ||
Returns a new `fetch` function. This is identical to the WHAT-WG fetch function, except that the returned object has some extra assertions added to it. | ||
If the `server` passed in is not already listening, each call to `fetch()` will call `listen()` on the server, and close it after each fetch. This will assign a random free port to the server, so you don't need to worry about listening on a well-known port for your tests to work. | ||
If the `server` passed in is an instance of tls.Server, then the returned `fetch` instance will use HTTPS to connect to the server instead of HTTP. Note that it's up to you to appropriately configure the server, supplying a certificate and key, and if you're using a self-signed certificate you'll need to pass an "agent" to the call to `fetch`. See [this example](https://github.com/jwalton/node-supertest-fetch/blob/master/test/https.ts) for details. | ||
### .expectStatus(statusCode[, statusText]) | ||
@@ -108,5 +116,3 @@ | ||
```js | ||
const result = await fetch('/hello') | ||
.expect(200) | ||
.json(); | ||
const result = await fetch('/hello').expect(200).json(); | ||
``` | ||
@@ -113,0 +119,0 @@ |
@@ -6,3 +6,3 @@ /// <reference types="node" /> | ||
import Test from './Test'; | ||
export { Body, BodyInit, HeadersInit, HeadersInit as HeaderInit, Headers, Request, RequestCache, RequestContext, RequestCredentials, RequestInfo, RequestInit, RequestMode, RequestRedirect, Response, ResponseInit, ResponseType, } from 'node-fetch'; | ||
export { Body, BodyInit, Headers, HeadersInit as HeaderInit, HeadersInit, Request, RequestCache, RequestContext, RequestCredentials, RequestInfo, RequestInit, RequestMode, RequestRedirect, Response, ResponseInit, ResponseType, } from 'node-fetch'; | ||
export { Test }; | ||
@@ -20,3 +20,3 @@ export { fetch }; | ||
* @returns - a Test, which is like a Promise<Response>, but it also | ||
* has 'exepect' methods on it. | ||
* has 'expect' methods on it. | ||
*/ | ||
@@ -23,0 +23,0 @@ export default function fetch(server: httpServer, url: string | nodeFetch.Request, init?: nodeFetch.RequestInit): Test; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53716
748
121
20