-
-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Requests aren't intercepted anymore since 2.4.4 #2385
Comments
Noticed the same updating to 2.4.4 here https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/merge_requests/2188/diffs |
Hi, @dbanck. Thanks for the detailed report. I will take a look at this once I have a moment. |
DiscoveryThe first thing I noticed is that replacing const request = axios.create({
adapter: 'fetch',
})
request
.get('https://example.com/test') // OK! In fact, using the Root causeThe request is not intercepted because the reference to We have both Axios and Swapping the import/require order of |
Interestingly enough, when I inspect the That may explain why, despite being constructed, the // node_modules/axios/dist/node/axios.cjs
req = transport.request(options, function handleResponse(res) { One more detail,
This is troubling because calling this
Looking closer at the Moreover, that patch seems to disregard any custom options.agent = agent;
How to fix this?@dbanck, given |
Here's the entirety of the patched(url, options, callback) {
if (typeof url !== 'string' && !(url && url.searchParams)) {
callback = options;
options = url;
url = null;
}
if (typeof options === 'function') {
callback = options;
options = null;
}
options = options || {};
if (options.socketPath) {
return original.apply(null, arguments);
}
const originalAgent = options.agent;
if (originalAgent === true) {
throw new Error('Unexpected agent option: true');
}
const isHttps = originals.globalAgent.protocol === 'https:';
const optionsPatched = originalAgent instanceof agent_1.PacProxyAgent;
const config = params.getProxySupport();
const useProxySettings = !optionsPatched && (config === 'override' || config === 'fallback' || (config === 'on' && originalAgent === undefined));
const addCertificatesV1 = !optionsPatched && params.addCertificatesV1() && isHttps && !options.ca;
if (useProxySettings || addCertificatesV1) {
if (url) {
const parsed = typeof url === 'string' ? new nodeurl.URL(url) : url;
const urlOptions = {
protocol: parsed.protocol,
hostname: parsed.hostname.lastIndexOf('[', 0) === 0 ? parsed.hostname.slice(1, -1) : parsed.hostname,
port: parsed.port,
path: `${parsed.pathname}${parsed.search}`
};
if (parsed.username || parsed.password) {
options.auth = `${parsed.username}:${parsed.password}`;
}
options = Object.assign(Object.assign({}, urlOptions), options);
}
else {
options = Object.assign({}, options);
}
const resolveP = (req, opts, url) => new Promise(resolve => resolveProxy({ useProxySettings, addCertificatesV1 }, req, opts, url, resolve));
const host = options.hostname || options.host;
const isLocalhost = !host || host === 'localhost' || host === '127.0.0.1'; // Avoiding https://github.com/microsoft/vscode/issues/120354
const agent = (0, agent_1.default)(resolveP, {
originalAgent: (!useProxySettings || isLocalhost || config === 'fallback') ? originalAgent : undefined,
lookupProxyAuthorization: params.lookupProxyAuthorization,
});
agent.protocol = isHttps ? 'https:' : 'http:';
options.agent = agent;
return original(options, callback);
}
return original.apply(null, arguments);
} |
This wasn't an issue before because MSW's patch was more aggressive, overriding |
Prerequisites
Environment check
msw
versionNode.js version
v20.18.0
Background
Thanks for this great library. We've been using it for some time now to mock response in the vscode-terraform test suite.
During some regular dependency bumps we noticed that the mocking didn't work anymore.
Reproduction repository
https://github.com/dbanck/playground-vscode-msw-bug
Reproduction steps
Current behavior
The request isn't intercepted anymore
The request isn't captured by any of the life-cycle events that log to the extension debug channel
Axios logs a 404 error, because the request isn't mocked and a real request is sent to
https://example.com/test
Expected behavior
I have traced it back to this change: v2.4.3...v2.4.4
When I downgrade msw to 2.4.3 everything is working as expected.
The request is logged by the lifecycle events
And my mocked response is returned
The text was updated successfully, but these errors were encountered: