Skip to content

Instantly share code, notes, and snippets.

@crccheck
Last active August 4, 2020 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crccheck/1239155e6baa3f48e55fdad5b8da43bf to your computer and use it in GitHub Desktop.
Save crccheck/1239155e6baa3f48e55fdad5b8da43bf to your computer and use it in GitHub Desktop.
ungzip nock.recorder.rec() output

https://github.com/nock/nock#recording

Recording

This is a cool feature:

Guessing what the HTTP calls are is a mess, especially if you are introducing nock on your already-coded tests.

For these cases where you want to mock an existing live system you can record and playback the HTTP calls like this:

nock.recorder.rec()
// Some HTTP calls happen and the nock code necessary to mock
// those calls will be outputted to console

Recording relies on intercepting real requests and responses and then persisting them for later use.

In order to stop recording you should call nock.restore() and recording will stop.

s = [/*...nock output here*/]
zlib = require('zlib')
zlib.gunzip(Buffer.from(s.join(''), 'hex'), (err, x) => console.log(x.toString()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment