* Adds a REPL-like debugging experience to E2E tests. * Usage: * 1. In a test, add `await repl(this);` where `this` is mocha's this context. * This will cause the test to wait indefinitely when you want to execute * commands in the DevTools console. * You may have to change `async() =>
(global, env)
| 22 | * @param {!Object} env |
| 23 | */ |
| 24 | function installRepl(global, env) { |
| 25 | let replPromise = null; |
| 26 | let replResolve = null; |
| 27 | |
| 28 | /** |
| 29 | * Usage: in a test, await repl(); |
| 30 | * @param {*} mochaThis |
| 31 | * @return {!Promise} |
| 32 | */ |
| 33 | global.repl = function (mochaThis) { |
| 34 | mochaThis.timeout(REPL_INFINITE_TIMEOUT); |
| 35 | |
| 36 | const {controller} = env; |
| 37 | global.repl.controller = controller; |
| 38 | global.repl.env = env; |
| 39 | global.repl.continue = replContinue; |
| 40 | |
| 41 | if (!replPromise) { |
| 42 | replPromise = new Promise((resolve) => { |
| 43 | replResolve = resolve; |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | console./*OK*/ log(READY_MESSAGE); |
| 48 | |
| 49 | return replPromise; |
| 50 | }; |
| 51 | |
| 52 | /** |
| 53 | * Continues execution while debugging. |
| 54 | */ |
| 55 | function replContinue() { |
| 56 | if (!replResolve) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | replResolve(); |
| 61 | replResolve = null; |
| 62 | replPromise = null; |
| 63 | delete global.repl.controller; |
| 64 | delete global.repl.env; |
| 65 | delete global.repl.continue; |
| 66 | |
| 67 | console./*OK*/ log(CONTINUE_MESSAGE); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Ends the debugging session. |