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

Function serializeTest

lib/mocha/test.js:90–139  ·  view source on GitHub ↗
(test, error = null)

Source from the content-addressed store, hash-verified

88}
89
90function 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
141function cloneTest(test) {
142 return deserializeTest(serializeTest(test))

Callers 3

simplifyMethod · 0.90
enhanceMochaTestFunction · 0.70
cloneTestFunction · 0.70

Calls 2

serializeErrorFunction · 0.90
simplifyMethod · 0.65

Tested by

no test coverage detected