How to use the nock.load function in nock

To help you get started, we’ve selected a few nock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nock / nock / types / tests.ts View on Github external
/// dont_print option
nock.recorder.rec({
  dont_print: true,
})
// ... some HTTP calls
const nockCalls = nock.recorder.play()

/// output_objects option
nock.recorder.rec({
  output_objects: true,
})
// ... some HTTP calls
const nockCallObjects = nock.recorder.play()

let nocks = nock.load(str)
nocks.forEach(nock => {
  nock = nock.filteringRequestBody((body: string) => {
    return body
  })
})

//  Pre-process the nock definitions as scope filtering has to be defined before the nocks are defined (due to its very hacky nature).
const nockDefs = nock.loadDefs(str)
nockDefs.forEach(def => {
  //  Do something with the definition object e.g. scope filtering.
  def.options = def.options || {}
  def.options.filteringScope = (scope: string) => {
    return /^https:\/\/api[0-9]*.example.test/.test(scope)
  }
})
//  Load the nocks from pre-processed definitions.
github ProboCI / probo / test / __nockout.js View on Github external
function initNock(fixture, opts) {
  var fixtureFile = './test/fixtures/' + fixture;

  var nocked = {};
  var requiredNocks = [];

  opts = opts || {};
  opts.not_required = opts.not_required || [];

  var nockMode = opts.mode || defaultNockMode;

  var nocks;
  if (nockMode === 'PLAY') {
    nocks = nock.load(fixtureFile);

    if (opts.processor) {
      var ret = opts.processor(nocks);
      if (typeof ret != 'undefined') {
        nocks = ret;
      }
    }

    nocks.forEach(function(n, i) {
      nocked[n.name || 'loaded_' + i] = n;
    });


    // allow some mocks to be not required
    Object.keys(nocked).filter(function(name) {
      return opts.not_required.indexOf(name) < 0;
github poetic / nock-vcr-recorder / lib / use-cassette.js View on Github external
function beforeTest(cassettePath, options) {
  nockReset();

  // I feel like this could be written better. Some duplication here
  if (options.mode === 'all') {
    nockStartRecording();
  } else if (fs.existsSync(cassettePath)) {
    if (!nock.isActive()) {
      nock.activate();
    }

    nock.load(cassettePath);
  } else {
    nockStartRecording();
  }
}
github coinbase / coinbase-pro-node / tests / public_client.spec.js View on Github external
test('streams trades', done => {
      nock.load('./tests/mocks/pubclient_stream_trades.json');

      let last = from;
      let current;

      publicClient
        .getProductTradeStream('BTC-USD', from, to)
        .on('data', data => {
          current = data.trade_id;
          assert.equal(typeof current, 'number');
          assert.equal(
            current,
            last + 1,
            current + ' is next in series, last: ' + last
          );
          last = current;
        })
github coinbase / coinbase-pro-node / tests / public_client.spec.js View on Github external
test('.getProductTradeStream() with current date function', done => {
      nock.load('./tests/mocks/pubclient_stream_trades_function.json');
      let last = from;
      let current;

      publicClient
        .getProductTradeStream(
          'BTC-USD',
          from,
          trade => Date.parse(trade.time) >= Date.now()
        )
        .on('data', data => {
          current = data.trade_id;
          assert.equal(typeof current, 'number');
          assert.equal(
            current,
            last + 1,
            current + ' is next in series, last: ' + last
github github-tools / github / test / search.spec.js View on Github external
before(function() {
      github = new Github({
         username: testUser.USERNAME,
         password: testUser.PASSWORD,
         auth: 'basic',
      });
      nock.load('test/fixtures/search.json');
   });
github jaridmargolin / s3-site / test / bucket.js View on Github external
before(function () {
    if (mocksExist) {
      nock.load(mocksPath);
    } else {
      TEST_DELAY = 1000;
      nock.recorder.rec({
        dont_print: true,
        output_objects: true
      });
    }
  });
github apis-is / apis / test / integration / endpoints.js View on Github external
before(() => {
  if (process.env.RECORD_MOCK_DATA) {
    nock.recorder.rec({
      output_objects: true,
      dont_print: true,
    })
  } else {
    nock.load(mockDataFilename)
  }
})