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AAS,SAAS,GAAG,MAAM,OAClC,EAAS,SAAS,GAAG,MAAM,KAAO,EAAS,SAAS,GAAG,MAAM,KAAK,QAAQ,GAElF,IAEI,IACA,EAAe,CAAC,aAAc,cAC9B,EAAM,UAAU,SAAQ,SAAU,GAC9B,EAAe,EAAa,QAAO,SAAU,GACzC,OAAQ,EAAK,EACjB,GACJ,IACA,EAAa,SAAQ,SAAU,GAC3B,IAAI,EAAM,CAAC,EACX,EAAI,GAAQ,GACZ,EAAM,UAAU,KAAK,EACzB,KAGC,EAAW,gBACL,EAAW,QAGtB,GAAc,EAAW,KAC7B,KAGK,EAAS,CACV,IAAI,EAAY,CACZ,MAAO,CACH,KAAM,KAAK,SAAS,gBACpB,MAAO,EAAM,SAAW,KAAQ,GAAG,QAAQ,GAC3C,MAAO,EACP,SAAU,EAAM,WAGpB,EAAM,UACN,EAAU,MAAM,QAAU,EAAM,SAEpC,EAAa,CAAC,GAAW,OAAO,EACpC,CAEA,OAAO,IAAI,CAAE,WAAY,GAAc,CAAE,aAAa,EAAM,OAAQ,MACxE,EAOA,mBAAmB,UAAU,eAAiB,SAAU,EAAK,GACzD,GAAI,EAAU,EAC0B,IAAhC,EAAS,QAAQ,YACjB,EAAW,EAAS,QAAQ,SAAU,IAAI,KAG9C,MAAM,kBAAmB,GACzB,OAAO,KAAK,KAAK,QAAQ,IAEzB,IACI,GAAG,cAAc,EAAU,EAAK,QACpC,CAAE,MAAO,GACL,MAAM,4BAA8B,EACxC,CACA,MAAM,+BACV,CACJ","file":"/npm/@vpavlik62/cypress-junit-reporter@1.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@vpavlik62/cypress-junit-reporter@1.0.0/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","'use strict';\r\n\r\nvar xml = require('xml');\r\nvar Base = require('mocha').reporters.Base;\r\nvar fs = require('fs');\r\nvar path = require('path');\r\nvar debug = require('debug')('cypress-junit-reporter');\r\nvar mkdirp = require('mkdirp');\r\nvar md5 = require('md5');\r\nvar stripAnsi = require('strip-ansi');\r\n\r\n// Save timer references so that times are correct even if Date is stubbed.\r\n// See https://github.com/mochajs/mocha/issues/237\r\nvar Date = global.Date;\r\n\r\nvar createStatsCollector;\r\nvar mocha6plus;\r\n\r\ntry {\r\n    var json = JSON.parse(\r\n        fs.readFileSync(path.dirname(require.resolve('mocha')) + \"/package.json\", \"utf8\")\r\n    );\r\n    var version = json.version;\r\n    if (version >= \"6\") {\r\n        createStatsCollector = require(\"mocha/lib/stats-collector\");\r\n        mocha6plus = true;\r\n    } else {\r\n        mocha6plus = false;\r\n    }\r\n} catch (e) {\r\n    // eslint-disable-next-line no-console\r\n    console.warn(\"Couldn't determine Mocha version\");\r\n}\r\nmodule.exports = MochaJUnitReporter;\r\n\r\n// A subset of invalid characters as defined in http://www.w3.org/TR/xml/#charsets that can occur in e.g. stacktraces\r\n// regex lifted from https://github.com/MylesBorins/xml-sanitizer/ (licensed MIT)\r\nvar INVALID_CHARACTERS_REGEX = /[\\u0000-\\u0008\\u000B\\u000C\\u000E-\\u001F\\u007f-\\u0084\\u0086-\\u009f\\uD800-\\uDFFF\\uFDD0-\\uFDFF\\uFFFF\\uC008]/g; //eslint-disable-line no-control-regex\r\n\r\nfunction findReporterOptions(options) {\r\n    debug('Checking for options in', options);\r\n    if (!options) {\r\n        debug('No options provided');\r\n        return {};\r\n    }\r\n    if (!mocha6plus) {\r\n        debug('Options for pre mocha@6');\r\n        return options.reporterOptions || {};\r\n    }\r\n    if (options.reporterOptions) {\r\n        debug('Command-line options for mocha@6+');\r\n        return options.reporterOptions;\r\n    }\r\n    // this is require to handle .mocharc.js files\r\n    debug('Looking for .mocharc.js options');\r\n    return Object.keys(options).filter(function (key) { return key.indexOf('reporterOptions.') === 0; })\r\n        .reduce(function (reporterOptions, key) {\r\n            reporterOptions[key.substring('reporterOptions.'.length)] = options[key];\r\n            return reporterOptions;\r\n        }, {});\r\n}\r\n\r\nfunction configureDefaults(options) {\r\n    var config = findReporterOptions(options);\r\n    debug('options', config);\r\n    config.mochaFile = getSetting(config.mochaFile, 'MOCHA_FILE', 'test-results.xml');\r\n    config.attachments = getSetting(config.attachments, 'ATTACHMENTS', false);\r\n    config.antMode = getSetting(config.antMode, 'ANT_MODE', false);\r\n    config.jenkinsMode = getSetting(config.jenkinsMode, 'JENKINS_MODE', false);\r\n    config.properties = getSetting(config.properties, 'PROPERTIES', null, parsePropertiesFromEnv);\r\n    config.toConsole = !!config.toConsole;\r\n    config.rootSuiteTitle = config.rootSuiteTitle || 'Root Suite';\r\n    config.testsuitesTitle = config.testsuitesTitle || 'Mocha Tests';\r\n    config.includeSpecFile = getSetting(config.includeSpecFile, 'INCLUDE_SPEC_FILE', false);\r\n\r\n    if (config.antMode) {\r\n        updateOptionsForAntMode(config);\r\n    }\r\n\r\n    if (config.jenkinsMode) {\r\n        updateOptionsForJenkinsMode(config);\r\n    }\r\n\r\n    config.suiteTitleSeparatedBy = config.suiteTitleSeparatedBy || ' ';\r\n\r\n    return config;\r\n}\r\n\r\nfunction updateOptionsForAntMode(options) {\r\n    options.antHostname = getSetting(options.antHostname, 'ANT_HOSTNAME', process.env.HOSTNAME);\r\n\r\n    if (!options.properties) {\r\n        options.properties = {};\r\n    }\r\n}\r\n\r\nfunction updateOptionsForJenkinsMode(options) {\r\n    if (options.useFullSuiteTitle === undefined) {\r\n        options.useFullSuiteTitle = true;\r\n    }\r\n    debug('jenkins mode - testCaseSwitchClassnameAndName', options.testCaseSwitchClassnameAndName);\r\n    if (options.testCaseSwitchClassnameAndName === undefined) {\r\n        options.testCaseSwitchClassnameAndName = true;\r\n    }\r\n    if (options.suiteTitleSeparatedBy === undefined) {\r\n        options.suiteTitleSeparatedBy = '.';\r\n    }\r\n}\r\n\r\n/**\r\n * Determine an option value.\r\n * 1. If `key` is present in the environment, then use the environment value\r\n * 2. If `value` is specified, then use that value\r\n * 3. Fall back to `defaultVal`\r\n * @module mocha-junit-reporter\r\n * @param {Object} value - the value from the reporter options\r\n * @param {String} key - the environment variable to check\r\n * @param {Object} defaultVal - the fallback value\r\n * @param {function} transform - a transformation function to be used when loading values from the environment\r\n */\r\nfunction getSetting(value, key, defaultVal, transform) {\r\n    if (process.env[key] !== undefined) {\r\n        var envVal = process.env[key];\r\n        return (typeof transform === 'function') ? transform(envVal) : envVal;\r\n    }\r\n    if (value !== undefined) {\r\n        return value;\r\n    }\r\n    return defaultVal;\r\n}\r\n\r\nfunction defaultSuiteTitle(suite) {\r\n    if (suite.root && suite.title === '') {\r\n        return stripAnsi(this._options.rootSuiteTitle);\r\n    }\r\n    return stripAnsi(suite.title);\r\n}\r\n\r\nfunction fullSuiteTitle(suite) {\r\n    var parent = suite.parent;\r\n    var title = [suite.title];\r\n\r\n    while (parent) {\r\n        if (parent.root && parent.title === '') {\r\n            title.unshift(this._options.rootSuiteTitle);\r\n        } else {\r\n            title.unshift(parent.title);\r\n        }\r\n        parent = parent.parent;\r\n    }\r\n\r\n    return stripAnsi(title.join(this._options.suiteTitleSeparatedBy));\r\n}\r\n\r\nfunction isInvalidSuite(suite) {\r\n    return (!suite.root && suite.title === '') || (suite.tests.length === 0 && suite.suites.length === 0);\r\n}\r\n\r\nfunction parsePropertiesFromEnv(envValue) {\r\n    if (envValue) {\r\n        debug('Parsing from env', envValue);\r\n        return envValue.split(',').reduce(function (properties, prop) {\r\n            var property = prop.split(':');\r\n            properties[property[0]] = property[1];\r\n            return properties;\r\n        }, []);\r\n    }\r\n\r\n    return null;\r\n}\r\n\r\nfunction generateProperties(options) {\r\n    var props = options.properties;\r\n    if (!props) {\r\n        return [];\r\n    }\r\n    return Object.keys(props).reduce(function (properties, name) {\r\n        var value = props[name];\r\n        properties.push({ property: { _attr: { name: name, value: value } } });\r\n        return properties;\r\n    }, []);\r\n}\r\n\r\nfunction getJenkinsClassname(test, options) {\r\n    debug('Building jenkins classname for', test);\r\n    var parent = test.parent;\r\n    var titles = [];\r\n    while (parent) {\r\n        parent.title && titles.unshift(parent.title);\r\n        parent = parent.parent;\r\n    }\r\n    if (options.jenkinsClassnamePrefix) {\r\n        titles.unshift(options.jenkinsClassnamePrefix);\r\n    }\r\n    return titles.join(options.suiteTitleSeparatedBy);\r\n}\r\n\r\nfunction getTestName(name, classname, specFilePath, flipClassAndName, includeSpecFile) {\r\n    name = flipClassAndName ? classname : name;\r\n\r\n    if (includeSpecFile) {\r\n        name = `[${specFilePath}] ${name}`;\r\n    }\r\n\r\n    return name;\r\n}\r\n\r\nfunction getSpecFile(test) {\r\n    if (!isUndefined(test.file)) {\r\n        return test.file;\r\n    } else if (!isUndefined(test.parent)) {\r\n        return getSpecFile(test.parent);\r\n    }\r\n    else {\r\n        return undefined;\r\n    }\r\n}\r\n\r\nfunction isUndefined(property) {\r\n    return property === null || property === undefined;\r\n}\r\n\r\n/**\r\n * JUnit reporter for mocha.js.\r\n * @module mocha-junit-reporter\r\n * @param {EventEmitter} runner - the test runner\r\n * @param {Object} options - mocha options\r\n */\r\nfunction MochaJUnitReporter(runner, options) {\r\n    if (mocha6plus) {\r\n        createStatsCollector(runner);\r\n    }\r\n    this._options = configureDefaults(options);\r\n    this._runner = runner;\r\n    this._generateSuiteTitle = this._options.useFullSuiteTitle ? fullSuiteTitle : defaultSuiteTitle;\r\n    this._antId = 0;\r\n    this._Date = (options || {}).Date || Date;\r\n\r\n    var testsuites = [];\r\n    this._testsuites = testsuites;\r\n\r\n    var currentError = null;\r\n\r\n    function lastSuite() {\r\n        return testsuites[testsuites.length - 1].testsuite;\r\n    }\r\n\r\n    // get functionality from the Base reporter\r\n    Base.call(this, runner);\r\n\r\n    // remove old results\r\n    this._runner.on('start', function () {\r\n        if (fs.existsSync(this._options.mochaFile)) {\r\n            debug('removing report file', this._options.mochaFile);\r\n            fs.unlinkSync(this._options.mochaFile);\r\n        }\r\n    }.bind(this));\r\n\r\n    this._onSuiteBegin = function (suite) {\r\n        if (!isInvalidSuite(suite)) {\r\n            testsuites.push(this.getTestsuiteData(suite));\r\n        }\r\n    };\r\n\r\n    this._runner.on('suite', function (suite) {\r\n        // allow tests to mock _onSuiteBegin\r\n        return this._onSuiteBegin(suite);\r\n    }.bind(this));\r\n\r\n    this._onSuiteEnd = function (suite) {\r\n        if (!isInvalidSuite(suite)) {\r\n            var testsuite = lastSuite();\r\n            if (testsuite) {\r\n                var start = testsuite[0]._attr.timestamp;\r\n                testsuite[0]._attr.time = this._Date.now() - start;\r\n            }\r\n        }\r\n    };\r\n\r\n    this._runner.on('suite end', function (suite) {\r\n        // allow tests to mock _onSuiteEnd\r\n        return this._onSuiteEnd(suite);\r\n    }.bind(this));\r\n\r\n    // it is necessary to use \"end\" events instead of \"pass\" \"fail\", because\r\n    // we need to access modified _testConfig, which is available only after hook or test end\r\n    this._runner.on('test end', function (test) {\r\n        var isInclude = !test.pending || this._options.includePending;\r\n\r\n        if (isInclude) {\r\n            var testcase = this.getTestcaseData(test);\r\n\r\n            if (test.pending) {\r\n                testcase.testcase.push({ skipped: null });\r\n            }\r\n\r\n            lastSuite().push(testcase);\r\n        }\r\n    }.bind(this));;\r\n\r\n    this._runner.on('fail', function (test) {\r\n        if (test.type === \"hook\") {\r\n            lastSuite().push(this.getTestcaseData(test));\r\n        }\r\n    }.bind(this));\r\n\r\n    this._runner.on('end', function () {\r\n        this.flush(testsuites);\r\n    }.bind(this));\r\n}\r\n\r\n/**\r\n * Produces an xml node for a test suite\r\n * @param  {Object} suite - a test suite\r\n * @return {Object}       - an object representing the xml node\r\n */\r\nMochaJUnitReporter.prototype.getTestsuiteData = function (suite) {\r\n    var antMode = this._options.antMode;\r\n\r\n    var _attr = {\r\n        name: this._generateSuiteTitle(suite),\r\n        timestamp: this._Date.now(),\r\n        tests: suite.tests.length\r\n    };\r\n    var testSuite = { testsuite: [{ _attr: _attr }] };\r\n\r\n\r\n    if (suite.file) {\r\n        testSuite.testsuite[0]._attr.file = suite.file;\r\n    }\r\n\r\n    var properties = generateProperties(this._options);\r\n    if (properties.length || antMode) {\r\n        testSuite.testsuite.push({\r\n            properties: properties\r\n        });\r\n    }\r\n\r\n    if (antMode) {\r\n        _attr.package = _attr.name;\r\n        _attr.hostname = this._options.antHostname;\r\n        _attr.id = this._antId;\r\n        _attr.errors = 0;\r\n        this._antId += 1;\r\n    }\r\n\r\n    return testSuite;\r\n};\r\n\r\n/**\r\n * Produces an xml config for a given test case.\r\n * @param {object} test - test case\r\n * @param {object} err - if test failed, the failure object\r\n * @returns {object}\r\n */\r\nMochaJUnitReporter.prototype.getTestcaseData = function (test) {\r\n    var jenkinsMode = this._options.jenkinsMode;\r\n    var flipClassAndName = this._options.testCaseSwitchClassnameAndName;\r\n    var includeSpecFile = this._options.includeSpecFile;\r\n    var name = stripAnsi(jenkinsMode ? getJenkinsClassname(test, this._options) : test.titlePath().join(this._options.suiteTitleSeparatedBy));\r\n    var classname = stripAnsi(test.title);\r\n    var specFilePath = getSpecFile(test);\r\n    var testcase = {\r\n        testcase: [{\r\n            _attr: {\r\n                name: getTestName(name, classname, specFilePath, flipClassAndName, includeSpecFile),\r\n                time: (typeof test.duration === 'undefined') ? 0 : test.duration / 1000,\r\n                classname: flipClassAndName ? name : classname\r\n            }\r\n        }]\r\n    };\r\n\r\n    // We need to merge console.logs and attachments into one <system-out> -\r\n    //  see JUnit schema (only accepts 1 <system-out> per test).\r\n    var testConfig = test._testConfig ?? {};\r\n    var systemOutLines = [];\r\n    if (this._options.outputs && (testConfig.consoleOutputs && testConfig.consoleOutputs.length > 0)) {\r\n        systemOutLines = systemOutLines.concat(testConfig.consoleOutputs);\r\n    }\r\n    if (this._options.attachments && testConfig.attachments && testConfig.attachments.length > 0) {\r\n        systemOutLines = systemOutLines.concat(testConfig.attachments.map(\r\n            function (file) {\r\n                return '[[ATTACHMENT|' + file + ']]';\r\n            }\r\n        ));\r\n    }\r\n    if (systemOutLines.length > 0) {\r\n        testcase.testcase.push({ 'system-out': this.removeInvalidCharacters(stripAnsi(systemOutLines.join('\\n'))) });\r\n    }\r\n\r\n    if (this._options.outputs && (testConfig.consoleErrors && testConfig.consoleErrors.length > 0)) {\r\n        testcase.testcase.push({ 'system-err': this.removeInvalidCharacters(stripAnsi(testConfig.consoleErrors.join('\\n'))) });\r\n    }\r\n\r\n    if (test.err && !test.pending) {\r\n        var err = test.err;\r\n        var message;\r\n        if (err.message && typeof err.message.toString === 'function') {\r\n            message = err.message + '';\r\n        } else if (typeof err.inspect === 'function') {\r\n            message = err.inspect() + '';\r\n        } else {\r\n            message = '';\r\n        }\r\n        var failureMessage = err.stack || message;\r\n        if (!Base.hideDiff && err.expected !== undefined) {\r\n            var oldUseColors = Base.useColors;\r\n            Base.useColors = false;\r\n            failureMessage += \"\\n\" + Base.generateDiff(err.actual, err.expected);\r\n            Base.useColors = oldUseColors;\r\n        }\r\n        var failureElement = {\r\n            _attr: {\r\n                message: this.removeInvalidCharacters(message) || '',\r\n                type: err.name || ''\r\n            },\r\n            _cdata: this.removeInvalidCharacters(failureMessage)\r\n        };\r\n\r\n        testcase.testcase.push({ failure: failureElement });\r\n    }\r\n    return testcase;\r\n};\r\n\r\n/**\r\n * @param {string} input\r\n * @returns {string} without invalid characters\r\n */\r\nMochaJUnitReporter.prototype.removeInvalidCharacters = function (input) {\r\n    if (!input) {\r\n        return input;\r\n    }\r\n    return input.replace(INVALID_CHARACTERS_REGEX, '');\r\n};\r\n\r\n/**\r\n * Writes xml to disk and ouputs content if \"toConsole\" is set to true.\r\n * @param {Array.<Object>} testsuites - a list of xml configs\r\n */\r\nMochaJUnitReporter.prototype.flush = function (testsuites) {\r\n    this._xml = this.getXml(testsuites);\r\n\r\n    this.writeXmlToDisk(this._xml, this._options.mochaFile);\r\n\r\n    if (this._options.toConsole === true) {\r\n        console.log(this._xml); // eslint-disable-line no-console\r\n    }\r\n};\r\n\r\n\r\n/**\r\n * Produces an XML string from the given test data.\r\n * @param {Array.<Object>} testsuites - a list of xml configs\r\n * @returns {string}\r\n */\r\nMochaJUnitReporter.prototype.getXml = function (testsuites) {\r\n    var totalTests = 0;\r\n    var stats = this._runner.stats;\r\n    var antMode = this._options.antMode;\r\n    var hasProperties = (!!this._options.properties) || antMode;\r\n    var Date = this._Date;\r\n\r\n    testsuites.forEach(function (suite) {\r\n        var _suiteAttr = suite.testsuite[0]._attr;\r\n        // testsuite is an array: [attrs, properties?, testcase, testcase, …]\r\n        // we want to make sure that we are grabbing test cases at the correct index\r\n        var _casesIndex = hasProperties ? 2 : 1;\r\n        var _cases = suite.testsuite.slice(_casesIndex);\r\n        var missingProps;\r\n\r\n        // suiteTime has unrounded time as a Number of milliseconds\r\n        var suiteTime = _suiteAttr.time;\r\n\r\n        _suiteAttr.time = (suiteTime / 1000 || 0).toFixed(3);\r\n        _suiteAttr.timestamp = new Date(_suiteAttr.timestamp).toISOString().slice(0, -5);\r\n        _suiteAttr.failures = 0;\r\n        _suiteAttr.skipped = 0;\r\n\r\n        _cases.forEach(function (testcase) {\r\n            var lastNode = testcase.testcase[testcase.testcase.length - 1];\r\n\r\n            _suiteAttr.skipped += Number('skipped' in lastNode);\r\n            _suiteAttr.failures += Number('failure' in lastNode);\r\n            if (typeof testcase.testcase[0]._attr.time === 'number') {\r\n                testcase.testcase[0]._attr.time = testcase.testcase[0]._attr.time.toFixed(3);\r\n            }\r\n        });\r\n\r\n        if (antMode) {\r\n            missingProps = ['system-out', 'system-err'];\r\n            suite.testsuite.forEach(function (item) {\r\n                missingProps = missingProps.filter(function (prop) {\r\n                    return !item[prop];\r\n                });\r\n            });\r\n            missingProps.forEach(function (prop) {\r\n                var obj = {};\r\n                obj[prop] = [];\r\n                suite.testsuite.push(obj);\r\n            });\r\n        }\r\n\r\n        if (!_suiteAttr.skipped) {\r\n            delete _suiteAttr.skipped;\r\n        }\r\n\r\n        totalTests += _suiteAttr.tests;\r\n    });\r\n\r\n\r\n    if (!antMode) {\r\n        var rootSuite = {\r\n            _attr: {\r\n                name: this._options.testsuitesTitle,\r\n                time: (stats.duration / 1000 || 0).toFixed(3),\r\n                tests: totalTests,\r\n                failures: stats.failures\r\n            }\r\n        };\r\n        if (stats.pending) {\r\n            rootSuite._attr.skipped = stats.pending;\r\n        }\r\n        testsuites = [rootSuite].concat(testsuites);\r\n    }\r\n\r\n    return xml({ testsuites: testsuites }, { declaration: true, indent: '  ' });\r\n};\r\n\r\n/**\r\n * Writes a JUnit test report XML document.\r\n * @param {string} xml - xml string\r\n * @param {string} filePath - path to output file\r\n */\r\nMochaJUnitReporter.prototype.writeXmlToDisk = function (xml, filePath) {\r\n    if (filePath) {\r\n        if (filePath.indexOf('[hash]') !== -1) {\r\n            filePath = filePath.replace('[hash]', md5(xml));\r\n        }\r\n\r\n        debug('writing file to', filePath);\r\n        mkdirp.sync(path.dirname(filePath));\r\n\r\n        try {\r\n            fs.writeFileSync(filePath, xml, 'utf-8');\r\n        } catch (exc) {\r\n            debug('problem writing results: ' + exc);\r\n        }\r\n        debug('results written successfully');\r\n    }\r\n};\r\n"]}