Using "@warp-drive/holodeck": "0.0.4" when registering a mock that contains searchParams, e.g. /test?param=1, the requests to that URL result in MOCK_NOT_FOUND.
Looking at the node server implementation, I see that when registering the mock, the cache key is built with the url defined in the payload:
const { url, headers, method, status, statusText, body, response } = payload;
const cacheKey = generateFilepath({
projectRoot,
testId,
url,
method,
body,
testRequestNumber,
});
Later, when checking actual requests, the cache key is built using niceUrl:
const cacheKey = generateFilepath({
projectRoot,
testId,
url: niceUrl,
method: req.method,
body: body ? body : null,
testRequestNumber,
});
The problem is that getNiceUrl strips the ? between pathname and searchParams, so we get two different cache keys for register and retrieval.
I was able to fix this by keeping the ? when relevant, e.g.
export function getNiceUrl(url) {
const urlObj = new URL(url);
urlObj.searchParams.delete('__xTestId');
urlObj.searchParams.delete('__xTestRequestNumber');
let params = urlObj.searchParams.toString();
if (params) {
params = '?' + params;
}
return (urlObj.pathname + params).slice(1);
}
Using
"@warp-drive/holodeck": "0.0.4"when registering a mock that contains searchParams, e.g./test?param=1, the requests to that URL result inMOCK_NOT_FOUND.Looking at the node server implementation, I see that when registering the mock, the cache key is built with the
urldefined in the payload:Later, when checking actual requests, the cache key is built using
niceUrl:The problem is that
getNiceUrlstrips the?betweenpathnameandsearchParams, so we get two different cache keys for register and retrieval.I was able to fix this by keeping the
?when relevant, e.g.