MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / buildTestCase

Function buildTestCase

lib/plugin/junitReporter.js:127–176  ·  view source on GitHub ↗
(doc, test, suiteName, config)

Source from the content-addressed store, hash-verified

125}
126
127function buildTestCase(doc, test, suiteName, config) {
128 const testEl = doc.createElement('testcase')
129 setAttr(testEl, 'name', test.title || '(no title)')
130 setAttr(testEl, 'classname', suiteName)
131 setAttr(testEl, 'time', toSeconds(test.duration || 0))
132 const file = test.file || (test.parent && test.parent.file)
133 if (file) setAttr(testEl, 'file', file)
134
135 if (config.attachMeta) {
136 const properties = metaProperties(test)
137 if (properties.length) {
138 const propertiesEl = doc.createElement('properties')
139 for (const [name, value] of properties) {
140 const prop = doc.createElement('property')
141 setAttr(prop, 'name', name)
142 setAttr(prop, 'value', value)
143 propertiesEl.appendChild(prop)
144 }
145 testEl.appendChild(propertiesEl)
146 }
147 }
148
149 const flat = flattenSteps(Array.isArray(test.steps) ? test.steps : [])
150
151 if (test.state === 'skipped' || test.state === 'pending') {
152 const skipped = doc.createElement('skipped')
153 const reason = skipReason(test)
154 if (reason) setAttr(skipped, 'message', reason)
155 testEl.appendChild(skipped)
156 } else if (test.state === 'failed') {
157 const err = test.err || {}
158 const failure = doc.createElement('failure')
159 setAttr(failure, 'message', err.message || 'Test failed')
160 setAttr(failure, 'type', err.name || 'Error')
161 let body = err.stack || err.message || 'Test failed'
162 if (config.stepsInFailure && flat.length) {
163 body += '\n\nSteps:\n' + flat.map(stepLogLine).join('\n')
164 }
165 failure.appendChild(doc.createTextNode(cleanText(body)))
166 testEl.appendChild(failure)
167 }
168
169 if (config.attachSteps && flat.length) {
170 const out = doc.createElement('system-out')
171 out.appendChild(doc.createTextNode(cleanText(flat.map(stepLogLine).join('\n'))))
172 testEl.appendChild(out)
173 }
174
175 return testEl
176}
177
178function metaProperties(test) {
179 const props = []

Callers 1

buildXmlFunction · 0.85

Calls 6

setAttrFunction · 0.85
toSecondsFunction · 0.85
metaPropertiesFunction · 0.85
flattenStepsFunction · 0.85
skipReasonFunction · 0.85
cleanTextFunction · 0.85

Tested by

no test coverage detected