(runner)
| 24 | }; |
| 25 | |
| 26 | const customRunner = (runner) => { |
| 27 | const stats = {suites: 0, tests: 0, passes: 0, pending: 0, failures: 0}; |
| 28 | let level = 0; |
| 29 | |
| 30 | if (!runner) return; |
| 31 | |
| 32 | // AUTO-SCROLLING: |
| 33 | |
| 34 | // Mocha can start multiple suites before the first 'suite' event is emitted. This can break the |
| 35 | // logic used to determine if the div is already scrolled to the bottom. If this is false, |
| 36 | // auto-scrolling unconditionally scrolls to the bottom no matter how far up the div is |
| 37 | // currently scrolled. If true, auto-scrolling only happens if the div is scrolled close to the |
| 38 | // bottom. |
| 39 | let manuallyScrolled = false; |
| 40 | // The 'scroll' event is fired for manual scrolling as well as JavaScript-initiated scrolling. |
| 41 | // This is incremented while auto-scrolling and decremented when done auto-scrolling. This is |
| 42 | // used to ensure that auto-scrolling never sets manuallyScrolled to true. |
| 43 | let autoScrolling = 0; |
| 44 | |
| 45 | // Auto-scroll the #mocha-report div to show the newly added test entry if it was previously |
| 46 | // scrolled to the bottom. |
| 47 | const autoscroll = (newElement) => { |
| 48 | const mr = $('#mocha-report')[0]; |
| 49 | const scroll = !manuallyScrolled || (() => { |
| 50 | const offsetTopAbs = newElement.getBoundingClientRect().top; |
| 51 | const mrOffsetTopAbs = mr.getBoundingClientRect().top - mr.scrollTop; |
| 52 | const offsetTop = offsetTopAbs - mrOffsetTopAbs; |
| 53 | // Add some margin to cover rounding error and to make it easier to engage the auto-scroll. |
| 54 | return offsetTop <= mr.clientHeight + mr.scrollTop + 5; |
| 55 | })(); |
| 56 | if (!scroll) return; |
| 57 | ++autoScrolling; |
| 58 | mr.scrollTop = mr.scrollHeight; |
| 59 | manuallyScrolled = false; |
| 60 | }; |
| 61 | |
| 62 | $('#mocha-report').on('scroll', () => { |
| 63 | if (!autoScrolling) manuallyScrolled = true; |
| 64 | else --autoScrolling; |
| 65 | }); |
| 66 | |
| 67 | runner.on('start', () => { |
| 68 | stats.start = new Date(); |
| 69 | }); |
| 70 | |
| 71 | runner.on('suite', (suite) => { |
| 72 | if (suite.root) return; |
| 73 | autoscroll($('#mocha-report .suite').last()[0]); |
| 74 | stats.suites++; |
| 75 | append(suite.title); |
| 76 | level++; |
| 77 | }); |
| 78 | |
| 79 | runner.on('suite end', (suite) => { |
| 80 | if (suite.root) return; |
| 81 | level--; |
| 82 | |
| 83 | if (level === 0) { |
no test coverage detected