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M,EAAe,KAAK,YAAY,eAAiB,EACjD,EAAa,KAAK,YAAY,UAAY,EAGhD,IAAI,EA5BS,UA8BX,KAAK,YAAY,QAAU,GAC3B,KAAK,YAAY,eACkB,IAA3B,KAAK,YAAY,OACvB,EAAe,KAEjB,EAAa,GAMf,MAAM,EAAM,KAAK,YAAY,KAAO,KAC9B,EAAS,KAAK,MAClB,KAAK,UAAU,EAAK,OAAO,oBAAoB,GAAO,CAAC,KAGnD,EAAa,CACjB,GAAI,YAAY,KAAK,aACrB,KAAM,KAAK,YAAY,KACvB,MAAO,KAAK,YAAY,MACxB,SAAU,KAAK,YAAY,SAC3B,SAAU,KAAK,YAAY,SAC3B,UAAW,KAAK,OAAS,KAAK,YAAY,UAAY,GACtD,QAAS,KAAK,MACd,aAAc,EACd,WAAY,EACZ,KAAM,KAAK,YAAY,KACvB,MAAO,EACP,OAAQ,IAAe,EACvB,MAAO,KAAK,YAAY,MACxB,IAAK,EACL,OAAQ,EACR,OAAQ,GAIJ,EAAM,GAAG,gCACf,QAAQ,MAAM,EAAK,KAAK,UAAU,IAClC,QAAQ,OAAO,EAAK,kBAGpB,MAAM,EAAW,GAAG,qBAAqB,UACzC,QAAQ,KAAK,GACb,QAAQ,OAAO,EAAU,iBAC3B,CAEA,GACF","file":"/npm/mocha-distributed@0.9.6/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/mocha-distributed@0.9.6/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// -----------------------------------------------------------------------------\n// Copyright (c) 2018 Pau Sanchez\n//\n// MIT Licensed\n// -----------------------------------------------------------------------------\nconst redis = require(\"redis\");\nconst crypto = require(\"crypto\");\n\nconst GRANULARITY = {\n  TEST: \"test\",\n  SUITE: \"suite\",\n};\n\n// Initialize variables from environment\nconst g_redisAddress = process.env.MOCHA_DISTRIBUTED || \"\";\nconst g_testExecutionId = process.env.MOCHA_DISTRIBUTED_EXECUTION_ID || \"\";\nconst g_expirationTime =\n  process.env.MOCHA_DISTRIBUTED_EXPIRATION_TIME || `${7 * 24 * 3600}`;\n\n// Generate a unique random id for this runner (with almost 100% certainty\n// to be different on any machine/environment).\nconst _randomRunnerBuf = Buffer.alloc(16);\nconst _randomRunnerId = crypto.randomFillSync(_randomRunnerBuf).toString(\"hex\");\nconst g_runnerId = process.env.MOCHA_DISTRIBUTED_RUNNER_ID || _randomRunnerId;\nlet g_granularity =\n  process.env.MOCHA_DISTRIBUTED_GRANULARITY || GRANULARITY.TEST;\nconst g_mochaVerbose = process.env.MOCHA_DISTRIBUTED_VERBOSE === \"true\";\n\nif (g_granularity !== GRANULARITY.TEST) {\n  g_granularity = GRANULARITY.SUITE;\n}\n\nlet g_redis = null;\n\nlet g_capture = { stdout: null, stderr: null };\n\n// -----------------------------------------------------------------------------\n// getTestPath\n//\n// Returns an array with the test suites and test name from a test context\n// as found in the hooks\n//\n// Example:\n//\n//    >>> getTestPath(ctxt)\n//\n// -----------------------------------------------------------------------------\nfunction getTestPath(testContext) {\n  const path = [testContext.title];\n\n  while (!testContext.root && testContext.parent) {\n    testContext = testContext.parent;\n\n    if (testContext && !testContext.root) {\n      path.push(testContext.title);\n    }\n  }\n\n  return path.reverse();\n}\n\n// -----------------------------------------------------------------------------\n// getSerialGranularity\n//\n// Returns the full string or the \"serial string\" which is whatever finds that\n// follows this regex \"[serial.*]\" on the string. Only first instance is\n// returned.\n//\n// This will allow serializing tests with given serial name.\n// -----------------------------------------------------------------------------\nfunction getSerialGranularity(testKey) {\n  // NOTE: a regular expression might be trickier to get right, since you can\n  //       have multiple instances of [serialxxxx] on the same string\n  let index = testKey.indexOf('[serial')\n  if (index === -1)\n    return testKey\n\n  let index2 = testKey.indexOf(']', index)\n  if (index2 === -1)\n    return testKey\n\n  return testKey.substring(index, index2+1)\n}\n\n// -----------------------------------------------------------------------------\n// captureStream\n// -----------------------------------------------------------------------------\nfunction captureStream(stream) {\n  var oldWrite = stream.write;\n  var buf = [];\n\n  stream.write = function (chunk, encoding, callback) {\n    buf.push(chunk.toString()); // chunk is a String or Buffer\n    oldWrite.apply(stream, arguments);\n  };\n\n  return {\n    unhook() {\n      stream.write = oldWrite;\n    },\n    captured() {\n      return buf;\n    },\n  };\n}\n\n// -----------------------------------------------------------------------------\n// Initialize redis once before the tests\n// -----------------------------------------------------------------------------\nexports.mochaGlobalSetup = async function () {\n  if (g_mochaVerbose) {\n    const redisNoCredentials = g_redisAddress.replace(\n      /\\/\\/[^@]*@/,\n      \"//***:***@\"\n    );\n    console.log(\"---------------------------------------------------\");\n    console.log(\" Mocha Distributed\");\n    console.log(\"   - Runner Id                :\", g_runnerId);\n    console.log(\"   - Redis Address            :\", redisNoCredentials);\n    console.log(\"   - Execution Id             :\", g_testExecutionId);\n    console.log(\"   - Data Expiration Time     :\", g_expirationTime);\n    console.log(\"   - Test Parallel Granularity:\", g_granularity);\n    console.log(\"---------------------------------------------------\");\n  }\n\n  if (!g_redisAddress || !g_testExecutionId) {\n    console.log(g_redisAddress, g_testExecutionId);\n    console.error(\n      \"You need to set at least the following environment variables:\\n\" +\n        \"  - MOCHA_DISTRIBUTED\\n\" +\n        \"  - MOCHA_DISTRIBUTED_EXECUTION_ID\\n\"\n    );\n    process.exit(-1);\n  }\n\n  g_redis = redis.createClient({ url: g_redisAddress });\n  g_redis.on(\"error\", (err) => {\n    console.log(\"Redis Client Error\", err);\n    console.log(\"Closing application!\");\n    process.exit(-1);\n  });\n  await g_redis.connect();\n};\n\n// -----------------------------------------------------------------------------\n// Quit from redis\n// -----------------------------------------------------------------------------\nexports.mochaGlobalTeardown = async function () {\n  if (g_redis) {\n    await g_redis.quit();\n  }\n};\n\n// -----------------------------------------------------------------------------\n// Hook tests\n//\n// Please note that we run skip before each test if the ownership of it has\n// already been defined by another runner.\n// -----------------------------------------------------------------------------\nexports.mochaHooks = {\n  beforeEach: async function () {\n    const testPath = getTestPath(this.currentTest);\n    const testKeyFullPath = `${g_testExecutionId}:${getSerialGranularity(testPath.join(\":\"))}`;\n    const testKeySuite = `${g_testExecutionId}:${getSerialGranularity(testPath[0])}`;\n\n    const testKey =\n      g_granularity === GRANULARITY.TEST ? testKeyFullPath : testKeySuite;\n\n    // Atomically set/get the runner id associated to this test. Only the first\n    // runner to get there will set the value to its own runner id.\n    const [_, assignedRunnerId] = await g_redis\n      .multi()\n      .set(testKey, g_runnerId, { EX: g_expirationTime, NX: true })\n      .get(testKey)\n      .exec();\n\n    if (assignedRunnerId !== g_runnerId) {\n      this.currentTest.title += \" (skipped by mocha_distributted)\";\n      this.skip();\n    } else {\n      g_capture.stdout = captureStream(process.stdout);\n      g_capture.stderr = captureStream(process.stderr);\n    }\n  },\n\n  afterEach(done) {\n    const SKIPPED = \"pending\";\n    const FAILED = \"failed\";\n    const PASSED = \"passed\";\n\n    let capturedStdout = \"\";\n    let capturedStderr = \"\";\n    if (g_capture.stdout) {\n      const stdoutArray = g_capture.stdout.captured();\n      capturedStdout = stdoutArray.join(\"\");\n      capturedStdout = capturedStdout.replace(\n        /\\s*\\u001b\\[3[12]m[^\\n]*\\n$/g,\n        \"\"\n      );\n      g_capture.stdout.unhook();\n      g_capture.stdout = null;\n    }\n\n    if (g_capture.stderr) {\n      capturedStderr = g_capture.stderr.captured().join(\"\");\n      g_capture.stderr.unhook();\n      g_capture.stderr = null;\n    }\n\n    // Save all data in redis in a way it can be retrieved and aggregated\n    // easily for all test by an external reporter\n    if (this.currentTest.state !== SKIPPED) {\n      const retryAttempt = this.currentTest._currentRetry || 0;\n      const retryTotal = this.currentTest._retries || 1;\n\n      // adjust state value accounting for exceptions, timeouts & retries\n      let stateFixed = PASSED;\n      if (\n        this.currentTest.state === FAILED ||\n        this.currentTest.timedOut ||\n        (typeof this.currentTest.state === \"undefined\" &&\n          retryAttempt < retryTotal)\n      ) {\n        stateFixed = FAILED;\n      }\n\n      // Error objects cannot be properly serialized with stringify, thus\n      // we need to use this hack to make it look like a normal object.\n      // Hopefully this should work as well with other sort of objects\n      const err = this.currentTest.err || null;\n      const errObj = JSON.parse(\n        JSON.stringify(err, Object.getOwnPropertyNames(err || {}))\n      );\n\n      const testResult = {\n        id: getTestPath(this.currentTest),\n        type: this.currentTest.type,\n        title: this.currentTest.title,\n        timedOut: this.currentTest.timedOut,\n        duration: this.currentTest.duration,\n        startTime: Date.now() - (this.currentTest.duration || 0),\n        endTime: Date.now(),\n        retryAttempt: retryAttempt,\n        retryTotal: retryTotal,\n        file: this.currentTest.file,\n        state: stateFixed,\n        failed: stateFixed === FAILED,\n        speed: this.currentTest.speed,\n        err: errObj,\n        stdout: capturedStdout,\n        stderr: capturedStderr,\n      };\n\n      // save results as single line on purpose\n      const key = `${g_testExecutionId}:test_result`;\n      g_redis.rPush(key, JSON.stringify(testResult));\n      g_redis.expire(key, g_expirationTime);\n\n      // increment passed_count/failed_count & set expiry time\n      const countKey = `${g_testExecutionId}:${stateFixed}_count`;\n      g_redis.incr(countKey);\n      g_redis.expire(countKey, g_expirationTime);\n    }\n\n    done();\n  },\n};\n"]}