Skip to content

Instantly share code, notes, and snippets.

@tbjers
Created April 16, 2019 14:40
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 tbjers/e0f49289bd41af5a4384f5e9b8cc0599 to your computer and use it in GitHub Desktop.
Save tbjers/e0f49289bd41af5a4384f5e9b8cc0599 to your computer and use it in GitHub Desktop.
Recording Nock objects and saving to disk
// eslint-disable-next-line import/no-extraneous-dependencies
const nock = require('nock');
const fs = require('fs');
const path = require('path');
nock.recorder.rec({
dont_print: true,
output_objects: true
});
const playback = filename => {
const pathname = path.resolve(__dirname, '..', '__tests__', 'fixtures', filename);
const nockObjects = nock.recorder.play();
fs.writeFileSync(pathname, JSON.stringify(nockObjects, null, 2));
nock.recorder.clear();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment