(test, error = null)
| 88 | } |
| 89 | |
| 90 | function serializeTest(test, error = null) { |
| 91 | // test = { ...test } |
| 92 | |
| 93 | if (test.start && !test.duration) { |
| 94 | const end = +new Date() |
| 95 | test.duration = end - test.start |
| 96 | } |
| 97 | |
| 98 | let err |
| 99 | |
| 100 | if (test.err) { |
| 101 | err = serializeError(test.err) |
| 102 | test.state = 'failed' |
| 103 | } else if (error) { |
| 104 | err = serializeError(error) |
| 105 | test.state = 'failed' |
| 106 | } |
| 107 | const parent = {} |
| 108 | if (test.parent) { |
| 109 | parent.title = test.parent.title |
| 110 | } |
| 111 | |
| 112 | if (test.opts) { |
| 113 | Object.keys(test.opts).forEach(k => { |
| 114 | if (typeof test.opts[k] === 'object') delete test.opts[k] |
| 115 | if (typeof test.opts[k] === 'function') delete test.opts[k] |
| 116 | }) |
| 117 | } |
| 118 | |
| 119 | let steps = undefined |
| 120 | if (Array.isArray(test.steps)) { |
| 121 | steps = test.steps.map(step => (step.simplify ? step.simplify() : step)) |
| 122 | } |
| 123 | |
| 124 | return { |
| 125 | opts: test.opts || {}, |
| 126 | tags: test.tags || [], |
| 127 | uid: test.uid, |
| 128 | retries: test._retries, |
| 129 | title: test.title, |
| 130 | state: test.state, |
| 131 | notes: test.notes || [], |
| 132 | meta: test.meta || {}, |
| 133 | artifacts: test.artifacts || {}, |
| 134 | duration: test.duration || 0, |
| 135 | err, |
| 136 | parent, |
| 137 | steps, |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | function cloneTest(test) { |
| 142 | return deserializeTest(serializeTest(test)) |
no test coverage detected