1 Commits
Author SHA1 Message Date
sneak 6b5f205965 test: the popup boot in the jest suite sends no request to the internet (closes #559)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run
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 other test files
use, and cleanupPopup() puts it back. tests/popupBoot.test.js checks
that both requests reach the stub.

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