undici icon indicating copy to clipboard operation
undici copied to clipboard

`MockAgent`: `MockResponseCallbackOptions` given to `replyOptionsCallback` is a totally wrong type

Open jonahsnider opened this issue 3 years ago • 5 comments

Bug Description

Reproducible By

import * as undici from 'undici';

const mockAgent = new undici.MockAgent();
mockAgent.disableNetConnect();
undici.setGlobalDispatcher(mockAgent);

const mockPool = mockAgent.get('https://example.com');

mockPool
  .intercept({
    path: '/',
  })
  .reply((request) => {
    console.log(request);

    return { statusCode: 200 };
  });

await undici.request('https://example.com/', {
  headers: {
    authorization: 'Bearer 123',
  },
});

Expected Behavior

The types should be correct.

Logs & Screenshots

Actual value:

{
  headers: { authorization: 'Bearer 123' },
  origin: 'https://example.com',
  path: '/',
  method: 'GET'
}

Expected value:

https://github.com/nodejs/undici/blob/1822ee6eea459bb7432996064144c394d27ee03f/types/mock-interceptor.d.ts#L26

https://github.com/nodejs/undici/blob/1822ee6eea459bb7432996064144c394d27ee03f/types/mock-interceptor.d.ts#L85-L87

https://github.com/nodejs/undici/blob/1822ee6eea459bb7432996064144c394d27ee03f/types/mock-interceptor.d.ts#L72-L79

Environment

Darwin 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000 arm64

{
  node: '16.15.1',
  v8: '9.4.146.24-node.21',
  uv: '1.43.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.18.1',
  modules: '93',
  nghttp2: '1.47.0',
  napi: '8',
  llhttp: '6.0.4',
  openssl: '1.1.1o+quic',
  cldr: '40.0',
  icu: '70.1',
  tz: '2021a3',
  unicode: '14.0',
  ngtcp2: '0.1.0-DEV',
  nghttp3: '0.1.0-DEV'
}

Additional context

jonahsnider avatar Jul 28 '22 10:07 jonahsnider

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

mcollina avatar Jul 29 '22 07:07 mcollina

@mcollina if you want I can take this issue?

sidwebworks avatar Aug 26 '22 08:08 sidwebworks

go for it!

mcollina avatar Aug 26 '22 08:08 mcollina