| 4 | let currentSection |
| 5 | |
| 6 | class Section { |
| 7 | constructor(name = '') { |
| 8 | this.name = name |
| 9 | |
| 10 | this.metaStep = new MetaStep(null, name) |
| 11 | |
| 12 | this.attachMetaStep = step => { |
| 13 | if (currentSection !== this) return |
| 14 | if (!step) return |
| 15 | const metaStep = getRootMetaStep(step) |
| 16 | |
| 17 | if (metaStep !== this.metaStep) { |
| 18 | metaStep.metaStep = this.metaStep |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | hidden() { |
| 24 | this.metaStep.collapsed = true |
| 25 | return this |
| 26 | } |
| 27 | |
| 28 | start() { |
| 29 | if (currentSection) currentSection.end() |
| 30 | currentSection = this |
| 31 | event.dispatcher.prependListener(event.step.before, this.attachMetaStep) |
| 32 | event.dispatcher.once(event.test.finished, () => this.end()) |
| 33 | return this |
| 34 | } |
| 35 | |
| 36 | end() { |
| 37 | currentSection = null |
| 38 | event.dispatcher.off(event.step.started, this.attachMetaStep) |
| 39 | return this |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @returns {Section} |
| 44 | */ |
| 45 | static current() { |
| 46 | return currentSection |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | function getRootMetaStep(step) { |
| 51 | if (step.metaStep) return getRootMetaStep(step.metaStep) |