{"version":3,"file":"logger-core.cjs","sources":["../../../src/logger/logger-core.js"],"sourcesContent":["import * as colors from 'colors/safe.js';\nimport { printErrorDetails } from './print-error-details.js';\n\n// Helper function to safely serialize errors for worker thread communication\nfunction serializeErrorSafely(error) {\n  if (!error) return null;\n  \n  // Create a clean error object without function references\n  const cleanError = {\n    message: error.message || String(error),\n    name: error.name || 'Error',\n    stack: error.stack || null,\n    matcherName: error.matcherName || null,\n    isNot: error.isNot || false\n  };\n  \n  // Safely serialize expected and actual values, removing function objects\n  if (error.expected !== undefined) {\n    cleanError.expected = serializeValueSafely(error.expected);\n  }\n  \n  if (error.actual !== undefined) {\n    cleanError.actual = serializeValueSafely(error.actual);\n  }\n  \n  return cleanError;\n}\n\n/**\n * Recursively serializes values for safe logging by converting functions to '[Function]' strings\n * while preserving the structure of objects and arrays\n * @param {*} value - The value to serialize (any type)\n * @returns {any} - Serialized value where:\n *  Functions become '[Function]' string\n *  Objects become new objects with recursively serialized properties  \n *  Arrays become new arrays with recursively serialized elements\n *  Primitives (string, number, boolean) and null/undefined are returned as-is\n */\nfunction serializeValueSafely(value) {\n  if (value === null || value === undefined) {\n    return value;\n  }\n  if (typeof value === 'function') {\n    return '[Function]';\n  }\n  if (Array.isArray(value)) {\n    return value.map(serializeValueSafely);\n  }\n  if (typeof value === 'object') {\n    const cleanObject = {};\n    for (const [key, val] of Object.entries(value)) {\n      cleanObject[key] = serializeValueSafely(val);\n    }\n    return cleanObject;\n  }\n  return value;\n}\n\nclass Logger {\n  constructor({ stdout = process.stdout, stderr = process.stderr } = {}) {\n    this.total = 0;\n    this.passed = 0;\n    this.failed = 0;\n    this.skipped = 0;\n    this.testResults = [];\n    this.suiteStack = [];\n    this.startTime = null;\n    this.endTime = null;\n    this.lastError = null;\n    this.slowThreshold = 500; // ms\n    this.stdout = stdout;\n    this.stderr = stderr;\n  }\n\n  startTimer() {\n    this.startTime = Date.now();\n  }\n\n  endTimer() {\n    this.endTime = Date.now();\n  }\n\n  perceive(context, msg, annotations) {\n    if (context === 'describe') {\n      // Suppress printing of the 'root' suite\n      if (msg === 'root') return;\n      this.suiteStack.push(msg);\n      this.stdout.write(colors.bold('\\n' + msg) + '\\n');\n    } else if (context === 'test') {\n      const startTime = Date.now();\n      this.currentTest = { \n        name: msg, \n        suite: [...this.suiteStack], \n        status: null, \n        error: null, \n        duration: 0, \n        skipped: false,\n        startTime: startTime\n      };\n    }\n  }\n\n  status(result, error = null, skipped = false) {\n    this.total++;\n    if (this.currentTest) {\n      const endTime = Date.now();\n      this.currentTest.endTime = endTime;\n      this.currentTest.duration = endTime - this.currentTest.startTime;\n      this.currentTest.skipped = skipped;\n      const testName = this.currentTest.name;\n      if (skipped) {\n        this.skipped++;\n        this.currentTest.status = 'skipped';\n        this.stdout.write('  ' + colors.yellow('- SKIPPED') + ' ' + testName + '\\n');\n      } else if (result) {\n        this.passed++;\n        this.currentTest.status = 'passed';\n        let slow = this.currentTest.duration > this.slowThreshold;\n        let slowMsg = slow ? colors.yellow(' (SLOW)') : '';\n        this.stdout.write('  ' + colors.green('✓') + ' ' + testName + slowMsg + '\\n');\n      } else {\n        // When result is false (test failed), mark as failed\n        this.failed++;\n        this.currentTest.status = 'failed';\n        this.currentTest.error = error;\n        this.stdout.write('  ' + colors.red('✗') + ' ' + testName + '\\n');\n        // Print error details immediately after the test status\n        printErrorDetails(error, this.stdout);\n      }\n      this.testResults.push(this.currentTest);\n      this.currentTest = null;\n    }\n  }\n\n  error(message) {\n    this.lastError = message;\n    this.stderr.write(colors.red(message) + '\\n');\n  }\n\n  getStats() {\n    return {\n      total: this.total,\n      passed: this.passed,\n      failed: this.failed,\n      skipped: this.skipped\n    };\n  }\n\n  getResultsJSON() {\n    return {\n      stats: this.getStats(),\n      duration: this.endTime && this.startTime ? (this.endTime - this.startTime) : 0,\n      tests: this.testResults.map(r => ({\n        name: r.name,\n        suite: r.suite,\n        status: r.status,\n        error: serializeErrorSafely(r.error),\n        duration: r.duration,\n        startTime: r.startTime,\n        endTime: r.endTime,\n        annotations: r.annotations || {},\n      }))\n    };\n  }\n\n  // This method is now only called from test-execution.js for the final summary\n  printSummary() {\n    if (!this.endTime && this.startTime) {\n      this.endTimer();\n    }\n    \n    const duration = this.endTime && this.startTime ? (this.endTime - this.startTime) : 0;\n    \n    if (this.testResults.length === 0) {\n      return;\n    }\n    \n    // Use suite counts if available (from test-execution.js), otherwise fall back to test counts\n    const totalSuites = this.totalSuites || this.total;\n    const passedSuites = this.passedSuites || this.passed;\n    const failedSuites = this.failedSuites || this.failed;\n    \n    this.stdout.write(\n      colors.bold('\\n\\n Test Suites: ') + \n      `${failedSuites > 0 ? colors.red(failedSuites + ' failed') : colors.green(passedSuites + ' passed')} | ${totalSuites} total` + '\\n'\n    );\n    this.stdout.write(\n      colors.bold(' Tests:       ') + \n      `${colors.green(this.passed + ' passed')}, ${colors.red(this.failed + ' failed')}, ${colors.yellow(this.skipped + ' skipped')}, ${this.total} total` + '\\n'\n    );\n    this.stdout.write(\n      colors.bold(' Time:        ') + `${(duration / 1000).toFixed(3)}s` + '\\n'\n    );\n  }\n}\n\nexport { Logger };\n"],"names":["colors.bold","colors.yellow","colors.green","colors.red","printErrorDetails"],"mappings":";;;;;AAGA;AACA,SAAS,oBAAoB,CAAC,KAAK,EAAE;AACrC,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI;AACzB;AACA;AACA,EAAE,MAAM,UAAU,GAAG;AACrB,IAAI,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC;AAC3C,IAAI,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,OAAO;AAC/B,IAAI,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,IAAI;AAC9B,IAAI,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,IAAI;AAC1C,IAAI,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI;AAC1B,GAAG;AACH;AACA;AACA,EAAE,IAAI,KAAK,CAAC,QAAQ,KAAK,SA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