{"version":3,"file":"matchers-D4tmF3wI.mjs","names":[],"sources":["../src/matchers/utils.ts","../src/matchers/to-be-in-the-console.ts","../src/matchers/to-have-errormessage.ts","../src/matchers/index.ts"],"sourcesContent":["import redent from \"redent\";\nimport type { TestInstance } from \"../types\";\n\nclass GenericTypeError extends Error {\n  constructor(\n    expectedString: string,\n    received: any,\n    // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n    matcherFn: Function,\n    context: any,\n  ) {\n    super();\n\n    /* istanbul ignore next */\n    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n    if (Error.captureStackTrace) {\n      Error.captureStackTrace(this, matcherFn);\n    }\n    let withType = \"\";\n    try {\n      withType = context.utils.printWithType(\n        \"Received\",\n        received,\n        context.utils.printReceived,\n      );\n    } catch (e) {\n      // Can throw for Document:\n      // https://github.com/jsdom/jsdom/issues/2304\n    }\n    this.message = [\n      context.utils.matcherHint(\n        `${context.isNot ? \".not\" : \"\"}.${matcherFn.name}`,\n        \"received\",\n        \"\",\n      ),\n      \"\",\n\n      `${context.utils.RECEIVED_COLOR(\n        \"received\",\n      )} value must ${expectedString}.`,\n      withType,\n    ].join(\"\\n\");\n  }\n}\n\ntype GenericTypeErrorArgs = ConstructorParameters<typeof GenericTypeError>;\n\ntype AllButFirst<T> = T extends [infer _First, ...infer Rest] ? Rest : never;\n\nclass CliInstanceTypeError extends GenericTypeError {\n  constructor(...args: AllButFirst<GenericTypeErrorArgs>) {\n    super(\"be a TestInstance\", ...args);\n  }\n}\n\ntype CliInstanceTypeErrorArgs = ConstructorParameters<\n  typeof CliInstanceTypeError\n>;\n\nfunction checkCliInstance(\n  cliInstance: TestInstance,\n  ...args: AllButFirst<CliInstanceTypeErrorArgs>\n) {\n  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n  if (!(cliInstance && cliInstance.process && cliInstance.process.stdout)) {\n    throw new CliInstanceTypeError(cliInstance, ...args);\n  }\n}\n\nfunction display(context: any, value: any) {\n  return typeof value === \"string\" ? value : context.utils.stringify(value);\n}\n\nfunction getMessage(\n  context: any,\n  matcher: string,\n  expectedLabel: string,\n  expectedValue: string,\n  receivedLabel: string,\n  receivedValue: string,\n) {\n  return [\n    `${matcher}\\n`,\n    `${expectedLabel}:\\n${context.utils.EXPECTED_COLOR(\n      redent(display(context, expectedValue), 2),\n    )}`,\n    `${receivedLabel}:\\n${context.utils.RECEIVED_COLOR(\n      redent(display(context, receivedValue), 2),\n    )}`,\n  ].join(\"\\n\");\n}\n\nexport { CliInstanceTypeError, checkCliInstance, getMessage };\n","import { getDefaultNormalizer } from \"../matches\";\nimport { checkCliInstance, getMessage } from \"./utils\";\nimport type { TestInstance } from \"../types\";\n\nexport function toBeInTheConsole(this: any, instance: TestInstance) {\n  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n  if (instance !== null || !this.isNot) {\n    checkCliInstance(instance, toBeInTheConsole, this);\n  }\n\n  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n  const errormessage = instance\n    ? getDefaultNormalizer()(\n        instance.stdoutArr.map((obj) => obj.contents).join(\"\\n\"),\n      )\n    : null;\n\n  return {\n    // Does not change based on `.not`, and as a result, we must confirm if it _actually_ is there\n    pass: !!instance,\n    message: () => {\n      const to = this.isNot ? \"not to\" : \"to\";\n      return getMessage(\n        this,\n        this.utils.matcherHint(\n          `${this.isNot ? \".not\" : \"\"}.toBeInTheConsole`,\n          \"instance\",\n          \"\",\n        ),\n        `Expected ${to} find the instance in the console`,\n        \"\",\n        \"Received\",\n        this.utils.printReceived(errormessage),\n      );\n    },\n  };\n}\n","import { getDefaultNormalizer } from \"../matches\";\nimport { checkCliInstance, getMessage } from \"./utils\";\nimport type { TestInstance } from \"../types\";\n\nexport function toHaveErrorMessage(\n  this: any,\n  testInstance: TestInstance,\n  checkWith?: string | RegExp,\n) {\n  checkCliInstance(testInstance, toHaveErrorMessage, this);\n\n  const expectsErrorMessage = checkWith !== undefined;\n\n  const errormessage = getDefaultNormalizer()(\n    testInstance.stderrArr.map((obj) => obj.contents).join(\"\\n\"),\n  );\n\n  return {\n    pass: expectsErrorMessage\n      ? checkWith instanceof RegExp\n        ? checkWith.test(errormessage)\n        : this.equals(errormessage, checkWith)\n      : Boolean(testInstance.stderrArr.length),\n    message: () => {\n      const to = this.isNot ? \"not to\" : \"to\";\n      return getMessage(\n        this,\n        this.utils.matcherHint(\n          `${this.isNot ? \".not\" : \"\"}.toHaveErrorMessage`,\n          \"instance\",\n          \"\",\n        ),\n        `Expected the instance ${to} have error message`,\n        this.utils.printExpected(checkWith),\n        \"Received\",\n        this.utils.printReceived(errormessage),\n      );\n    },\n  };\n}\n","import { toBeInTheConsole } from \"./to-be-in-the-console\";\nimport { toHaveErrorMessage } from \"./to-have-errormessage\";\n\nexport { toBeInTheConsole, toHaveErrorMessage };\n"],"mappings":";;;;AAGA,IAAM,mBAAN,cAA+B,MAAM;CACnC,YACE,gBACA,UAEA,WACA,SACA;EACA,MAAM;;EAIN,IAAI,MAAM,mBACR,MAAM,kBAAkB,MAAM,SAAS;EAEzC,IAAI,WAAW;EACf,IAAI;GACF,WAAW,QAAQ,MAAM,cACvB,YACA,UACA,QAAQ,MAAM,aAChB;EACF,SAAS,GAAG,CAGZ;EACA,KAAK,UAAU;GACb,QAAQ,MAAM,YACZ,GAAG,QAAQ,QAAQ,SAAS,GAAG,GAAG,UAAU,QAC5C,YACA,EACF;GACA;GAEA,GAAG,QAAQ,MAAM,eACf,UACF,EAAE,cAAc,eAAe;GAC/B;EACF,CAAC,CAAC,KAAK,IAAI;CACb;AACF;AAMA,IAAM,uBAAN,cAAmC,iBAAiB;CAClD,YAAY,GAAG,MAAyC;EACtD,MAAM,qBAAqB,GAAG,IAAI;CACpC;AACF;AAMA,SAAS,iBACP,aACA,GAAG,MACH;CAEA,IAAI,EAAE,eAAe,YAAY,WAAW,YAAY,QAAQ,SAC9D,MAAM,IAAI,qBAAqB,aAAa,GAAG,IAAI;AAEvD;AAEA,SAAS,QAAQ,SAAc,OAAY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