How to use the nock.back 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 isomorphic-git / isomorphic-git / __tests__ / server-only.test-GitRemoteHTTP.js View on Github external
it('preparePull (Github response)', async () => {
    // Setup
    const { nockDone } = await nock.back(
      'GitRemoteHTTP - preparePull (Github response).json'
    )
    // Test
    const remote = await GitRemoteHTTP.discover({
      core: 'default',
      service: 'git-upload-pack',
      url: 'https://github.com/isomorphic-git/isomorphic-git',
      headers: {}
    })
    expect(remote).toBeTruthy()
    expect(remote.symrefs.size > 0)
    expect(remote.symrefs.get('HEAD')).toBe('refs/heads/master')
    // Teardown
    nockDone()
  })
github isomorphic-git / isomorphic-git / __tests__ / server-only.test-GitRemoteHTTP.js View on Github external
it('preparePull (mock response)', async () => {
    // Setup
    const { nockDone } = await nock.back(
      'GitRemoteHTTP - preparePull (mock response).json'
    )
    // Test
    const remote = await GitRemoteHTTP.discover({
      core: 'default',
      service: 'git-upload-pack',
      url: 'http://example.dev/test-GitRemoteHTTP',
      headers: {}
    })
    expect(remote).toBeTruthy()
    // Teardown
    nockDone()
  })
github isomorphic-git / isomorphic-git / __tests__ / server-only.test-pull.js View on Github external
it('basic pull', async () => {
    // Setup
    const { nockDone } = await nock.back('pull - basic pull.json')
    const { dir, gitdir } = await makeFixture('test-pull-client')
    // Test
    const desiredOid = '97c024f73eaab2781bf3691597bc7c833cb0e22f'
    await pull({
      dir,
      gitdir,
      ref: 'master',
      fastForwardOnly: true
    })
    const oid = await resolveRef({
      gitdir,
      ref: 'master'
    })
    expect(oid).toEqual(desiredOid)
    // Teardown
    nockDone()
github elementary / houston / test / utility / http.ts View on Github external
export async function record (p: string, opts?: INockOptions) {
  const options: any = {} // tslint:disable-line no-any

  if (opts != null && opts.ignoreBody === true) {
    options.before = (scope) => {
      scope.filteringRequestBody = () => '*'
    }
  }

  const { nockDone } = await nock.back(p, options)

  return { done: nockDone }
}
github nock / nock / types / tests.ts View on Github external
request.get('http://example.test', (err: any, res: any, body: string) => {
    nockDone()
    // usage of the created fixture
    nock.back('fixture.json', (nockDone: () => void) => {
      nockDone() // never gets here
    })
  })
})
github rgrove / rawgit / test / helpers.js View on Github external
beforeEach((done) => {
    nock.back(filename, cb => {
      nockDone = cb;

      // Nock fucks everything up unless we keep re-enabling connections to
      // Express.
      nock.enableNetConnect('127.0.0.1');

      done();
    });
  });
github npms-io / queries / test / spec / search.js View on Github external
it('should make use of options.from and options.size', () => {
        let nockDone;

        nockBack('search-react-with-from-and-limit.json', (_nockDone) => { nockDone = _nockDone; });

        return queries.search('react', localEsClient, { from: 1, size: 1 })
        .then((res) => {
            expect(res.total).to.be.greaterThan(1);
            expect(res.results).to.have.length(1);
            expect(res.results[0].package.name).to.not.equal('react');
            nockDone();
        });
    });
github npms-io / queries / test / spec / searchSimilar.js View on Github external
it('should return the desired results', () => {
        let nockDone;

        nockBack('search-similar.json', (_nockDone) => { nockDone = _nockDone; });

        return queries.search.similar('chaik', localEsClient)
        .then((similar) => {
            expect(similar).to.have.length(10);
            expect(similar[0]).to.contain.all.keys('package', 'score', 'searchScore');
            expect(similar[0].package.name).to.equal('chalk');
            nockDone();
        });
    });
github npms-io / queries / test / spec / search.js View on Github external
it('should return the desired results of a complex query', () => {
        let nockDone;

        nockBack('search-complex-query-spawn.json', (_nockDone) => { nockDone = _nockDone; });

        return queries.search('maintainer:satazor keywords:spawn,-foo is:deprecated not:insecure boost-exact:no spawn', localEsClient)
        .then((res) => {
            expect(res.total).to.equal(1);
            expect(res.results).to.have.length(1);
            expect(res.results[0].package.name).to.equal('cross-spawn-async');
            nockDone();
        });
    });
github npms-io / queries / test / spec / search.js View on Github external
it('should allow to search all packages of an author', () => {
        let nockDone;

        nockBack('search-author-sindresorhus.json', (_nockDone) => { nockDone = _nockDone; });

        return queries.search('author:sindresorhus', localEsClient)
        .then((res) => {
            expect(res.total).to.equal(943);
            expect(res.results).to.have.length(25);
            res.results.forEach((result) => expect(result.package.author.username).to.equal('sindresorhus'));
            nockDone();
        });
    });