{"version":3,"file":"text.cjs","sources":["../../../src/queries/text.ts"],"sourcesContent":["import {\n  buildQueries,\n  fuzzyMatches,\n  makeNormalizer,\n  matches,\n} from \"./all-utils\";\nimport type { TestInstance } from \"../types\";\nimport type {\n  GetErrorFunction,\n  Matcher,\n  SelectorMatcherOptions,\n} from \"./all-utils\";\nimport type { waitForOptions } from \"../wait-for\";\n\nexport type QueryByText<T extends TestInstance = TestInstance> = (\n  instance: TestInstance,\n  id: Matcher,\n  options?: SelectorMatcherOptions,\n) => T | null;\n\nexport type GetByText<T extends TestInstance = TestInstance> = (\n  instance: TestInstance,\n  id: Matcher,\n  options?: SelectorMatcherOptions,\n) => T;\n\nexport type FindByText<T extends TestInstance = TestInstance> = (\n  instance: TestInstance,\n  id: Matcher,\n  options?: SelectorMatcherOptions,\n  waitForElementOptions?: waitForOptions,\n) => Promise<T>;\n\nconst queryByTextBase: QueryByText = (\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.stdoutArr.map((output) => output.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 [_queryByTextWithSuggestions, _getByText, _findByText] = buildQueries(\n  queryByTextBase,\n  getMissingError,\n);\n\nexport function getByText<T extends TestInstance = TestInstance>(\n  ...args: Parameters<GetByText<T>>\n): ReturnType<GetByText<T>> {\n  return _getByText<T>(...args);\n}\nexport function queryByText<T extends TestInstance = TestInstance>(\n  ...args: Parameters<QueryByText<T>>\n): ReturnType<QueryByText<T>> {\n  return _queryByTextWithSuggestions<T>(...args);\n}\nexport function findByText<T extends TestInstance = TestInstance>(\n  ...args: Parameters<FindByText<T>>\n): ReturnType<FindByText<T>> {\n  return _findByText(...args);\n}\n"],"names":["matches","fuzzyMatches","makeNormalizer","buildQueries"],"mappings":";;;;AAiCA,MAAM,kBAA+B,CACnC,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,WAAW,OAAO,QAAQ,EAAE,KAAK,IAAI;AACzE,MAAI,QAAQ,KAAK,UAAU,MAAM,eAAe,EAAU,QAAA;AAAA,MAC9C,QAAA;AACd;AAEA,MAAM,kBAA+C,CAAC,IAAI,SACxD,gDAAgD,IAAI;AAEtD,MAAM,CAAC,6BAA6B,YAAY,WAAW,IAAIC,aAAA;AAAA,EAC7D;AAAA,EACA;AACF;AAEO,SAAS,aACX,MACuB;AACnB,SAAA,WAAc,GAAG,IAAI;AAC9B;AACO,SAAS,eACX,MACyB;AACrB,SAAA,4BAA+B,GAAG,IAAI;AAC/C;AACO,SAAS,cACX,MACwB;AACpB,SAAA,YAAY,GAAG,IAAI;AAC5B;;;;"}