(label, fn, options = {})
| 2041 | } |
| 2042 | |
| 2043 | async function measuredStep(label, fn, options = {}) { |
| 2044 | const parentTiming = activeTiming; |
| 2045 | const timing = { |
| 2046 | label, |
| 2047 | phase: options.phase ?? phaseTest, |
| 2048 | startedAt: Date.now(), |
| 2049 | elapsedMs: 0, |
| 2050 | sleepMs: 0, |
| 2051 | describeUiMs: 0, |
| 2052 | commandMs: 0, |
| 2053 | ok: false, |
| 2054 | }; |
| 2055 | activeTiming = timing; |
| 2056 | try { |
| 2057 | const result = await fn(); |
| 2058 | timing.ok = true; |
| 2059 | return result; |
| 2060 | } finally { |
| 2061 | timing.elapsedMs = Date.now() - timing.startedAt; |
| 2062 | stepTimings.push(timing); |
| 2063 | activeTiming = parentTiming; |
| 2064 | logStep( |
| 2065 | `timing ${label}: active ${formatDuration(timing.elapsedMs - timing.sleepMs)} (${formatDuration(timing.elapsedMs)} wall, ${formatDuration(timing.sleepMs)} artificial delay)`, |
| 2066 | ); |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | function sleep(ms) { |
| 2071 | if (activeTiming) { |
no test coverage detected