interceptors
interceptors copied to clipboard
should call callback before response event
Node.js behaviour:
const http = require('http');
const req = http.get('http://nowhere.com/', res => {
console.log('response event');
})
req.on('finish', () => console.log('finish'))
req.end('', null, () => console.log('callback'))
This prints:
finish callback response event
Mocked behavior:
const { ClientRequestInterceptor } = require('@mswjs/interceptors/ClientRequest')
const http = require('http');
const interceptor = new ClientRequestInterceptor({
name: 'my-interceptor',
})
interceptor.apply();
interceptor.on('request', async ({request}) => {
request.respondWith(new Response())
});
const req = http.request('http://nowhere.com/', res => {
console.log('response event');
})
req.on('finish', () => console.log('finish'))
req.end('', null, () => console.log('callback'))
Prints:
finish response event callback
I can open a PR that pass the callback to the respondWIth
and put it after the finish event.
Hi, @mikicho. Can you please describe the expected behavior here? Is this the callback order that you find wrong? That seems to be correct (in your example). Are we not printing some of this? I suppose the .end()
callback never gets called for bypassed requests?
Sorry for the incomplete description. I have updated it.