test: load the popup's libraries once per test file, not on every boot (closes #428)
check / check (push) Failing after 1s
e2e / e2e-chrome (push) Failing after 1s
e2e / e2e-firefox (push) Failing after 1s

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: more than half of a boot, and
tests/persistedFieldContract.test.js boots the popup 321 times.
tests/support/popupBoot.js now loads those four once per test file and hands
the same copies to every boot. No test or assertion changed. make test takes
10-15s on the shared build host instead of 23-29s.

Model: opus-5-5
This commit is contained in:
2026-10-04 12:39:56 +00:00
parent 43c236451f
commit 7949c73afd
3 changed files with 31 additions and 6 deletions
+16
View File
@@ -20,6 +20,17 @@ 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() would
// otherwise load them again on every boot, which was more than half of what a
// boot cost. None of them holds popup state; everything under src/ is still
// loaded fresh on each boot. A test that mocks one of these itself has its mock
// replaced by bootPopup().
const ethers = require("ethers");
const sodium = require("libsodium-wrappers-sumo");
const QRCode = require("qrcode");
const makeBlockie = require("ethereum-blockies-base64");
const POPUP_HTML = fs.readFileSync(
path.join(__dirname, "..", "..", "src", "popup", "index.html"),
"utf8",
@@ -219,6 +230,11 @@ async function settle() {
async function bootPopup(stored, options) {
jest.resetModules();
jest.doMock("ethers", () => ethers);
jest.doMock("libsodium-wrappers-sumo", () => sodium);
jest.doMock("qrcode", () => QRCode);
jest.doMock("ethereum-blockies-base64", () => makeBlockie);
// The three modules that reach the network. None is on the path under
// test; all would make the suite hit the internet.
jest.doMock("../../src/shared/prices", () => ({