MCPcopy
hub / github.com/codeceptjs/CodeceptJS / testToFileName

Function testToFileName

lib/mocha/test.js:154–175  ·  view source on GitHub ↗

* Get a filename from the test object * @param {CodeceptJS.Test} test * @param {Object} options * @param {string} options.suffix Add a suffix to the filename * @param {boolean} options.unique Add a unique suffix to the file * * @returns {string} the filename

(test, { suffix = '', unique = false } = {})

Source from the content-addressed store, hash-verified

152 * @returns {string} the filename
153 */
154function testToFileName(test, { suffix = '', unique = false } = {}) {
155 let fileName = test.title
156
157 // remove tags with empty string (disable for now)
158 // fileName = fileName.replace(/\@\w+/g, '')
159 fileName = fileName.slice(0, 100)
160 if (fileName.indexOf('{') !== -1) {
161 fileName = fileName.substr(0, fileName.indexOf('{') - 3).trim()
162 }
163
164 // Apply unique suffix AFTER removing data part to ensure uniqueness
165 if (unique) fileName = `${fileName}_${test?.uid || Math.floor(new Date().getTime())}`
166 if (suffix) fileName = `${fileName}_${suffix}`
167 if (test.ctx && test.ctx.test && test.ctx.test.type === 'hook') fileName = clearString(`${test.title}_${test.ctx.test.title}`)
168 // TODO: add suite title to file name
169 // if (test.parent && test.parent.title) {
170 // fileName = `${clearString(test.parent.title)}_${fileName}`
171 // }
172 fileName = clearString(fileName).slice(0, 100)
173
174 return fileName
175}
176
177export { createTest, testToFileName, enhanceMochaTest, serializeTest, deserializeTest, cloneTest }
178

Callers 6

wireOnStepFunction · 0.90
wireOnUrlFunction · 0.90
suffixFunction · 0.90
pageInfo.jsFile · 0.90
startScreencastFunction · 0.90
finalizeScreencastFunction · 0.90

Calls 1

clearStringFunction · 0.90

Tested by

no test coverage detected