How to use the nock.disableNetConnect 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 elementary / houston / test / service / github.js View on Github external
test.before((t) => {
  // This will capture any incoming data and put it to a file.
  // Use it for verifying we are testing real data.
  // Make sure to enable net connect and disable the tests you don't want
  // to run with `test.skip()`!
  // nock.recorder.rec({
  //   logging: (context) => fs.appendFile('github.log', context)
  // })

  nock.disableNetConnect() // Disables all real HTTP requests
  db.connect(config.database)
})
github actions / cache / jest.config.js View on Github external
require('nock').disableNetConnect();

module.exports = {
  clearMocks: true,
  moduleFileExtensions: ['js', 'ts'],
  testEnvironment: 'node',
  testMatch: ['**/*.test.ts'],
  testRunner: 'jest-circus/runner',
  transform: {
    '^.+\\.ts$': 'ts-jest'
  },
  verbose: true
}

const processStdoutWrite = process.stdout.write.bind(process.stdout)
process.stdout.write = (str, encoding, cb) => {
  // Core library will directly call process.stdout.write for commands
github steve-jansen / json-proxy / spec / shared / setup.js View on Github external
function configureNock(options, config) {
  var result = {};
  // deny all real net connections except for localhost
  nock.disableNetConnect();
  nock.enableNetConnect('localhost');

  function createNock(url) {
    var instance = nock(url),
        expectedViaHeader = options.headers['Via'] ||
                            'http://localhost:' + config.proxy.gateway.port,
        expectedHostHeader = options.headers['Host'] || /.*/;

    if (options.proxy === true) {
      // verify that the request was actually proxied
      // optionally support downstream proxies with non-RFC expectations on
      // the Host and Via request headers
      instance.matchHeader('via', expectedViaHeader);
      instance.matchHeader('host', expectedHostHeader);
    }
github solid / solid-auth-client / src / __test__ / solid-auth-client.spec.js View on Github external
beforeEach(() => {
  polyfillWindow()
  nock.disableNetConnect()
  instance.removeAllListeners('login')
  instance.removeAllListeners('logout')
  instance.removeAllListeners('session')
})
github Crypto-Punkers / resolver-engine / test / __tests__ / parsers / urlresolver.spec.ts View on Github external
beforeAll(() => {
    nock.disableNetConnect();
    correctUrls.forEach(pair => {
      const [url, content] = pair;

      if (content) {
        nock(url)
          .get("")
          .reply(200, content)
          .persist();
      } else {
        nock(url)
          .get("")
          .reply(404, "")
          .persist();
      }
    });
  });
github swagger-api / swagger-js / test / resolver / index.js View on Github external
beforeAll(() => {
            Swagger.clearCache()

            if (!nock.isActive()) {
              nock.activate()
            }

            nock.cleanAll()
            nock.disableNetConnect()

            const nockScope = nock('http://mock.swagger.test')

            if (currentCase.remoteDocuments) {
              Object.keys(currentCase.remoteDocuments).forEach((key) => {
                const docContent = currentCase.remoteDocuments[key]
                nockScope
                  .get(`/${key}`)
                  .reply(200, docContent, {
                    'Content-Type': 'application/yaml'
                  })
              })
            }
          })
github JackuB / apish / test / init-parsing-service-call.js View on Github external
before(() => {
    apib = fs.readFileSync(__dirname + '/fixtures/basic-swagger.yaml').toString();
    nock.disableNetConnect('apiblueprint.org');
  });
github veritone / veritone-sdk / packages / veritone-client-js / apis / helper / ApiClient.spec.js View on Github external
import { expect } from 'chai';
import nock from 'nock';
nock.disableNetConnect();

import veritoneApi from './ApiClient';

const apiBaseUrl = 'http://fake.domain';

describe('veritoneApi', function() {
  describe('API methods', function() {
    it('Returns the configured API functions', function() {
      const api = veritoneApi(
        {
          token: 'token-abc',
          apiToken: 'api-token-abc'
        },
        {
          libraries: {
            getLibrary: () => 'ok'
github steve-jansen / json-proxy / spec / proxy-suite.js View on Github external
function configureNock(done) {
      nock.disableNetConnect();
      nock.enableNetConnect('localhost');

      endpoints = [
        nock('http://api.example.com')
        .get('/api/hello')
        .reply(200, '{ "hello": "world" }')
        .get('/api/notfound')
        .reply(404),

        nock('http://www.example.com')
        .get('/foo/12345/bar')
        .reply(200, '{ "foo": "bar" }'),

        nock('https://secure.example.com')
        .get('/secure/api/hello')
        .reply(200, '{ "hello": "world" }')
github boyney123 / graphql.explore-tech.org / src / scripts / create-material / spec.js View on Github external
import script from './'
import nock from 'nock'
import fs from 'fs-extra'
import path from 'path'
import fm from 'front-matter'
import puppeteer from 'puppeteer'
import mockRepoData from './test-data/repo.json'
import mockReadmeData from './test-data/readme.json'
import mockReleaseData from './test-data/release.json'

nock.disableNetConnect()

nock('https://api.github.com')
  .persist()
  .get('/repos/boyney123/graphql.explore-tech.org')
  .reply(200, mockRepoData)
  .persist()
  .get('/repos/boyney123/graphql.explore-tech.org/readme')
  .reply(200, mockReadmeData)
  .persist()
  .get('/repos/boyney123/graphql.explore-tech.org/releases/latest')
  .reply(200, mockReadmeData)

let exit

const scriptArgs = [
  '_',