{"id":13657131,"url":"https://github.com/LvChengbin/koa-sham","last_synced_at":"2025-04-24T01:31:19.439Z","repository":{"id":32944755,"uuid":"147095469","full_name":"LvChengbin/koa-sham","owner":"LvChengbin","description":"To send fake requests to a Koa application without starting a http server.","archived":false,"fork":false,"pushed_at":"2023-01-03T18:40:15.000Z","size":3128,"stargazers_count":2,"open_issues_count":15,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-26T21:21:54.501Z","etag":null,"topics":["fake","http","koa","mock","request","sham","test"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LvChengbin.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}},"created_at":"2018-09-02T15:01:06.000Z","updated_at":"2019-08-07T10:05:18.000Z","dependencies_parsed_at":"2023-01-14T22:46:44.030Z","dependency_job_id":null,"html_url":"https://github.com/LvChengbin/koa-sham","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LvChengbin%2Fkoa-sham","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LvChengbin%2Fkoa-sham/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LvChengbin%2Fkoa-sham/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LvChengbin%2Fkoa-sham/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LvChengbin","download_url":"https://codeload.github.com/LvChengbin/koa-sham/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250543903,"owners_count":21447990,"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":["fake","http","koa","mock","request","sham","test"],"created_at":"2024-08-02T05:00:37.423Z","updated_at":"2025-04-24T01:31:14.672Z","avatar_url":"https://github.com/LvChengbin.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# koa-sham\n\nTo send fake request to a Koa application without starting a http server.\n\n**Sending `multipart` data will be supported later.**\n\n## Installation\n\n```js\n$ npm i koa-sham --save\n```\n\n## Usage\n\n```js\nconst Koa = require( 'koa' );\nconst sham = require( 'koa-sham' );\n\nconst app = new Koa();\n\napp.use( ctx =\u003e {\n    ctx.body = { status : 1 };\n} );\n\nsham( app, ( err, res, body ) =\u003e {\n    console.log( body ); // { status : 1 }\n} );\n\nsham( app, {\n    qs : {\n        x : 1\n    }\n}, ( err, res, body ) =\u003e {\n    console.log( body ); // { status : 1 }\n} );\n\nsham( app, '/path', { https: true }, ( err, res, body ) =\u003e {\n    console.log( body ); // { status : 1 }\n} );\n\nsham( app, { \n    method : 'POST',\n    body : {\n        x : 1\n    }\n}, ( err, res, body ) =\u003e {\n    console.log( body ); // { status : 1 }\n} );\n```\n\n### Promise\n\n```js\nsham( app, { promise : true } ).then( data =\u003e {\n    console.log( data );\n} );\n```\n\n### Streaming\n\n```js\nsham( app ).pipe( process.stdout );\n```\n\n### API\n\n#### sham( app, [ url, options, callback ] )\n\nReturns a `Readable Stream` by default, but can be changed by using `{ promise : true }` in `options`.\n\n**app**\n\nThe instance of `Koa` application. \n\n**url**\n\nType: `String`\n\nThe `URL` or `PATH` the you want to request. The host of the URL will be set as `127.0.0.1` by default. The protocol will be set to `http` if `options.https` is not `true`. The default port is `80` and it can be changed with `options.port`.\n\nIf the protocol of the URL is `https`, the request will be set to `secure`, even thought the `options.https` is not set to `true`.\n\n**options**\n\nType: `Object`\n\nOptions for the fake request.\n\n- **remoteAddress** `String`\n    The remote IP address, `127.0.0.1` by default.\n\n- **host** `String`\n    The host of URL, this item will be ignored if the passed `URL` contains it's host.\n\n- **port** `Number`\n    The port of URL, this item will be ignored if the passed `URL` contains it's host.\n\n- **https** `Boolean`\n    To set the request to `secure`, this item will be ignored if the passed `URL` contains it's protocol and is not 'https'.\n\n- **method** `String`\n    The request method\n\n- **qs** `Object`\n    The query string, should be an object.\n\n- **headers** `Object`\n    The headers of the request.\n\n- **cookies** `Object`\n    The cookies that will be set while sending request, it will overwrite the same cookie which is also in `headers`.\n\n- **body** `Object` `String`\n    The request body for `POST` or `PUT` request.\n\n- **promise** `Boolean`\n    If `promise` is true, the function will return a `Promise` object.\n\n- **resolveWithFullResponse `Boolean`\n    By setting this option to `true`, the returned `promise` will use the full response data as it's value.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLvChengbin%2Fkoa-sham","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLvChengbin%2Fkoa-sham","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLvChengbin%2Fkoa-sham/lists"}