{"id":15622813,"url":"https://github.com/rjz/supertest-session","last_synced_at":"2025-04-05T19:13:15.605Z","repository":{"id":526820,"uuid":"14074383","full_name":"rjz/supertest-session","owner":"rjz","description":"Persistent sessions for supertest","archived":false,"fork":false,"pushed_at":"2023-08-01T20:35:22.000Z","size":453,"stargazers_count":87,"open_issues_count":13,"forks_count":21,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-05-20T08:03:55.530Z","etag":null,"topics":["javascript","supertest","supertest-session"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rjz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-11-02T20:24:50.000Z","updated_at":"2024-06-18T13:37:46.848Z","dependencies_parsed_at":"2024-06-18T13:37:38.140Z","dependency_job_id":"ff45f488-25c8-4611-85a9-b778caa1367c","html_url":"https://github.com/rjz/supertest-session","commit_stats":{"total_commits":101,"total_committers":12,"mean_commits":8.416666666666666,"dds":"0.37623762376237624","last_synced_commit":"faa71f69159038b2d9df7bb3182ecc9fffa6a98b"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjz%2Fsupertest-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjz%2Fsupertest-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjz%2Fsupertest-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjz%2Fsupertest-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rjz","download_url":"https://codeload.github.com/rjz/supertest-session/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386265,"owners_count":20930619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","supertest","supertest-session"],"created_at":"2024-10-03T09:55:19.219Z","updated_at":"2025-04-05T19:13:15.579Z","avatar_url":"https://github.com/rjz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Supertest sessions\n\nSession wrapper around supertest.\n\n[![Coverage\nStatus](https://coveralls.io/repos/rjz/supertest-session/badge.png)](https://coveralls.io/r/rjz/supertest-session)\n\nReferences:\n\n  * https://gist.github.com/joaoneto/5152248\n  * https://github.com/visionmedia/supertest/issues/46\n  * https://github.com/visionmedia/supertest/issues/26\n\n## Installation\n\n    $ npm install --save-dev supertest supertest-session\n\n## Test\n\n    $ npm test\n\n## Usage\n\nRequire `supertest-session` and pass in the test application:\n\n```js\nvar session = require('supertest-session');\nvar myApp = require('../../path/to/app');\n\nvar testSession = null;\n\nbeforeEach(function () {\n  testSession = session(myApp);\n});\n```\n\nAnd set some expectations:\n\n```js\nit('should fail accessing a restricted page', function (done) {\n  testSession.get('/restricted')\n    .expect(401)\n    .end(done)\n});\n\nit('should sign in', function (done) {\n  testSession.post('/signin')\n    .send({ username: 'foo', password: 'password' })\n    .expect(200)\n    .end(done);\n});\n```\n\nYou can set preconditions:\n\n```js\ndescribe('after authenticating session', function () {\n\n  var authenticatedSession;\n\n  beforeEach(function (done) {\n    testSession.post('/signin')\n      .send({ username: 'foo', password: 'password' })\n      .expect(200)\n      .end(function (err) {\n        if (err) return done(err);\n        authenticatedSession = testSession;\n        return done();\n      });\n  });\n\n  it('should get a restricted page', function (done) {\n    authenticatedSession.get('/restricted')\n      .expect(200)\n      .end(done)\n  });\n\n});\n\n```\n\n### Accessing cookies\n\nThe cookies attached to the session may be retrieved from `session.cookies`:\n\n```js\nvar sessionCookie = testSession.cookies.find(function (cookie) {\n  return cookie.name === connect.sid;\n});\n```\n\nIf you're using\n\n### Request hooks\n\nBy default, supertest-session authenticates using session cookies. If your app\nuses a custom strategy to restore sessions, you can provide `before` and `after`\nhooks to adjust the request and inspect the response:\n\n```js\nvar testSession = session(myApp, {\n  before: function (req) {\n    req.set('authorization', 'Basic aGVsbG86d29ybGQK');\n  }\n});\n```\n\n### Cookie Jar Access Options\n\nBy default supertest-session will derive the CookieAccessInfo config of the cookie jar from the\nagent configuration. There might be cases where you want to override this, e.g. if you're testing\na service which is configured to run behind a proxy but which [sets secure\ncookies](https://expressjs.com/en/api.html#req.secure). To have supertest-session expose these\nsecure cookies you can provide an override config to the internal call to\n[CookieAccessInfo](https://github.com/bmeck/node-cookiejar#cookieaccessinfodomainpathsecurescript):\n\n```js\nvar cookieAccess = {\n  domain: 'example.com',\n  path: '/testpath',\n  secure: true,\n  script: true,\n};\nvar testSession = session(myApp, { cookieAccess: cookieAccess });\n```\n\nBy default the underlying `supertest` agent will still determine the CookieAccessInfo from the URL.\nIf you want supertest-session to instead send cookies according to this `cookieAccess` config you\ncan make use of the `before` hook:\n\n```js\nvar cookieAccess = {\n  domain: 'example.com',\n  path: '/testpath',\n  secure: true,\n  script: true,\n};\nvar testSession = session(myApp, {\n  cookieAccess: cookieAccess,\n  before: function (req) {\n    req.cookies = this.cookies.toValueString();\n  },\n});\n```\n\n## License\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjz%2Fsupertest-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frjz%2Fsupertest-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjz%2Fsupertest-session/lists"}