{"version":3,"file":"utils.cjs","sources":["../../../src/matchers/utils.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"],"names":[],"mappings":";;;AAGA,MAAM,yBAAyB,MAAM;AAAA,EACnC,YACE,gBACA,UAEA,WACA,SACA;AACM,UAAA;AAIN,QAAI,MAAM,mBAAmB;AACrB,YAAA,kBAAkB,MAAM,SAAS;AAAA,IAAA;AAEzC,QAAI,WAAW;AACX,QAAA;AACF,iBAAW,QAAQ,MAAM;AAAA,QACvB;AAAA,QACA;AAAA,QACA,QAAQ,MAAM;AAAA,MAChB;AAAA,aACO,GAAG;AAAA,IAAA;AAIZ,SAAK,UAAU;AAAA,MACb,QAAQ,MAAM;AAAA,QACZ,GAAG,QAAQ,QAAQ,SAAS,EAAE,IAAI,UAAU,IAAI;AAAA,QAChD;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,MAEA,GAAG,QAAQ,MAAM;AAAA,QACf;AAAA,MAAA,CACD,eAAe,cAAc;AAAA,MAC9B;AAAA,IAAA,EACA,KAAK,IAAI;AAAA,EAAA;AAEf;AAMA,MAAM,6BAA6B,iBAAiB;AAAA,EAClD,eAAe,MAAyC;AAChD,UAAA,qBAAqB,GAAG,IAAI;AAAA,EAAA;AAEtC;AAMA,SAAS,iBACP,gBACG,MACH;AAEA,MAAI,EAAE,eAAe,YAAY,WAAW,YAAY,QAAQ,SAAS;AACvE,UAAM,IAAI,qBAAqB,aAAa,GAAG,IAAI;AAAA,EAAA;AAEvD;AAEA,SAAS,QAAQ,SAAc,OAAY;AACzC,SAAO,OAAO,UAAU,WAAW,QAAQ,QAAQ,MAAM,UAAU,KAAK;AAC1E;AAEA,SAAS,WACP,SACA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