1 Commits
Author SHA1 Message Date
sneak 871fa80234 test: the popup boot in the jest suite sends no request to the internet (closes #559)
check / check (push) Canceled after 0s
e2e / e2e-chrome (push) Canceled after 0s
e2e / e2e-firefox (push) Canceled after 0s
bootPopup() in tests/support/popupBoot.js mocked three of the modules
that reach the network, but a boot onto the transaction screen still
asked Blockscout for its transaction, and a boot onto the confirmation
screen had src/shared/etherscanLabels.js look the recipient up on
Etherscan, both through the real fetch().
tests/persistedFieldContract.test.js boots onto both, so every run sent
those requests and logged their answers after its tests had finished.
bootPopup() now replaces fetch() with the throwing stub the rest of the
suite uses, and cleanupPopup() puts it back. tests/popupBoot.test.js
checks that both requests reach the stub.

Model: opus-5-5
2026-10-19 05:58:42 +00:00
2 changed files with 8 additions and 12 deletions
+2 -2
View File
@@ -42,8 +42,8 @@ test("a flash message's timer does not fire after cleanupPopup()", async () => {
await wait(FLASH_MS * 5); await wait(FLASH_MS * 5);
}); });
// A boot onto a screen that sends a request no mocked module answers: that // A boot onto a screen whose requests no mocked module answers: they reach the
// request reaches the boot's fetch() stub, never the internet // boot's fetch() stub, never the internet
// (https://git.eeqj.de/sneak/AutistMask/issues/559). // (https://git.eeqj.de/sneak/AutistMask/issues/559).
function restoringOnto(view, viewData) { function restoringOnto(view, viewData) {
return unversionedValidProfile({ return unversionedValidProfile({
+6 -10
View File
@@ -261,14 +261,10 @@ async function settle() {
async function bootPopup(stored, options) { async function bootPopup(stored, options) {
jest.resetModules(); jest.resetModules();
// The RPC requests made through src/shared/balances.js go through Node's // Three of the modules that reach the network. None is on the path under
// own http and https modules, not fetch(), so the fetch() stub below would // test; all would make the suite hit the internet. Every other request,
// not stop them, which is why that module stays mocked. // such as the transaction screen's Blockscout lookup and the Etherscan
// src/shared/prices.js and src/shared/transactions.js send their requests // lookup in src/shared/etherscanLabels.js, meets the fetch() stub below.
// through fetch(), and their mocks answer with no prices and no
// transactions. Every request the page still sends, such as the
// transaction screen's Blockscout lookup and the Etherscan lookup in
// src/shared/etherscanLabels.js, meets the fetch() stub.
jest.doMock("../../src/shared/prices", () => ({ jest.doMock("../../src/shared/prices", () => ({
prices: {}, prices: {},
refreshPrices: jest.fn(async () => {}), refreshPrices: jest.fn(async () => {}),
@@ -342,8 +338,8 @@ async function bootPopup(stored, options) {
}, },
}; };
// Every fetch() the page makes fails, as it does elsewhere in the suite, // Every fetch() the page makes fails, as it does elsewhere in the suite,
// instead of reaching the internet. A new stub per boot, so the calls it // instead of reaching the internet. A new stub per boot, so its calls are
// records start with that boot. Put back by cleanupPopup(). // that boot's requests. Put back by cleanupPopup().
globalThis.fetch = jest.fn(() => { globalThis.fetch = jest.fn(() => {
throw new Error("tests must not perform network requests"); throw new Error("tests must not perform network requests");
}); });