
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
@heise/request-promise-native-record
Advanced tools
Records and plays back responses from remote web services so you can test your code in peace.
When 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.
If 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.
yarn add --dev @heise/request-promise-native-record
or
npm install --save-dev @heise/request-promise-native-record
lib/my-api.js
:
const request = require('request-promise-native')
class Api {
static getFoo() {
return request.get('http://example.com/')
}
}
module.exports = Api
test/my-api.js
:
const assert = require('assert')
const record = require('@heise/request-promise-native-record')
record.start({folder: '/tmp'})
const Api = require('../lib/my-api')
describe('my description', () => {
it('should test my api', async () => {
let response = await Api.getFoo() // 1. call: network request
let response = await Api.getFoo() // 2. call: read from fs
assert.ok(response.includes('Example Domain'))
})
})
Generated file:
$ cat /tmp/14ba12b98882bca3bc00abff8735175a2544a9c1aa64794e85503198d84595b5.json
"<!doctype html>\n<html>\n<head>[...]"
To save the full response instead of just the response body, use the option resolveWithFullResponse
. The Authorization
header is removed from the headers object before writing to the hard disk.
lib/my-api.js
:
const request = require('request-promise-native')
class Api {
static getFoo() {
return request.get('http://example.com/', {resolveWithFullResponse: true})
}
}
module.exports = Api
request-promise-native
is supported as HTTP lib.request.get()
is supported.v1.0.13, 2019-06-11
FAQs
Records and plays back responses from remote web services so you can test your code in peace.
We found that @heise/request-promise-native-record demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.