DEV: Clear pretender request log between test runs (#14456)

Previously we would store every FakeRequest object for all tests, resulting in many hundreds/thousands of objects in the `handledRequests` array.

This commit ensures all pretender state is reset between tests.
This commit is contained in:
David Taylor 2021-09-29 14:43:55 +01:00 committed by GitHub
parent b609f6c11c
commit 928f102516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -1111,3 +1111,10 @@ export function applyDefaultHandlers(pretender) {
});
});
}
export function resetPretender() {
instance.handlers = [];
instance.handledRequests = [];
instance.unhandledRequests = [];
instance.passthroughRequests = [];
}

View File

@ -3,9 +3,10 @@ import {
exists,
resetSite,
} from "discourse/tests/helpers/qunit-helpers";
import createPretender, {
import pretender, {
applyDefaultHandlers,
pretenderHelpers,
resetPretender,
} from "discourse/tests/helpers/create-pretender";
import {
currentSettings,
@ -244,8 +245,7 @@ function setupTestsCommon(application, container, config) {
setupS3CDN(null, null);
}
server = createPretender;
server.handlers = [];
server = pretender;
applyDefaultHandlers(server);
server.prepareBody = function (body) {
@ -307,6 +307,7 @@ function setupTestsCommon(application, container, config) {
QUnit.testDone(function () {
sinon.restore();
resetPretender();
// Destroy any modals
$(".modal-backdrop").remove();