mocks pending and isDone() is false when running simple test in Azure pipeline

711 views Asked by At

I have a simple test

  import { expect } from 'chai';
  import request from 'request-promise';
  import nock from 'nock';
  ....
  const url = 'http://www.google.com';
  it.only('should return Test', async () => {
    const stub = nock(url).get('/').reply(200, 'Test');
    const res = await request(url);
    if (!stub.isDone()) {
      console.error('pending mocks: %j', stub.pendingMocks());
    }
    expect(stub.isDone()).equal(true);
    expect(res).equal('Test');
  });

It works fine locally however fails when run in Azure pipeline. It fails on

expect(stub.isDone()).equal(true);

console output:

pending mocks: ["GET http://www.google.com:80/"]

I'm moving legacy project to Azure and must use Node 12. Nock version is 12.0.3 I suspect it might be a timing issue however not sure how to confirm/fix it. Any help will be much appreciated

Update 1

It's the only test running, no other tests After enabling nock debugging got this:

2020-12-11T15:06:33.349Z nock.intercept Overriding ClientRequest
2020-12-11T15:06:33.350Z nock.intercept ClientRequest overridden
2020-12-11T15:06:33.350Z nock.common overriding requests
2020-12-11T15:06:33.350Z nock.common - overriding request for http
2020-12-11T15:06:33.350Z nock.common - overridden request for http
2020-12-11T15:06:33.350Z nock.common - overriding request for https
2020-12-11T15:06:33.350Z nock.common - overridden request for https
2020-12-11T15:06:33.354Z nock.back New nock back mode: dryrun
2020-12-11T15:06:33.354Z nock.recorder 0 restoring all the overridden http/https properties
2020-12-11T15:06:33.355Z nock.common restoring requests
2020-12-11T15:06:33.355Z nock.common - restoring request for http
2020-12-11T15:06:33.355Z nock.common - restored request for http
2020-12-11T15:06:33.355Z nock.common - restoring request for https
2020-12-11T15:06:33.355Z nock.common - restored request for https
2020-12-11T15:06:33.356Z nock.intercept restoring overridden ClientRequest
2020-12-11T15:06:33.356Z nock.intercept - ClientRequest restored
2020-12-11T15:06:33.356Z nock.intercept Overriding ClientRequest
2020-12-11T15:06:33.356Z nock.intercept ClientRequest overridden
2020-12-11T15:06:33.356Z nock.common overriding requests
2020-12-11T15:06:33.356Z nock.common - overriding request for http
2020-12-11T15:06:33.356Z nock.common - overridden request for http
2020-12-11T15:06:33.356Z nock.common - overriding request for https
2020-12-11T15:06:33.356Z nock.common - overridden request for https
2020-12-11T15:06:36.882Z nock.common options.host: 127.0.0.1
2020-12-11T15:06:36.882Z nock.common options.hostname in the end: "127.0.0.1"
2020-12-11T15:06:36.882Z nock.common options.host in the end: "127.0.0.1:39917"
2020-12-11T15:06:36.883Z nock.intercept interceptors for "127.0.0.1:39917"
2020-12-11T15:06:36.883Z nock.intercept filtering interceptors for basepath http://127.0.0.1:39917
2020-12-11T15:06:36.883Z nock.common options.host: 127.0.0.1:39917
2020-12-11T15:06:36.883Z nock.common options.hostname in the end: "127.0.0.1"
2020-12-11T15:06:36.883Z nock.common options.host in the end: "127.0.0.1:39917"
2020-12-11T15:06:36.883Z nock.intercept Net connect  enabled for 127.0.0.1:39917
2020-12-11T15:06:36.926Z nock.common options.host: 150.151.144.119
2020-12-11T15:06:36.926Z nock.common options.hostname in the end: "150.151.144.119"
2020-12-11T15:06:36.926Z nock.common options.host in the end: "150.151.144.119:3128"
2020-12-11T15:06:36.926Z nock.intercept interceptors for "150.151.144.119:3128"
2020-12-11T15:06:36.927Z nock.intercept filtering interceptors for basepath http://150.151.144.119:3128
2020-12-11T15:06:36.927Z nock.common options.host: 150.151.144.119:31282020-12-11T15:06:36.927Z nock.common options.hostname in the end: "150.151.144.119"
2020-12-11T15:06:36.927Z nock.common options.host in the end: "150.151.144.119:3128"
2020-12-11T15:06:36.927Z nock.intercept Net connect  enabled for 150.151.144.119:3128
pending mocks: ["GET http://www.google.com:80/"]

It looks strange that google.com doesn't appear there in the log. Instead it shows this IP - 150.151.144.119 which seems to be from Australia (???). When running locally log looks like:

nock.common options.host: 127.0.0.1 +3s
  nock.common options.hostname in the end: "127.0.0.1" +0ms
  nock.common options.host in the end: "127.0.0.1:33983" +0ms
  nock.intercept interceptors for "127.0.0.1:33983" +3s
  nock.intercept filtering interceptors for basepath http://127.0.0.1:33983 +0ms
  nock.common options.host: 127.0.0.1:33983 +0ms
  nock.common options.hostname in the end: "127.0.0.1" +0ms
  nock.common options.host in the end: "127.0.0.1:33983" +0ms
  nock.intercept Net connect  enabled for 127.0.0.1:33983 +1ms
  convertError
  nock.common options.host: www.google.com +74ms
  nock.common options.hostname in the end: "www.google.com" +1ms
  nock.common options.host in the end: "www.google.com:80" +0ms
  nock.intercept interceptors for "www.google.com:80" +74ms
  nock.intercept filtering interceptors for basepath http://www.google.com:80 +0ms
  nock.common options.host: www.google.com:80 +1ms
  nock.common options.hostname in the end: "www.google.com" +0ms
  nock.common options.host in the end: "www.google.com:80" +0ms
  nock.intercept interceptors for "www.google.com:80" +1ms
  nock.intercept filtering interceptors for basepath http://www.google.com:80 +1ms
  nock.intercept using 1 interceptors +0ms
  nock.request_overrider setHeader host www.google.com +0ms
  nock.request_overrider setHeader host www.google.com +2ms
  nock.request_overrider req.end +1ms
  nock.request_overrider write [Arguments] { '0': undefined, '1': undefined, '2': [Function] } +0ms
  nock.request_overrider ending +1ms
  nock.interceptor match {"_events":{},"_eventsCount":3,"uri":{"protocol":"http:","slashes":true,"auth":null,"host":"www.google.com","port":80,"hostname":"www.google.com","hash":null,"search":null,"query":null,"pathname":"/","path":"/","href":"http://www.google.com/"},..........

Update 2

150.151.144.119 is a proxy used by build agent. So it is a proxy issue. However I'm not sure how to fix it.

0

There are 0 answers