test: load the popup's libraries once per test file, not on every boot (closes #428)
Every popup boot in the tests resets jest's module registry so that src/ loads fresh, and that also reloaded ethers, libsodium-wrappers-sumo, qrcode and ethereum-blockies-base64 each time. tests/support/popupBoot.js now loads those four once per test file and registers them once with jest.doMock(), which jest.resetModules() keeps, so every boot gets the same copies. No test or assertion changed. make test takes 8-13s on the shared build host, down from 17-25s, measured in alternating runs before and after the change. Model: opus-5-5
This commit was merged in pull request #430.
This commit is contained in:
@@ -20,6 +20,26 @@ const path = require("path");
|
||||
|
||||
const { makeStorageStub } = require("./storageStub");
|
||||
|
||||
// The four libraries the popup loads from node_modules, loaded once per test
|
||||
// file and handed to every boot. jest.resetModules() in bootPopup() empties the
|
||||
// module cache but keeps what jest.doMock() registered, so these registrations
|
||||
// hold for every boot in the file and the libraries are not loaded again. None
|
||||
// of them holds popup state; everything under src/ is still loaded fresh on
|
||||
// each boot.
|
||||
//
|
||||
// A test's own mock of one of them: a jest.doMock() made inside the test
|
||||
// replaces the registration here, as it would for any module. A top-of-file
|
||||
// jest.mock() is what the require() below gets, so it is kept, but its factory
|
||||
// runs once per file and every boot shares the same mock object.
|
||||
const ethers = require("ethers");
|
||||
const sodium = require("libsodium-wrappers-sumo");
|
||||
const QRCode = require("qrcode");
|
||||
const makeBlockie = require("ethereum-blockies-base64");
|
||||
jest.doMock("ethers", () => ethers);
|
||||
jest.doMock("libsodium-wrappers-sumo", () => sodium);
|
||||
jest.doMock("qrcode", () => QRCode);
|
||||
jest.doMock("ethereum-blockies-base64", () => makeBlockie);
|
||||
|
||||
const POPUP_HTML = fs.readFileSync(
|
||||
path.join(__dirname, "..", "..", "src", "popup", "index.html"),
|
||||
"utf8",
|
||||
|
||||
Reference in New Issue
Block a user