How to use the proxyquire.preserveCache function in proxyquire

To help you get started, we’ve selected a few proxyquire 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 / tests / test_reply_with_file.js View on Github external
'use strict'

// Tests for `.replyWithFile()`.

const path = require('path')
const { expect } = require('chai')
const proxyquire = require('proxyquire').preserveCache()
const nock = require('..')
const got = require('./got_client')

require('./setup')

const textFile = path.join(__dirname, '..', 'assets', 'reply_file_1.txt')
const binaryFile = path.join(__dirname, '..', 'assets', 'reply_file_2.txt.gz')

describe('`.replyWithFile()', () => {
  it('reply with file', async () => {
    const scope = nock('http://example.test')
      .get('/')
      .replyWithFile(200, textFile)

    const { statusCode, body } = await got('http://example.test/')
github nock / nock / tests / test_scope.js View on Github external
'use strict'

const path = require('path')
const { expect } = require('chai')
const sinon = require('sinon')
const proxyquire = require('proxyquire').preserveCache()
const Interceptor = require('../lib/interceptor')
const nock = require('..')
const got = require('./got_client')

require('./setup')

it('scope exposes interceptors', () => {
  const scopes = nock.load(path.join(__dirname, 'fixtures', 'goodRequest.json'))

  expect(scopes).to.be.an.instanceOf(Array)
  expect(scopes).to.have.lengthOf.at.least(1)

  scopes.forEach(scope => {
    scope.interceptors.forEach(interceptor => {
      expect(interceptor).to.be.an.instanceOf(Interceptor)
      interceptor.delayConnection(100)
github nock / nock / tests / test_back.js View on Github external
'use strict'

const http = require('http')
const fs = require('fs')
const path = require('path')
const { beforeEach, test } = require('tap')
const proxyquire = require('proxyquire').preserveCache()
const nock = require('..')

require('./cleanup_after_each')()

beforeEach(done => {
  nockBack.setMode('wild')
  nockBack.fixtures = `${__dirname}/fixtures`
  done()
})

const nockBack = nock.back
const exists = fs.existsSync

function testNock(t) {
  let dataCalled = false

proxyquire

Proxies nodejs require in order to allow overriding dependencies during testing.

MIT
Latest version published 5 years ago

Package Health Score

74 / 100
Full package analysis