* Enhances Mocha Test with CodeceptJS specific functionality using composition * @param {CodeceptJS.Test & Mocha.Test} test - Test instance to enhance * @returns {CodeceptJS.Test & Mocha.Test} Enhanced test instance
(test)
| 21 | * @returns {CodeceptJS.Test & Mocha.Test} Enhanced test instance |
| 22 | */ |
| 23 | function enhanceMochaTest(test) { |
| 24 | // if no test, create a dummy one |
| 25 | if (!test) test = createTest('...', () => {}) |
| 26 | // already enhanced |
| 27 | if (test.codeceptjs) return test |
| 28 | |
| 29 | test.codeceptjs = true |
| 30 | // Add properties |
| 31 | test.tags = test.title.match(/(\@[a-zA-Z0-9-_]+)/g) || [] |
| 32 | test.steps = [] |
| 33 | test.config = {} |
| 34 | test.artifacts = [] |
| 35 | test.inject = {} |
| 36 | test.opts = {} |
| 37 | test.meta = {} |
| 38 | |
| 39 | test.notes = [] |
| 40 | test.addNote = (type, note) => { |
| 41 | test.notes.push({ type, text: note }) |
| 42 | } |
| 43 | |
| 44 | // Add new methods |
| 45 | /** |
| 46 | * @param {Mocha.Suite} suite - The Mocha suite to add this test to |
| 47 | */ |
| 48 | test.addToSuite = function (suite) { |
| 49 | enhanceMochaSuite(suite) |
| 50 | // Get testWrapper from asyncWrapper module |
| 51 | suite.addTest(testWrapper(this)) |
| 52 | if (test.file && !suite.file) suite.file = test.file |
| 53 | test.tags = [...(test.tags || []), ...(suite.tags || [])] |
| 54 | test.fullTitle = () => `${suite.title}: ${test.title}` |
| 55 | test.uid = genTestId(test) |
| 56 | } |
| 57 | |
| 58 | test.applyOptions = function (opts) { |
| 59 | if (!opts) opts = {} |
| 60 | test.opts = opts |
| 61 | test.meta = opts.meta || {} |
| 62 | test.totalTimeout = opts.timeout |
| 63 | if (opts.retries) this.retries(opts.retries) |
| 64 | } |
| 65 | |
| 66 | test.simplify = function () { |
| 67 | return serializeTest(this) |
| 68 | } |
| 69 | |
| 70 | return test |
| 71 | } |
| 72 | |
| 73 | function deserializeTest(test) { |
| 74 | test = Object.assign( |
no test coverage detected