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

Previously we were maintaining the same pretender instance throughout an entire test run. That meant that we would store many hundreds/thousands of objects in the handledRequests array.

This commit ensures a fresh pretender instance is used for each test, thereby reducing the memory usage during test runs.

The leaking objects showed as FakeRequest instances in the chrome memory inspector, and could be viewed in the console by running

> require("discourse/tests/helpers/create-pretender").default().handledRequests
// (10) [FakeRequest, FakeRequest, FakeRequest, FakeRequest, FakeRequest, FakeRequest, FakeRequest, FakeRequest, FakeRequest, FakeRequest]

GitHub

Looks like lots of core/plugin tests are doing something like this:

import pretender from "discourse/tests/helpers/create-pretender";

Which relies on there being a single pretender instance :cry:

The title of this pull request changed from “DEV: Create new pretender instance for each test run” to "DEV: Clear pretender request log between test runs

import pretender

We definitely want to get away from this! I thought I’d removed them all from core already, but I guess not!

It looks to me like they were removed from acceptance tests, but they remain in component tests, and a few other places.

I updated my PR to keep the same pretender instance, and simply reset the internal state.