console-fail-test
Version:
Gently fails test runs if the console was used during them. 📢
1 lines • 2.02 kB
Source Map (JSON)
{"version":3,"sources":["../../src/spies/jest.ts"],"sourcesContent":["import { SpyCallArgs, SpyFactory, SpyFactoryGetter } from \"./spyTypes.js\";\n\ndeclare interface Jest {\n\tfn(implementation: Function): void;\n}\n\ndeclare const jest: Jest | undefined;\n\nconst isJestModule = (spyLibrary: unknown): spyLibrary is Jest => {\n\treturn (\n\t\ttypeof spyLibrary === \"object\" &&\n\t\ttypeof (spyLibrary as Partial<Jest>).fn === \"function\"\n\t);\n};\n\nconst createJestSpyFactory = (spyLibrary: Jest): SpyFactory => {\n\treturn (container: any, methodName: string) => {\n\t\tconst methodCalls: SpyCallArgs[] = [];\n\t\tconst originalMethod = container[methodName];\n\n\t\tconst methodSpy = function (this: unknown, ...args: SpyCallArgs) {\n\t\t\tmethodCalls.push(args);\n\t\t\treturn originalMethod.apply(this, args);\n\t\t};\n\n\t\tcontainer[methodName] = spyLibrary.fn(methodSpy);\n\n\t\treturn {\n\t\t\tgetCalls: () => methodCalls,\n\t\t\trestore: () => {\n\t\t\t\tcontainer[methodName] = originalMethod;\n\t\t\t},\n\t\t};\n\t};\n};\n\nexport const selectJestSpyFactory: SpyFactoryGetter = ({ spyLibrary }) => {\n\tif (isJestModule(spyLibrary)) {\n\t\treturn createJestSpyFactory(spyLibrary);\n\t}\n\n\tif (typeof jest !== \"undefined\" && isJestModule(jest)) {\n\t\treturn createJestSpyFactory(jest);\n\t}\n\n\treturn undefined;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,MAAM,eAAe,CAAC,eAA4C;AACjE,SACC,OAAO,eAAe,YACtB,OAAQ,WAA6B,OAAO;AAE9C;AAEA,MAAM,uBAAuB,CAAC,eAAiC;AAC9D,SAAO,CAAC,WAAgB,eAAuB;AAC9C,UAAM,cAA6B,CAAC;AACpC,UAAM,iBAAiB,UAAU,UAAU;AAE3C,UAAM,YAAY,YAA4B,MAAmB;AAChE,kBAAY,KAAK,IAAI;AACrB,aAAO,eAAe,MAAM,MAAM,IAAI;AAAA,IACvC;AAEA,cAAU,UAAU,IAAI,WAAW,GAAG,SAAS;AAE/C,WAAO;AAAA,MACN,UAAU,MAAM;AAAA,MAChB,SAAS,MAAM;AACd,kBAAU,UAAU,IAAI;AAAA,MACzB;AAAA,IACD;AAAA,EACD;AACD;AAEO,MAAM,uBAAyC,CAAC,EAAE,WAAW,MAAM;AACzE,MAAI,aAAa,UAAU,GAAG;AAC7B,WAAO,qBAAqB,UAAU;AAAA,EACvC;AAEA,MAAI,OAAO,SAAS,eAAe,aAAa,IAAI,GAAG;AACtD,WAAO,qBAAqB,IAAI;AAAA,EACjC;AAEA,SAAO;AACR;","names":[]}