How to use the nock.enableNetConnect 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 greenkeeperio / greenkeeper / test / jobs / cancel-stripe-subscription.js View on Github external
const nock = require('nock')

const dbs = require('../../lib/dbs')
const removeIfExists = require('../helpers/remove-if-exists')

const cancelStripeSubscription = require('../../jobs/cancel-stripe-subscription')

nock.disableNetConnect()
nock.enableNetConnect('localhost')

afterAll(async () => {
  const { payments } = await dbs()
  await Promise.all([
    removeIfExists(payments, '123')
  ])
})

test('Cancel Stripe Subscription', async () => {
  const { payments } = await dbs()
  expect.assertions(3)

  nock('https://api.stripe.com/v1')
    .delete('/subscriptions/345')
    .reply(200, () => {
      // Stripe called
github oaeproject / Hilary / packages / oae-tests / runner / before-tests.js View on Github external
afterEach(function(callback) {
  // Ensure we don't mess with the HTTP stack by accident
  nock.enableNetConnect();

  // Clean up all the mocks
  nock.cleanAll();

  log().info('Finishing test "%s"', this.currentTest.title);
  return callback();
});
github marcelduran / webpagetest-api / test / helpers / nock-server.js View on Github external
function WebPageTestMockServer(host) {
  var server;

  if (!(this instanceof WebPageTestMockServer)) {
    return new WebPageTestMockServer(host);
  }

  server = nock(host || 'https://www.webpagetest.org');
  nock.enableNetConnect();

  // request/response mapping
  Object.keys(reqResMap).forEach(function (source) {
    var filename = reqResMap[source],
        pathname = path.join(PATH_RESPONSES, filename),
        ext = (path.extname(pathname) || '').slice(1),
        type = typeMap[ext];

    if (filename) {
      server
        .filteringPath(/http%3A%2F%2F127.0.0.1%3A\d+%2F/g,
          'http%3A%2F%2F127.0.0.1%3A8000%2F')
        .persist()
        .get(source)
        .replyWithFile(200, pathname, {'Content-Type': type});
    } else {
github probot / probot / test / setup.ts View on Github external
// This file gets loaded when mocha is run

process.env.LOG_LEVEL = 'fatal'

import nock from 'nock'

nock.disableNetConnect()
nock.enableNetConnect(/127\.0\.0\.1/)
github veganaut / veganaut-backend / test / helpers_.js View on Github external
var mockery = require('mockery');
mockery.enable({
    warnOnUnregistered: false
});

// Register the mock mailer with mockery
// TODO: should use more absolute path?
mockery.registerMock('../utils/mailTransporter.js', {
    sendMail: function(mail) {
        mockMailer.sentMails.push(mail);
        return BPromise.resolve(undefined);
    }
});

// Configure Nock to allow connections to localhost (for the e2e tests to connect to the API).
nock.enableNetConnect('localhost:' + port);

// Create a mock response for the Nominatim API.
// This mock will keep on re-installing itself to allow for unlimited requests.
var nominatim = nock('https://nominatim.openstreetmap.org');
var installNominatimMock = function() {
    nominatim
        .get('/reverse')
        .query(true)
        .optionally()
        .reply(200, function() {
            // Re-install the mock to always be ready for a next request
            installNominatimMock();
            return {
                address: {
                    house_number: '1', // jshint ignore:line
                    road: 'Bundesplatz',
github greenkeeperio / greenkeeper / test / lib / github.js View on Github external
const nock = require('nock')
const simple = require('simple-mock')

nock.disableNetConnect()
nock.enableNetConnect('localhost')

test('parse github host', async () => {
  expect.assertions(1)

  nock('https://enterprise.github')
    .get('/api/v3/repos/greenkeeperio/greenkeeper')
    .reply(200, () => {
      expect(true).toBeTruthy()
    })

  simple.mock(process.env, 'GITHUB_HOST', 'https://enterprise.github')

  const Github = require('../../lib/github')
  const github = Github()

  try {
github jarrodldavis / probot-gpg / test / integration.js View on Github external
before(async () => {
    probotOptions = {
      id: process.env.APP_ID || createAppId(),
      secret: process.env.WEBHOOK_SECRET || createSha(),
      cert: process.env.PRIVATE_KEY || await createPrivateKey(),
      port: 3000
    };

    nock.disableNetConnect();
    nock.enableNetConnect('localhost:3000');
  });
github extraStatic / stapsher / __tests__ / helpers / disablers.js View on Github external
module.exports.disableNetConnect = () => {
  nock.disableNetConnect()
  nock.enableNetConnect('localhost')
}
github greenkeeperio / greenkeeper / test / jobs / send-stripe-cancel-survey.js View on Github external
const nock = require('nock')
const dbs = require('../../lib/dbs')

const timeToWaitAfterTests = 1000
const waitFor = (milliseconds) => {
  return new Promise((resolve) => {
    setTimeout(resolve, milliseconds)
  })
}

nock.disableNetConnect()
nock.enableNetConnect('localhost')

describe('send-stripe-cancel-survey', async () => {
  beforeEach(async () => {
    const { payments } = await dbs()
    await payments.put({
      _id: '1',
      stripeSubscriptionId: null
    })
    await payments.put({
      _id: '2',
      stripeSubscriptionId: 'hello'
    })

    jest.clearAllMocks()
  })
github greenkeeperio / greenkeeper / test / jobs / github-event / check_suite / completed.js View on Github external
const nock = require('nock')

const dbs = require('../../../../lib/dbs')
const removeIfExists = require('../../../helpers/remove-if-exists')

nock.disableNetConnect()
nock.enableNetConnect('localhost')

describe('github-event checksuite_completed', async () => {
  beforeAll(async () => {
    const { installations } = await dbs()

    await installations.put({
      _id: '1111',
      installation: '7331'
    })
  })

  beforeEach(() => {
    jest.resetModules()
  })

  afterAll(async () => {