// Initialise `core` once, before any test file is required. // // Loaded via `node --test --require ./test/_setup.js`, the same arrangement // core's own suite uses. It exists because of the one structural difference // between testing this module and testing the code when it lived in core: // nothing here can be stubbed by monkey-patching a core module, because there // are no core modules to patch. `require('../utils/db')` does not exist. What a // test controls instead is the `ctx` core would have handed over — which is a // better seam anyway, since it is exactly the surface the contract promises and // nothing wider. // // The ctx installed here is deliberately NOT frozen. Core freezes what it hands // a module, and `entry.test.js` asserts the module behaves against a frozen one; // but a test that needs `settings.get` to return a particular value has to be // able to say so, and a frozen ctx would mean re-initialising core per test. The // mutable copy is a test seam, not a claim about what core does. const core = require('../core') const { fakeCtx } = require('./_fakes') const ctx = fakeCtx({ freeze: false }) core.init(ctx) // Exposed so a test can reach the same object it is running against, e.g. // `testCtx.settings.get = async () => '/srv/uo'`. There is one ctx per process, // as there is in core, so a test that changes a member should put it back. module.exports = { ctx }