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AC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;YACrD,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,EAAE;gBACrE,UAAU,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;gBACzC,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,IAAI,EAAE,KAAK,CAAC,IAAI;aACjB,CAAC,CAAC;SACJ;aAAM,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,EAAE;YAC/B,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE;gBACzB,UAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;aAC3B,CAAC,CAAC;SACJ;QAED,OAAO,IAAI,CAAC;IACd,CAAC","sourcesContent":["import { createWriteStream } from 'fs';\nimport { dirname } from 'path';\n\nimport Suite, { isSuite } from '../Suite';\nimport Test from '../Test';\nimport Reporter, { eventHandler, ReporterProperties } from './Reporter';\nimport { Executor } from '../executors/Executor';\nimport { mkdirp } from '../node/util';\n\n/**\n * There is no formal spec for this format and everyone does it differently, so\n * good luck! We've mashed as many of the different incompatible JUnit/xUnit\n * XSDs as possible into one reporter.\n */\nexport default class JUnit extends Reporter {\n readonly filename: string | undefined;\n\n constructor(executor: Executor, options: Partial<JUnitProperties> = {}) {\n super(executor, options);\n if (options.filename) {\n this.filename = options.filename;\n if (dirname(this.filename) !== '.') {\n mkdirp(dirname(this.filename));\n }\n this.output = createWriteStream(this.filename);\n }\n }\n\n @eventHandler()\n runEnd() {\n const rootNode = new XmlNode('testsuites');\n this.executor.suites.forEach(suite => {\n rootNode.childNodes.push(createSuiteNode(suite, this));\n });\n const report =\n '<?xml version=\"1.0\" encoding=\"UTF-8\" ?>' + rootNode.toString() + '\\n';\n this.output.end(report);\n }\n}\n\nexport interface JUnitProperties extends ReporterProperties {\n filename?: string;\n}\n\n/**\n * Simple XML generator.\n * @constructor\n * @param {string} nodeName The node name.\n * @param {Object?} attributes Optional attributes.\n */\nclass XmlNode {\n nodeName = '';\n childNodes: any[] = [];\n attributes: any;\n\n constructor(nodeName: string, attributes?: any) {\n this.nodeName = nodeName;\n\n if (attributes && attributes.childNodes) {\n this.childNodes = attributes.childNodes;\n attributes.childNodes = undefined;\n }\n this.attributes = attributes || {};\n }\n\n /**\n * Creates a new XML node and pushes it to the end of the current node.\n * @param {string} nodeName The node name for the new node.\n * @param {Object?} attributes Optional attributes for the new node.\n * @param {(XmlNode|string)[]?} childNodes Optional child nodes for the new\n * node.\n * @returns {XmlNode} A new node.\n */\n createNode(nodeName: string, attributes: Object) {\n const node = new XmlNode(nodeName, attributes);\n this.childNodes.push(node);\n return node;\n }\n\n _escape(str: string) {\n return String(str)\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/\"/g, '"');\n }\n\n _serializeAttributes() {\n const attributes = this.attributes;\n const nodes: any[] = [];\n\n for (let key in attributes) {\n if (attributes[key] != null) {\n nodes.push(key + '=\"' + this._escape(attributes[key]) + '\"');\n }\n }\n\n return nodes.length ? ' ' + nodes.join(' ') : '';\n }\n\n _serializeContent() {\n const nodeList = this.childNodes;\n const nodes: any[] = [];\n for (let i = 0, j = nodeList.length; i < j; ++i) {\n nodes.push(\n typeof nodeList[i] === 'string'\n ? this._escape(nodeList[i])\n : nodeList[i].toString()\n );\n }\n\n return nodes.join('');\n }\n\n /**\n * Outputs the node as a serialised XML string.\n * @returns {string}\n */\n toString() {\n const children = this._serializeContent();\n\n return (\n '<' +\n this.nodeName +\n this._serializeAttributes() +\n (children.length ? '>' + children + '</' + this.nodeName + '>' : '/>')\n );\n }\n}\n\nfunction createChildErrorNode(error: Error, reporter: JUnit) {\n return new XmlNode('error', {\n childNodes: [reporter.formatError(error)],\n message: error.message,\n type: error.name\n });\n}\n\nfunction createSuiteNode(suite: Suite, reporter: JUnit): XmlNode {\n const { error } = suite;\n let childNodes: XmlNode[] | undefined;\n if (error && error.lifecycleMethod === 'before') {\n childNodes = [createChildErrorNode(error, reporter)];\n } else {\n childNodes = suite.tests.map(test => createTestNode(test, reporter));\n }\n\n if (error && error.lifecycleMethod === 'after') {\n childNodes.push(createChildErrorNode(error, reporter));\n }\n\n return new XmlNode('testsuite', {\n name: suite.name || 'Node.js',\n failures: suite.numFailedTests,\n skipped: suite.numSkippedTests,\n tests: suite.numTests,\n time: suite.timeElapsed! / 1000,\n childNodes\n });\n}\n\nfunction createTestNode(test: Suite | Test, reporter: JUnit) {\n if (isSuite(test)) {\n return createSuiteNode(test, reporter);\n }\n\n const node = new XmlNode('testcase', {\n name: test.name,\n time: test.timeElapsed! / 1000,\n status: test.error ? 1 : 0\n });\n\n if (test.error || test.suiteError) {\n const error = <Error>(test.error || test.suiteError);\n node.createNode(error.name === 'AssertionError' ? 'failure' : 'error', {\n childNodes: [reporter.formatError(error)],\n message: error.message,\n type: error.name\n });\n } else if (test.skipped != null) {\n node.createNode('skipped', {\n childNodes: [test.skipped]\n });\n }\n\n return node;\n}\n"]} |