Urgent.News

What's breaking now, across thousands of outlets.

Tech

Setting an env var above your imports does not run before them, and our integration test works anyway

The largest test file in PubTrivia is 543 lines, and it has no mocks in it. It calls the actual server actions a player's phone calls, and the actual engine the host's buttons and our WebSocket server both call, against the actual Postgres database the app uses. That is a trade with real costs, which I will get to. First, the two lines at the top, because they taught me something about module…

The largest test file in PubTrivia, containing 543 lines, calls actual server actions, the engine, and the Postgres database against which it operates. This setup has real costs associated with it. The key insight came from the two lines placed above the imports that disable WebSocket notifications before importing modules that read them during execution.

Despite the belief that these lines would run before the imported modules, this is not the case in an ES module environment. Import declarations are hoisted, and all imported modules are fully evaluated before the first statement of the importing module runs. Consequently, the order of assignments and imports does not matter, and the test functions correctly for a different reason.

The code being disabled is an async function that notifies a WebSocket server with session ID, event, and payload. The function checks if the required variables are set before proceeding. However, when the variables are blanked before the imports, the function returns early with a warning, ensuring the test is the only one controlling the closing of a question.

This demonstrates the importance of understanding the evaluation order of modules in ES environments and the impact it can have on test results.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Debugging Service Workers in Firefox: DevTools, about:debugging, and Common Issues

Service workers are a critical web platform feature — they enable offline capabilities, push notifications, and background sync. Firefox has full service worker support.

  • Firefox provides comprehensive support for service workers with DevTools and about:debugging
  • Common Firefox service worker issues: incorrect scope, registration errors, and HTTPS requirements

about:config Settings Worth Changing (and What Not to Touch)

about:config is Firefox's advanced settings panel — a flat key-value store for hundreds of internal preferences. Most users never touch it.

  • DNS over HTTPS (Forced Mode) enhances privacy by routing DNS queries through a trusted resolver
  • Sanitize History on Shutdown clears cookies and history when Firefox closes for enhanced privacy

More from Friday 16 October →