Skip to content

Instantly share code, notes, and snippets.

@outofambit
Created May 10, 2018 19:26
Show Gist options
  • Save outofambit/d4cda06964251102f1c8ba94a706abdd to your computer and use it in GitHub Desktop.
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)
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