{"id":19474928,"url":"https://github.com/heiseonline/request-promise-native-record","last_synced_at":"2025-04-25T12:32:10.027Z","repository":{"id":26913961,"uuid":"111706527","full_name":"heiseonline/request-promise-native-record","owner":"heiseonline","description":"Records and plays back responses from remote web services so you can test your code in peace.","archived":false,"fork":false,"pushed_at":"2022-05-29T06:21:32.000Z","size":179,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":11,"default_branch":"develop","last_synced_at":"2025-04-20T02:18:23.831Z","etag":null,"topics":["javascript","mocha","recorder","request-promise-native","testing"],"latest_commit_sha":null,"homepage":"","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/heiseonline.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-22T16:16:03.000Z","updated_at":"2020-03-20T15:13:07.000Z","dependencies_parsed_at":"2022-09-20T06:50:44.273Z","dependency_job_id":null,"html_url":"https://github.com/heiseonline/request-promise-native-record","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiseonline%2Frequest-promise-native-record","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiseonline%2Frequest-promise-native-record/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiseonline%2Frequest-promise-native-record/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiseonline%2Frequest-promise-native-record/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heiseonline","download_url":"https://codeload.github.com/heiseonline/request-promise-native-record/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250817882,"owners_count":21492245,"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","mocha","recorder","request-promise-native","testing"],"created_at":"2024-11-10T19:27:40.597Z","updated_at":"2025-04-25T12:32:09.533Z","avatar_url":"https://github.com/heiseonline.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# request-promise-native-record\n\n[![Build Status](https://travis-ci.org/heiseonline/request-promise-native-record.svg?branch=master)](https://travis-ci.org/heiseonline/request-promise-native-record)\n\n[![Dependency Status](https://img.shields.io/david/heiseonline/request-promise-native-record.svg?style=flat-square)](https://david-dm.org/heiseonline/request-promise-native-record)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\nWhen writing unit tests for APIs that consume remote web services, your goal is to test your code, not the network or remote web service. `request-promise-native-record` records the answers of these web services and plays them back later.\n\nIf a recording does not exist or the environment variable `HTTP_MODE` is set to `record`, HTTP responses are written to files when running your tests. You may want to check these files into your VCS. If recordings are available, they will be used automatically for further test runs. No network traffic will occur from now on.\n\n## Installation\n\n```sh\nyarn add --dev @heise/request-promise-native-record\n```\n\nor\n\n```sh\nnpm install --save-dev @heise/request-promise-native-record\n```\n\n## Usage\n\n`lib/my-api.js`:\n\n```js\nconst request = require('request-promise-native')\n\nclass Api {\n  static getFoo() {\n    return request.get('http://example.com/')\n  }\n}\n\nmodule.exports = Api\n```\n\n`test/my-api.js`:\n\n```js\nconst assert = require('assert')\nconst record = require('@heise/request-promise-native-record')\n\nrecord.start({folder: '/tmp'})\nconst Api = require('../lib/my-api')\n\ndescribe('my description', () =\u003e {\n  it('should test my api', async () =\u003e {\n    let response = await Api.getFoo() // 1. call: network request\n    let response = await Api.getFoo() // 2. call: read from fs\n    assert.ok(response.includes('Example Domain'))\n  })\n})\n```\n\nGenerated file:\n\n```sh\n$ cat /tmp/14ba12b98882bca3bc00abff8735175a2544a9c1aa64794e85503198d84595b5.json \n\"\u003c!doctype html\u003e\\n\u003chtml\u003e\\n\u003chead\u003e[...]\"\n```\n\n## Storing/Retrieving response headers, status codes and response body\n\nTo save the full response instead of just the response body, use the option [`resolveWithFullResponse`](https://github.com/request/request-promise#get-the-full-response-instead-of-just-the-body). The `Authorization` header is removed from the headers object before writing to the hard disk.\n\n`lib/my-api.js`:\n\n```js\nconst request = require('request-promise-native')\n\nclass Api {\n  static getFoo() {\n    return request.get('http://example.com/', {resolveWithFullResponse: true})\n  }\n}\n\nmodule.exports = Api\n```\n\n## Limitations\n\n- Currently only `request-promise-native` is supported as HTTP lib.\n- Currently only `request.get()` is supported.\n- The generated files are stored flat in the specified directory. You may have to clean up the files by yourself.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheiseonline%2Frequest-promise-native-record","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheiseonline%2Frequest-promise-native-record","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheiseonline%2Frequest-promise-native-record/lists"}