[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-3351":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":27,"readmeContent":28,"aiSummary":29,"trendingCount":16,"starSnapshotCount":16,"syncStatus":17,"lastSyncTime":30,"discoverSource":31},3351,"supertest","forwardemail\u002Fsupertest","forwardemail","🕷 Super-agent driven library for testing node.js HTTP servers using a fluent API.   Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.","",null,"JavaScript",14365,783,107,168,0,2,16,71.28,"MIT License",false,"master",[24,25,26,5],"assertions","node","superagent","2026-06-12 04:00:17","# [supertest](https:\u002F\u002Fforwardemail.github.io\u002Fsuperagent\u002F)\n\n[![build status](https:\u002F\u002Fgithub.com\u002Fforwardemail\u002Fsupertest\u002Factions\u002Fworkflows\u002Fci.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fforwardemail\u002Fsupertest\u002Factions\u002Fworkflows\u002Fci.yml)\n[![code coverage](https:\u002F\u002Fimg.shields.io\u002Fcodecov\u002Fc\u002Fgithub\u002Fladjs\u002Fsupertest.svg)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fladjs\u002Fsupertest)\n[![code style](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fcode_style-XO-5ed9c7.svg)](https:\u002F\u002Fgithub.com\u002Fsindresorhus\u002Fxo)\n[![styled with prettier](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fstyled_with-prettier-ff69b4.svg)](https:\u002F\u002Fgithub.com\u002Fprettier\u002Fprettier)\n[![made with lass](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fmade_with-lass-95CC28.svg)](https:\u002F\u002Flass.js.org)\n[![license](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flicense\u002Fladjs\u002Fsupertest.svg)](LICENSE)\n\n> HTTP assertions made easy via [superagent](http:\u002F\u002Fgithub.com\u002Fladjs\u002Fsuperagent).  Maintained for [Forward Email](https:\u002F\u002Fgithub.com\u002Fforwardemail) and [Lad](https:\u002F\u002Fgithub.com\u002Fladjs).\n\n## About\n\nThe motivation with this module is to provide a high-level abstraction for testing\nHTTP, while still allowing you to drop down to the [lower-level API](https:\u002F\u002Fforwardemail.github.io\u002Fsuperagent\u002F) provided by superagent.\n\n## Getting Started\n\nInstall supertest as an npm module and save it to your package.json file as a development dependency:\n\n```bash\nnpm install supertest --save-dev\n```\n\n  Once installed it can now be referenced by simply calling ```require('supertest');```\n\n## Example\n\nYou may pass an `http.Server`, or a `Function` to `request()` - if the server is not\nalready listening for connections then it is bound to an ephemeral port for you so\nthere is no need to keep track of ports.\n\nsupertest works with any test framework, here is an example without using any\ntest framework at all:\n\n```js\nconst request = require('supertest');\nconst express = require('express');\n\nconst app = express();\n\napp.get('\u002Fuser', function(req, res) {\n  res.status(200).json({ name: 'john' });\n});\n\nrequest(app)\n  .get('\u002Fuser')\n  .expect('Content-Type', \u002Fjson\u002F)\n  .expect('Content-Length', '15')\n  .expect(200)\n  .end(function(err, res) {\n    if (err) throw err;\n  });\n```\n\nTo enable http2 protocol, simply append an options to `request` or `request.agent`:\n\n```js\nconst request = require('supertest');\nconst express = require('express');\n\nconst app = express();\n\napp.get('\u002Fuser', function(req, res) {\n  res.status(200).json({ name: 'john' });\n});\n\nrequest(app, { http2: true })\n  .get('\u002Fuser')\n  .expect('Content-Type', \u002Fjson\u002F)\n  .expect('Content-Length', '15')\n  .expect(200)\n  .end(function(err, res) {\n    if (err) throw err;\n  });\n\nrequest.agent(app, { http2: true })\n  .get('\u002Fuser')\n  .expect('Content-Type', \u002Fjson\u002F)\n  .expect('Content-Length', '15')\n  .expect(200)\n  .end(function(err, res) {\n    if (err) throw err;\n  });\n```\n\nHere's an example with mocha, note how you can pass `done` straight to any of the `.expect()` calls:\n\n```js\ndescribe('GET \u002Fuser', function() {\n  it('responds with json', function(done) {\n    request(app)\n      .get('\u002Fuser')\n      .set('Accept', 'application\u002Fjson')\n      .expect('Content-Type', \u002Fjson\u002F)\n      .expect(200, done);\n  });\n});\n```\n\nYou can use `auth` method to pass HTTP username and password in the same way as in the [superagent](https:\u002F\u002Fforwardemail.github.io\u002Fsuperagent\u002F#authentication):\n\n```js\ndescribe('GET \u002Fuser', function() {\n  it('responds with json', function(done) {\n    request(app)\n      .get('\u002Fuser')\n      .auth('username', 'password')\n      .set('Accept', 'application\u002Fjson')\n      .expect('Content-Type', \u002Fjson\u002F)\n      .expect(200, done);\n  });\n});\n```\n\nOne thing to note with the above statement is that superagent now sends any HTTP\nerror (anything other than a 2XX response code) to the callback as the first argument if\nyou do not add a status code expect (i.e. `.expect(302)`).\n\nIf you are using the `.end()` method `.expect()` assertions that fail will\nnot throw - they will return the assertion as an error to the `.end()` callback. In\norder to fail the test case, you will need to rethrow or pass `err` to `done()`, as follows:\n\n```js\ndescribe('POST \u002Fusers', function() {\n  it('responds with json', function(done) {\n    request(app)\n      .post('\u002Fusers')\n      .send({name: 'john'})\n      .set('Accept', 'application\u002Fjson')\n      .expect('Content-Type', \u002Fjson\u002F)\n      .expect(200)\n      .end(function(err, res) {\n        if (err) return done(err);\n        return done();\n      });\n  });\n});\n```\n\nYou can also use promises:\n\n```js\ndescribe('GET \u002Fusers', function() {\n  it('responds with json', function() {\n    return request(app)\n      .get('\u002Fusers')\n      .set('Accept', 'application\u002Fjson')\n      .expect('Content-Type', \u002Fjson\u002F)\n      .expect(200)\n      .then(response => {\n         expect(response.body.email).toEqual('foo@bar.com');\n      })\n  });\n});\n```\n\nOr async\u002Fawait syntax:\n\n```js\ndescribe('GET \u002Fusers', function() {\n  it('responds with json', async function() {\n    const response = await request(app)\n      .get('\u002Fusers')\n      .set('Accept', 'application\u002Fjson')\n    expect(response.headers[\"content-type\"]).toMatch(\u002Fjson\u002F);\n    expect(response.status).toEqual(200);\n    expect(response.body.email).toEqual('foo@bar.com');\n  });\n});\n```\n\nExpectations are run in the order of definition. This characteristic can be used\nto modify the response body or headers before executing an assertion.\n\n```js\ndescribe('POST \u002Fuser', function() {\n  it('user.name should be an case-insensitive match for \"john\"', function(done) {\n    request(app)\n      .post('\u002Fuser')\n      .send('name=john') \u002F\u002F x-www-form-urlencoded upload\n      .set('Accept', 'application\u002Fjson')\n      .expect(function(res) {\n        res.body.id = 'some fixed id';\n        res.body.name = res.body.name.toLowerCase();\n      })\n      .expect(200, {\n        id: 'some fixed id',\n        name: 'john'\n      }, done);\n  });\n});\n```\n\nAnything you can do with superagent, you can do with supertest - for example multipart file uploads!\n\n```js\nrequest(app)\n  .post('\u002F')\n  .field('name', 'my awesome avatar')\n  .field('complex_object', '{\"attribute\": \"value\"}', {contentType: 'application\u002Fjson'})\n  .attach('avatar', 'test\u002Ffixtures\u002Favatar.jpg')\n  ...\n```\n\nPassing the app or url each time is not necessary, if you're testing\nthe same host you may simply re-assign the request variable with the\ninitialization app or url, a new `Test` is created per `request.VERB()` call.\n\n```js\nrequest = request('http:\u002F\u002Flocalhost:5555');\n\nrequest.get('\u002F').expect(200, function(err){\n  console.log(err);\n});\n\nrequest.get('\u002F').expect('heya', function(err){\n  console.log(err);\n});\n```\n\nHere's an example with mocha that shows how to persist a request and its cookies:\n\n```js\nconst request = require('supertest');\nconst should = require('should');\nconst express = require('express');\nconst cookieParser = require('cookie-parser');\n\ndescribe('request.agent(app)', function() {\n  const app = express();\n  app.use(cookieParser());\n\n  app.get('\u002F', function(req, res) {\n    res.cookie('cookie', 'hey');\n    res.send();\n  });\n\n  app.get('\u002Freturn', function(req, res) {\n    if (req.cookies.cookie) res.send(req.cookies.cookie);\n    else res.send(':(')\n  });\n\n  const agent = request.agent(app);\n\n  it('should save cookies', function(done) {\n    agent\n    .get('\u002F')\n    .expect('set-cookie', 'cookie=hey; Path=\u002F', done);\n  });\n\n  it('should send cookies', function(done) {\n    agent\n    .get('\u002Freturn')\n    .expect('hey', done);\n  });\n});\n```\n\nThere is another example that is introduced by the file [agency.js](https:\u002F\u002Fgithub.com\u002Fladjs\u002Fsuperagent\u002Fblob\u002Fmaster\u002Ftest\u002Fnode\u002Fagency.js)\n\nHere is an example where 2 cookies are set on the request.\n\n```js\nagent(app)\n  .get('\u002Fapi\u002Fcontent')\n  .set('Cookie', ['nameOne=valueOne;nameTwo=valueTwo'])\n  .send()\n  .expect(200)\n  .end((err, res) => {\n    if (err) {\n      return done(err);\n    }\n    expect(res.text).to.be.equal('hey');\n    return done();\n  });\n```\n\n## API\n\nYou may use any [superagent](http:\u002F\u002Fgithub.com\u002Fladjs\u002Fsuperagent) methods,\nincluding `.write()`, `.pipe()` etc and perform assertions in the `.end()` callback\nfor lower-level needs.\n\n### .expect(status[, fn])\n\nAssert response `status` code.\n\n### .expect(status, body[, fn])\n\nAssert response `status` code and `body`.\n\n### .expect(body[, fn])\n\nAssert response `body` text with a string, regular expression, or\nparsed body object.\n\n### .expect(field, value[, fn])\n\nAssert header `field` `value` with a string or regular expression.\n\n### .expect(function(res) {})\n\nPass a custom assertion function. It'll be given the response object to check. If the check fails, throw an error.\n\n```js\nrequest(app)\n  .get('\u002F')\n  .expect(hasPreviousAndNextKeys)\n  .end(done);\n\nfunction hasPreviousAndNextKeys(res) {\n  if (!('next' in res.body)) throw new Error(\"missing next key\");\n  if (!('prev' in res.body)) throw new Error(\"missing prev key\");\n}\n```\n\n### .end(fn)\n\nPerform the request and invoke `fn(err, res)`.\n\n## Cookies\n\nHere is an example of using the `set` and `not` cookie assertions:\n\n```js\n\u002F\u002F setup super-test\nconst request = require('supertest');\nconst express = require('express');\nconst cookies = request.cookies;\n\n\u002F\u002F setup express test service\nconst app = express();\n\napp.get('\u002Fusers', function(req, res) {\n  res.cookie('alpha', 'one', { domain: 'domain.com', path: '\u002F', httpOnly: true });\n  res.send(200, { name: 'tobi' });\n});\n\n\u002F\u002F test request to service\nrequest(app)\n  .get('\u002Fusers')\n  .expect('Content-Type', \u002Fjson\u002F)\n  .expect('Content-Length', '15')\n  .expect(200)\n  \u002F\u002F assert 'alpha' cookie is set with domain, path, and httpOnly options\n  .expect(cookies.set({ name: 'alpha', options: ['domain', 'path', 'httponly'] }))\n  \u002F\u002F assert 'bravo' cookie is NOT set\n  .expect(cookies.not('set', { name: 'bravo' }))\n  .end(function(err, res) {\n    if (err) {\n      throw err;\n    }\n  });\n```\n\nIt is also possible to chain assertions:\n\n```js\ncookies.set({\u002F* ... *\u002F}).not('set', {\u002F* ... *\u002F})\n```\n\n### Cookie assertions\n\nFunctions and methods are chainable.\n\n#### cookies([secret], [asserts])\n\nGet assertion function for [super-test](https:\u002F\u002Fgithub.com\u002Fvisionmedia\u002Fsupertest) `.expect()` method.\n\n*Arguments*\n\n- `secret` - String or array of strings. Cookie signature secrets.\n- `asserts(req, res)` - Function or array of functions. Failed custom assertions should throw.\n\n#### .set(expects, [assert])\n\nAssert that cookie and options are set.\n\n*Arguments*\n\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n  - `options` - *Optional* array of options.\n- `assert` - *Optional* boolean \"assert true\" modifier. Default: `true`.\n\n#### .reset(expects, [assert])\n\nAssert that cookie is set and was already set (in request headers).\n\n*Arguments*\n\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n- `assert` - *Optional* boolean \"assert true\" modifier. Default: `true`.\n\n#### .new(expects, [assert])\n\nAssert that cookie is set and was NOT already set (NOT in request headers).\n\n*Arguments*\n\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n- `assert` - *Optional* boolean \"assert true\" modifier. Default: `true`.\n\n#### .renew(expects, [assert])\n\nAssert that cookie is set with a strictly greater `expires` or `max-age` than the given value.\n\n*Arguments*\n\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n  - `options` - Object of options. `use one of two options below`\n  - `options`.`expires` - String UTC expiration for original cookie (in request headers).\n  - `options`.`max-age` - Integer ttl in seconds for original cookie (in request headers).\n- `assert` - *Optional* boolean \"assert true\" modifier. Default: `true`.\n\n#### .contain(expects, [assert])\n\nAssert that cookie is set with value and contains options.\n\nRequires `cookies(secret)` initialization if cookie is signed.\n\n*Arguments*\n\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n  - `value` - *Optional* string unsigned value of cookie.\n  - `options` - *Optional* object of options.\n  - `options`.`domain` - *Optional* string domain.\n  - `options`.`path` - *Optional* string path.\n  - `options`.`expires` - *Optional* string UTC expiration.\n  - `options`.`max-age` - *Optional* integer ttl, in seconds.\n  - `options`.`secure` - *Optional* boolean secure flag.\n  - `options`.`httponly` - *Optional* boolean httpOnly flag.\n- `assert` - *Optional* boolean \"assert true\" modifier. Default: `true`.\n\n#### .not(method, expects)\n\nCall any cookies assertion method with \"assert true\" modifier set to `false`.\n\nSyntactic sugar.\n\n*Arguments*\n\n- `method` - String method name. Arguments of method name apply in `expects`.\n- `expects` - Object or array of objects.\n  - `name` - String name of cookie.\n  - `value` - *Optional* string unsigned value of cookie.\n  - `options` - *Optional* object of options.\n\n## Notes\n\nInspired by [api-easy](https:\u002F\u002Fgithub.com\u002Fflatiron\u002Fapi-easy) minus vows coupling.\n\n## License\n\nMIT\n\n[coverage-badge]: https:\u002F\u002Fimg.shields.io\u002Fcodecov\u002Fc\u002Fgithub\u002Fladjs\u002Fsupertest.svg\n[coverage]: https:\u002F\u002Fcodecov.io\u002Fgh\u002Fladjs\u002Fsupertest\n[travis-badge]: https:\u002F\u002Ftravis-ci.org\u002Fladjs\u002Fsupertest.svg?branch=master\n[travis]: https:\u002F\u002Ftravis-ci.org\u002Fladjs\u002Fsupertest\n[dependencies-badge]: https:\u002F\u002Fdavid-dm.org\u002Fladjs\u002Fsupertest\u002Fstatus.svg\n[dependencies]: https:\u002F\u002Fdavid-dm.org\u002Fladjs\u002Fsupertest\n[prs-badge]: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPRs-welcome-brightgreen.svg?style=flat-square\n[prs]: http:\u002F\u002Fmakeapullrequest.com\n[license-badge]: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-blue.svg?style=flat-square\n[license]: https:\u002F\u002Fgithub.com\u002Fladjs\u002Fsupertest\u002Fblob\u002Fmaster\u002FLICENSE\n","supertest 是一个基于 superagent 的库，用于测试 Node.js HTTP 服务器，并提供流畅的 API 接口。它通过简洁的断言方式简化了 HTTP 请求的测试过程，支持多种协议包括 HTTP2，并且可以与任何测试框架配合使用。其核心功能在于能够自动处理端口绑定等底层细节，使得开发者可以专注于业务逻辑的测试。适用于需要对 RESTful API 或其他 HTTP 服务进行单元测试或集成测试的场景，尤其适合那些希望快速搭建起高效测试环境的 Node.js 项目。","2026-06-11 02:53:43","top_language"]