How to use the nock.activate 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 adobe / helix-cli / test / testRemotePublishCmd.failprepare.js View on Github external
this.timeout(5000);
    writeDictItem = sinon.fake.resolves(true);
    purgeAll = sinon.fake.resolves(true);

    RemotePublishCommand = proxyquire('../src/remotepublish.cmd', {
      '@adobe/fastly-native-promises': () => ({
        transact: (fn) => fn(3),
        writeDictItem,
        purgeAll,
      }),
    });

    // ensure to reset nock to avoid conflicts with PollyJS
    nock.restore();
    nock.cleanAll();
    nock.activate();

    scope = nock('https://adobeioruntime.net')
      .post('/api/v1/web/helix/helix-services/publish@v2')
      .reply(400, {});
  });
github adobe / helix-cli / test / testRemotePublishCmd.botconfig.js View on Github external
this.timeout(5000);
    writeDictItem = sinon.fake.resolves(true);
    purgeAll = sinon.fake.resolves(true);

    RemotePublishCommand = proxyquire('../src/remotepublish.cmd', {
      '@adobe/fastly-native-promises': () => ({
        transact: (fn) => fn(3),
        writeDictItem,
        purgeAll,
      }),
    });

    // ensure to reset nock to avoid conflicts with PollyJS
    nock.restore();
    nock.cleanAll();
    nock.activate();

    scope = nock('https://adobeioruntime.net')
      .post('/api/v1/web/helix/helix-services/publish@v2')
      .reply(200, {})
      .post('/api/v1/web/helix/helix-services/logging@v1')
      .reply(200, {});
  });
github adobe / helix-cli / test / testRemotePublishCmd.js View on Github external
purgeAll = sinon.fake.resolves(true);
    softPurgeKey = sinon.fake.resolves(true);

    RemotePublishCommand = proxyquire('../src/remotepublish.cmd', {
      '@adobe/fastly-native-promises': () => ({
        transact: (fn) => fn(3),
        writeDictItem,
        purgeAll,
        softPurgeKey,
      }),
    });

    // ensure to reset nock to avoid conflicts with PollyJS
    nock.restore();
    nock.cleanAll();
    nock.activate();
  });
github adobe / helix-cli / test / testRemotePublishCmd.filter.js View on Github external
softPurgeKey = sinon.fake.resolves(true);

    RemotePublishCommand = proxyquire('../src/remotepublish.cmd', {
      '@adobe/fastly-native-promises': () => ({
        transact: (fn) => fn(3),
        writeDictItem,
        purgeAll,
        softPurgeKey,
      }),
    });


    // ensure to reset nock to avoid conflicts with PollyJS
    nock.restore();
    nock.cleanAll();
    nock.activate();

    nock('https://adobeioruntime.net')
      .post('/api/v1/web/helix/helix-services/publish@v2', (body) => {
        publishedstrains = body.configuration.strains.reduce((o, strain) => {
          if (strain.origin) {
            // eslint-disable-next-line no-param-reassign
            o[strain.name] = strain.origin.hostname === 'www.adobe.io' ? 'branch' : 'master';
          }
          if (strain.package) {
            // eslint-disable-next-line no-param-reassign
            o[strain.name] = strain.package;
          }
          return o;
        }, {});
        return true;
      })
github adobe / helix-cli / test / testRemotePublishCmd.customvcl.js View on Github external
softPurgeKey = sinon.fake.resolves(true);

    ProxiedRemotePublishCommand = proxyquire('../src/remotepublish.cmd', {
      '@adobe/fastly-native-promises': () => ({
        transact: (fn) => fn(3),
        writeDictItem,
        purgeAll,
        softPurgeKey,
      }),
    });


    // ensure to reset nock to avoid conflicts with PollyJS
    nock.restore();
    nock.cleanAll();
    nock.activate();

    scope = nock('https://adobeioruntime.net')
      .post('/api/v1/web/helix/helix-services/publish@v2', (body) => {
        ({ vcl } = body);
        return true;
      })
      .reply(200, {})
      .post('/api/v1/web/helix/helix-services/logging@v1')
      .reply(200, {});

    // set up a fake git repo.
    testRoot = await createTestRoot();
    await fs.copy(path.resolve(__dirname, 'fixtures/filtered-master.yaml'), path.resolve(testRoot, 'helix-config.yaml'));

    // throw a Javascript error when any shell.js command encounters an error
    shell.config.fatal = true;
github Netflix / pollyjs / packages / @pollyjs / adapter-node-http / src / index.js View on Github external
body = JSON.stringify(body);
          }
        }

        adapter.handleRequest({
          url,
          method,
          headers,
          body,
          requestArguments: { req, body, respond, parsedArguments }
        });
      });
    });

    // Activate nock so it can start to intercept all outgoing requests
    nock.activate();
  }
github ambrosus / ambrosus-nop / test / services / setup_creator.js View on Github external
beforeEach(() => {
      if (!nock.isActive()) {
        nock.activate();
      }
    });
github balena-io / balena-cli / tests / balena-api-mock.ts View on Github external
constructor() {
		nock.cleanAll();

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

		this.scope = nock(BalenaAPIMock.basePathPattern);

		nock.emitter.on('no match', this.handleUnexpectedRequest);
	}
github unlock-protocol / unlock / unlock-js / src / __tests__ / helpers / nockHelper.js View on Github external
cleanAll() {
    nock.cleanAll()
    if (!this.recording) {
      nock.restore()
      nock.activate()
    }
    this._noMatches = []
  }
github ericclemmons / node-recorder / src / Recorder.ts View on Github external
const [options] = REQUEST_ARGUMENTS.get(req);

          const interceptedRequest: InterceptedRequest = {
            body,
            headers,
            method,
            options,
            req,
            respond: respond as nock.ReplyCallback
          };

          recorder.handleRequest(interceptedRequest);
        });
    });

    nock.activate();
  }
}