Gathering detailed insights and metrics for supertest-session
Gathering detailed insights and metrics for supertest-session
Gathering detailed insights and metrics for supertest-session
Gathering detailed insights and metrics for supertest-session
npm install supertest-session
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
6,123,079
Last Day
855
Last Week
25,383
Last Month
103,397
Last Year
1,113,363
NOASSERTION License
88 Stars
124 Commits
21 Forks
6 Watchers
10 Branches
9 Contributors
Updated on Jul 01, 2025
Minified
Minified + Gzipped
Latest Version
5.0.1
Package Id
supertest-session@5.0.1
Unpacked Size
13.37 kB
Size
5.01 kB
File Count
12
NPM Version
9.7.2
Node Version
20.4.0
Published on
Aug 01, 2023
Cumulative downloads
Total Downloads
Last Day
-44.8%
855
Compared to previous day
Last Week
-4.6%
25,383
Compared to previous week
Last Month
-5.4%
103,397
Compared to previous month
Last Year
-0.5%
1,113,363
Compared to previous year
Session wrapper around supertest.
References:
$ npm install --save-dev supertest supertest-session
$ npm test
Require supertest-session
and pass in the test application:
1var session = require('supertest-session'); 2var myApp = require('../../path/to/app'); 3 4var testSession = null; 5 6beforeEach(function () { 7 testSession = session(myApp); 8});
And set some expectations:
1it('should fail accessing a restricted page', function (done) { 2 testSession.get('/restricted') 3 .expect(401) 4 .end(done) 5}); 6 7it('should sign in', function (done) { 8 testSession.post('/signin') 9 .send({ username: 'foo', password: 'password' }) 10 .expect(200) 11 .end(done); 12});
You can set preconditions:
1describe('after authenticating session', function () { 2 3 var authenticatedSession; 4 5 beforeEach(function (done) { 6 testSession.post('/signin') 7 .send({ username: 'foo', password: 'password' }) 8 .expect(200) 9 .end(function (err) { 10 if (err) return done(err); 11 authenticatedSession = testSession; 12 return done(); 13 }); 14 }); 15 16 it('should get a restricted page', function (done) { 17 authenticatedSession.get('/restricted') 18 .expect(200) 19 .end(done) 20 }); 21 22}); 23
The cookies attached to the session may be retrieved from session.cookies
:
1var sessionCookie = testSession.cookies.find(function (cookie) { 2 return cookie.name === connect.sid; 3});
If you're using
By default, supertest-session authenticates using session cookies. If your app
uses a custom strategy to restore sessions, you can provide before
and after
hooks to adjust the request and inspect the response:
1var testSession = session(myApp, { 2 before: function (req) { 3 req.set('authorization', 'Basic aGVsbG86d29ybGQK'); 4 } 5});
By default supertest-session will derive the CookieAccessInfo config of the cookie jar from the agent configuration. There might be cases where you want to override this, e.g. if you're testing a service which is configured to run behind a proxy but which sets secure cookies. To have supertest-session expose these secure cookies you can provide an override config to the internal call to CookieAccessInfo:
1var cookieAccess = { 2 domain: 'example.com', 3 path: '/testpath', 4 secure: true, 5 script: true, 6}; 7var testSession = session(myApp, { cookieAccess: cookieAccess });
By default the underlying supertest
agent will still determine the CookieAccessInfo from the URL.
If you want supertest-session to instead send cookies according to this cookieAccess
config you
can make use of the before
hook:
1var cookieAccess = { 2 domain: 'example.com', 3 path: '/testpath', 4 secure: true, 5 script: true, 6}; 7var testSession = session(myApp, { 8 cookieAccess: cookieAccess, 9 before: function (req) { 10 req.cookies = this.cookies.toValueString(); 11 }, 12});
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/16 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
15 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
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