console-fail-test
Version:
Gently fails test runs if the console was used during them. 📢
1 lines • 2.77 kB
Source Map (JSON)
{"version":3,"sources":["../../src/spies/selectSpyFactory.ts"],"sourcesContent":["import { CftRequest, SupportedSpyLibrary } from \"../types.js\";\nimport { selectFallbackSpyFactory } from \"./fallback.js\";\nimport { selectJasmineSpyFactory } from \"./jasmine.js\";\nimport { selectJestSpyFactory } from \"./jest.js\";\nimport { selectSinonSpyFactory } from \"./sinon.js\";\nimport { SpyFactoryGetter as SpyFactorySelector } from \"./spyTypes.js\";\nimport { selectVitestSpyFactory } from \"./vitest.js\";\n\nconst spyFactoriesByName = new Map<SupportedSpyLibrary, SpyFactorySelector>([\n\t[\"fallback\", selectFallbackSpyFactory],\n\t[\"jasmine\", selectJasmineSpyFactory],\n\t[\"jest\", selectJestSpyFactory],\n\t[\"sinon\", selectSinonSpyFactory],\n\t[\"vitest\", selectVitestSpyFactory],\n]);\n\nconst detectableSpyFactorySelectors: SpyFactorySelector[] = [\n\tselectVitestSpyFactory,\n\n\t// Jest should come before Jasmine because Jest includes a monkey-patched Jasmine\n\tselectJestSpyFactory,\n\tselectJasmineSpyFactory,\n\n\tselectSinonSpyFactory,\n];\n\nexport const selectSpyFactory = (request: CftRequest) => {\n\t// If a spy library is requested by name, it must exist\n\tif (typeof request.spyLibrary === \"string\") {\n\t\tconst getter = spyFactoriesByName.get(request.spyLibrary);\n\t\tif (getter === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`Requested spy library '${request.spyLibrary}' not known by name in console-fail-test.`,\n\t\t\t);\n\t\t}\n\n\t\tconst library = getter(request);\n\t\tif (library === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`Requested spy library '${request.spyLibrary}' does not seem to be active.`,\n\t\t\t);\n\t\t}\n\n\t\treturn library;\n\t}\n\n\t// Otherwise, attempt to auto-detect an active one\n\tfor (const getter of detectableSpyFactorySelectors) {\n\t\tconst library = getter(request);\n\n\t\tif (library !== undefined) {\n\t\t\treturn library;\n\t\t}\n\t}\n\n\treturn selectFallbackSpyFactory();\n};\n"],"mappings":"AACA,SAAS,gCAAgC;AACzC,SAAS,+BAA+B;AACxC,SAAS,4BAA4B;AACrC,SAAS,6BAA6B;AAEtC,SAAS,8BAA8B;AAEvC,MAAM,qBAAqB,oBAAI,IAA6C;AAAA,EAC3E,CAAC,YAAY,wBAAwB;AAAA,EACrC,CAAC,WAAW,uBAAuB;AAAA,EACnC,CAAC,QAAQ,oBAAoB;AAAA,EAC7B,CAAC,SAAS,qBAAqB;AAAA,EAC/B,CAAC,UAAU,sBAAsB;AAClC,CAAC;AAED,MAAM,gCAAsD;AAAA,EAC3D;AAAA;AAAA,EAGA;AAAA,EACA;AAAA,EAEA;AACD;AAEO,MAAM,mBAAmB,CAAC,YAAwB;AAExD,MAAI,OAAO,QAAQ,eAAe,UAAU;AAC3C,UAAM,SAAS,mBAAmB,IAAI,QAAQ,UAAU;AACxD,QAAI,WAAW,QAAW;AACzB,YAAM,IAAI;AAAA,QACT,0BAA0B,QAAQ,UAAU;AAAA,MAC7C;AAAA,IACD;AAEA,UAAM,UAAU,OAAO,OAAO;AAC9B,QAAI,YAAY,QAAW;AAC1B,YAAM,IAAI;AAAA,QACT,0BAA0B,QAAQ,UAAU;AAAA,MAC7C;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAGA,aAAW,UAAU,+BAA+B;AACnD,UAAM,UAAU,OAAO,OAAO;AAE9B,QAAI,YAAY,QAAW;AAC1B,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO,yBAAyB;AACjC;","names":[]}