* 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 } = {})
| 152 | * @returns {string} the filename |
| 153 | */ |
| 154 | function 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 | |
| 177 | export { createTest, testToFileName, enhanceMochaTest, serializeTest, deserializeTest, cloneTest } |
| 178 |
no test coverage detected