cli-testing-library
Version:
Simple and complete CLI testing utilities that encourage good testing practices.
1 lines • 3.12 kB
Source Map (JSON)
{"version":3,"file":"error.cjs","sources":["../../../src/queries/error.ts"],"sourcesContent":["import {\n buildQueries,\n fuzzyMatches,\n makeNormalizer,\n matches,\n} from \"./all-utils\";\nimport type {\n GetErrorFunction,\n Matcher,\n SelectorMatcherOptions,\n} from \"./all-utils\";\nimport type { TestInstance } from \"../types\";\nimport type { waitForOptions } from \"../wait-for\";\n\nexport type QueryByError<T extends TestInstance = TestInstance> = (\n instance: TestInstance,\n id: Matcher,\n options?: SelectorMatcherOptions,\n) => T | null;\n\nexport type GetByError<T extends TestInstance = TestInstance> = (\n instance: TestInstance,\n id: Matcher,\n options?: SelectorMatcherOptions,\n) => T;\n\nexport type FindByError<T extends TestInstance = TestInstance> = (\n instance: TestInstance,\n id: Matcher,\n options?: SelectorMatcherOptions,\n waitForElementOptions?: waitForOptions,\n) => Promise<T>;\n\nconst queryByErrorBase: QueryByError = (\n instance,\n text,\n { exact = false, collapseWhitespace, trim, normalizer, stripAnsi } = {},\n) => {\n const matcher = exact ? matches : fuzzyMatches;\n const matchNormalizer = makeNormalizer({\n stripAnsi,\n collapseWhitespace,\n trim,\n normalizer,\n });\n const str = instance.stderrArr.map((obj) => obj.contents).join(\"\\n\");\n if (matcher(str, instance, text, matchNormalizer)) return instance;\n else return null;\n};\n\nconst getMissingError: GetErrorFunction<[unknown]> = (_c, text) =>\n `Unable to find an stdout line with the text: ${text}. This could be because the text is broken up by multiple lines. In this case, you can provide a function for your text matcher to make your matcher more flexible.`;\n\nconst [_queryByErrorWithSuggestions, _getByError, _findByError] = buildQueries(\n queryByErrorBase,\n getMissingError,\n);\n\nexport function getByError<T extends TestInstance = TestInstance>(\n ...args: Parameters<GetByError<T>>\n): ReturnType<GetByError<T>> {\n return _getByError<T>(...args);\n}\n\nexport function queryByError<T extends TestInstance = TestInstance>(\n ...args: Parameters<QueryByError<T>>\n): ReturnType<QueryByError<T>> {\n return _queryByErrorWithSuggestions<T>(...args);\n}\n\nexport function findByError<T extends TestInstance = TestInstance>(\n ...args: Parameters<FindByError<T>>\n): ReturnType<FindByError<T>> {\n return _findByError<T>(...args);\n}\n"],"names":["matches","fuzzyMatches","makeNormalizer","buildQueries"],"mappings":";;;;AAiCA,MAAM,mBAAiC,CACrC,UACA,MACA,EAAE,QAAQ,OAAO,oBAAoB,MAAM,YAAY,UAAU,IAAI,CAAA,MAClE;AACG,QAAA,UAAU,QAAQA,QAAAA,UAAUC,QAAA;AAClC,QAAM,kBAAkBC,QAAAA,eAAe;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AACK,QAAA,MAAM,SAAS,UAAU,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE,KAAK,IAAI;AACnE,MAAI,QAAQ,KAAK,UAAU,MAAM,eAAe,EAAU,QAAA;AAAA,MAC9C,QAAA;AACd;AAEA,MAAM,kBAA+C,CAAC,IAAI,SACxD,gDAAgD,IAAI;AAEtD,MAAM,CAAC,8BAA8B,aAAa,YAAY,IAAIC,aAAA;AAAA,EAChE;AAAA,EACA;AACF;AAEO,SAAS,cACX,MACwB;AACpB,SAAA,YAAe,GAAG,IAAI;AAC/B;AAEO,SAAS,gBACX,MAC0B;AACtB,SAAA,6BAAgC,GAAG,IAAI;AAChD;AAEO,SAAS,eACX,MACyB;AACrB,SAAA,aAAgB,GAAG,IAAI;AAChC;;;;"}