Created
May 10, 2018 19:26
-
-
Save outofambit/d4cda06964251102f1c8ba94a706abdd to your computer and use it in GitHub Desktop.
nockback helper to only record remote url requests (adapted from https://github.com/Flet/tape-nock/blob/master/README.md)
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
const nock = require('nock'); | |
const path = require('path'); | |
nock.back.fixtures = path.resolve(`${__dirname}/fixtures/nockback/`); | |
nock.back.setMode('lockdown'); // change to 'record' to make new recordings | |
const allowLocalhost = () => { nock.enableNetConnect('127.0.0.1'); }; | |
const filterLocalhost = (reqs) => { | |
const localhost = /http:\/\/127\.0\.0\.1.*/; | |
return reqs.filter(r => !localhost.test(r.scope)); | |
}; | |
const nockBackOptions = { after: allowLocalhost, afterRecord: filterLocalhost }; | |
const nockBackRemotes = recordingName => nock.back(recordingName, nockBackOptions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment