UNPKG

console-fail-test

Version:

Gently fails test runs if the console was used during them. 📢

47 lines • 1.54 kB
import { selectFallbackSpyFactory } from "./fallback.js"; import { selectJasmineSpyFactory } from "./jasmine.js"; import { selectJestSpyFactory } from "./jest.js"; import { selectSinonSpyFactory } from "./sinon.js"; import { selectVitestSpyFactory } from "./vitest.js"; const spyFactoriesByName = /* @__PURE__ */ new Map([ ["fallback", selectFallbackSpyFactory], ["jasmine", selectJasmineSpyFactory], ["jest", selectJestSpyFactory], ["sinon", selectSinonSpyFactory], ["vitest", selectVitestSpyFactory] ]); const detectableSpyFactorySelectors = [ selectVitestSpyFactory, // Jest should come before Jasmine because Jest includes a monkey-patched Jasmine selectJestSpyFactory, selectJasmineSpyFactory, selectSinonSpyFactory ]; const selectSpyFactory = (request) => { if (typeof request.spyLibrary === "string") { const getter = spyFactoriesByName.get(request.spyLibrary); if (getter === void 0) { throw new Error( `Requested spy library '${request.spyLibrary}' not known by name in console-fail-test.` ); } const library = getter(request); if (library === void 0) { throw new Error( `Requested spy library '${request.spyLibrary}' does not seem to be active.` ); } return library; } for (const getter of detectableSpyFactorySelectors) { const library = getter(request); if (library !== void 0) { return library; } } return selectFallbackSpyFactory(); }; export { selectSpyFactory }; //# sourceMappingURL=selectSpyFactory.js.map