Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
})
// .removeInterceptor()
nock.removeInterceptor({
hostname: 'localhost',
path: '/mockedResource',
})
nock.removeInterceptor({
hostname: 'localhost',
path: '/login',
method: 'POST',
proto: 'https',
})
const interceptor = nock('http://example.test').get('somePath')
nock.removeInterceptor(interceptor)
// Events
/// Global no match event
nock.emitter.on('no match', (req: any) => {})
// Nock Back
/// Setup
nock.back.fixtures = '/path/to/fixtures/'
nock.back.setMode('record')
/// Usage
const before = (def: nock.Definition) => {
def.options = def.options || {}
def.options.filteringScope = (scope: string) => {
return /^https:\/\/api[0-9]*.example.test/.test(scope)
}
enable_reqheaders_recording: true,
})
/// logging option
const nullAppender = (content: string) => {}
nock.recorder.rec({
logging: nullAppender,
})
/// use_separator option
nock.recorder.rec({
use_separator: false,
})
// .removeInterceptor()
nock.removeInterceptor({
hostname: 'localhost',
path: '/mockedResource',
})
nock.removeInterceptor({
hostname: 'localhost',
path: '/login',
method: 'POST',
proto: 'https',
})
const interceptor = nock('http://example.test').get('somePath')
nock.removeInterceptor(interceptor)
// Events
/// Global no match event
nock.emitter.on('no match', (req: any) => {})
it('should repsect retry config', async () => {
// simulate first request network fail
let networkFail = true;
nock.removeInterceptor(interceptorS3);
scope.persist(false);
interceptorS3.twice().reply(
function(url, _, cb) {
if (networkFail) {
networkFail = false;
return cb('Error');
}
cb(null, mockPut(url, this.req.headers));
},
{
etag: 'test',
}
);
afterEach(async function() {
nock.removeInterceptor(nockLoginPage);
testutil.stopServer();
});
it("should open and not save wrong yaml", async function() {
afterEach(function() {
nock.removeInterceptor(scope);
});
afterEach(function() {
nock.removeInterceptor(localVaultMock);
});
afterEach(function(bddone){
nock.removeInterceptor(nockLoginPage);
return bddone();
});
after(function() {
nock.removeInterceptor(globalVaultMock);
nock.cleanAll();
});
it('should retry complete request on 202 status code', async () => {
const mock202 = jest
.fn()
.mockName('202 mock')
.mockReturnValue('');
nock.removeInterceptor(interceptorComplete);
scope.persist(false);
scope.post('/multipart/complete').reply(202, () => mock202());
scope.post('/multipart/complete').reply(200, (_, data) => mockComplete(JSON.parse(data)));
const u = new S3Uploader({});
u.setUrl(testHost);
u.setApikey(testApikey);
u.addFile(getTestFile());
const res = await u.execute();
expect(res[0].handle).toEqual('test_handle');
expect(res[0].status).toEqual('test_status');
expect(mock202).toHaveBeenCalledTimes(1);
expect(mockComplete).toHaveBeenCalledTimes(1);
mock.interceptors.forEach((interceptor) => nock.removeInterceptor(interceptor));
});