Gathering detailed insights and metrics for supertest-fetch
Gathering detailed insights and metrics for supertest-fetch
Gathering detailed insights and metrics for supertest-fetch
Gathering detailed insights and metrics for supertest-fetch
npm install supertest-fetch
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (98.29%)
JavaScript (1.71%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
41 Stars
200 Commits
8 Forks
2 Watchers
9 Branches
9 Contributors
Updated on Mar 02, 2025
Latest Version
2.0.0
Package Id
supertest-fetch@2.0.0
Unpacked Size
41.69 kB
Size
10.78 kB
File Count
14
NPM Version
10.8.1
Node Version
20.15.0
Published on
Jun 27, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A typescript friendly alternative to Supertest. Backed by native node fetch implementation so it requires node 18+ version.
This is a library heavily influenced by Visionmedia's excellent supertest library, but with a WHATWG Fetch-like interface. The advantages of this library are:
1import http from 'http'; 2import { makeFetch } from 'supertest-fetch'; 3 4const server = http.createServer((req, res) => { 5 res.setHeader('content-type', 'application/json'); 6 res.end(JSON.stringify({ greeting: 'Hello!' })); 7}); 8 9// This is a function with an API identical to the WHATWG `fetch()` function, 10// except the returned Promise has a bunch of supertest like functions on it. 11// 12// If the server is not listening, then `fetch()` will call `listen()` on the 13// server before each fetch, and close it after each fetch. 14const fetch = makeFetch(server); 15 16describe('my server tests', function () { 17 it('should return a response', async function () { 18 await fetch('/hello') 19 .expect(200) 20 .expect('content-type', 'application/json') 21 .expect({ greeting: 'Hello!' }); 22 }); 23 24 it('will work just like fetch if you need to do more advanced things', async function () { 25 const response = await fetch('/hello') 26 .expect(200) 27 .expect('content-type', 'application/json'); 28 29 expect(await response.json()).to.eql({ greeting: 'Hello!' }); 30 }); 31 32 it('should post data', async function () { 33 await fetch('/hello', { 34 method: 'post', 35 body: '<message>Hello</message>', 36 headers: { 'content-type': 'application/xml' }, 37 }); 38 }); 39});
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 request. 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 for details.
Verify response status code and text.
Verify headerName matches the given value or regex. If value
is null,
verifies that the header is not present.
Verify body is the given string, JSON object, or matches the given regular expression.
Supertest friendly alias for .expectStatus(statusCode)
.
Supertest friendly alias for .expectStatus(statusCode).expectBody(body)
.
Supertest friendly alias for .expectBody(body)
.
Supertest friendly alias for .expectHeader(field, value)
.
Convenience function which returns a Promise which resolves to the JSON content of the response. This:
1const result = await fetch('/hello').expect(200).json();
is equivalent to:
1const response = await fetch('/hello').expect(200); 2const result = await response.json();
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 3/7 approved changesets -- score normalized to 4
Reason
0 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More