I am using nock.back as part of mocha tests in my project.
Even though I have setup nock.enableNetConnect
, nock.back still records outgoing calls to the domain.
const nock = require('nock')
const path = require('path')
nock.back.fixtures = path.join(__dirname, 'fixtures')
// use recorded nocks, and record new nocks - don't remove
nock.back.setMode('record')
nock.enableNetConnect(/(vault|localhost|schema-registry)/)
const noBodyMatching = scope => {
scope.filteringRequestBody = (_body, recordedBody) => recordedBody
nock.enableNetConnect(/(vault|localhost|schema-registry)/)
}
const defaultOptions = {
before: noBodyMatching
}
const nockBack = (fixture, options) => {
let nockDone
beforeEach(async function() {
// eslint-disable-next-line
;({ nockDone } = await nock.back(fixture, {
...defaultOptions,
...options
}))
})
afterEach(function() {
nockDone()
})
}
module.exports = {
nockBack,
defaultOptions
}
I still get errors like following:
No match for request {\n \"method\": \"GET\",\n \"url\": \"http://schema-registry:3000/find-schema-by-routing-key/event.serviceability.offers.retry.queued\"
Looking at some existing/closed issues, I found following but didn't have any luck: https://github.com/nock/nock/issues/484#issuecomment-191822034
Would someone know how to get nock.back to ignore certain domains? or is this not possible?