I have a frontend that I’m testing using some testing framework. I use npmjs.org/packages/nock to do mocking. This works great when running my tests locally on my laptop.
When I push my code, and Drone runs my tests, I am presented with a “ECONNREFUSED” for http://localhost:8000 (which is my API endpoint that I’m mocking).
So for some reason, my mocking is failing on Drone/Docker. I have ran my tests on my laptop, on a brand new server (with same ENV variables as Drone), and on a colleague’s laptop and they all worked. Is there anything I’m missing here? This the test logic that fails inside my Docker pipeline:
// Testing only generated HTML
test('Route / exits and render HTML', async t => {
nock(process.env.CMS_URL) // localhost:8000
.get('/api/v1/cities')
.reply(200, {
cities: []
})
let context = { req: {} }
const { html } = await t.context.nuxt.renderRoute('/', context)
t.true(html.includes('Hello World'))
})
this is the error inside my Drone logs:
✖ Route / exits and render HTML Rejected promise returned by test
{ Error: connect ECONNREFUSED http://localhost:8000
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8000,
config:
{ adapter: [Function: httpAdapter],
transformRequest: { '0': [Function: transformRequest] },
transformResponse: { '0': [Function: transformResponse] },
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers:
{ Accept: 'application/json, text/plain, */*',
'User-Agent': 'axios/0.17.1' },
method: 'get',
url: 'http://localhost:8000/api/v1/cities',
data: undefined }
I’ve already tried changing URLs to 0.0.0.0:8000 or 127.0.0.1:8000, but that didn’t help: same error. It simply should not even be trying to connect to that URL, because I’m intercepting it with my mocking.