Created
April 16, 2019 14:40
-
-
Save tbjers/e0f49289bd41af5a4384f5e9b8cc0599 to your computer and use it in GitHub Desktop.
Recording Nock objects and saving to disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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