All files / wdio-local-runner/src replQueue.js

100% Statements 15/15
100% Branches 4/4
100% Functions 5/5
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43                5x 5x       5x       6x 3x     3x 3x   3x 3x 3x       3x 3x   3x 3x         12x      
import WDIORepl from './repl'
 
/**
 * repl queue class
 * allows to run debug commands in mutliple workers one after another
 */
export default class ReplQueue {
    constructor () {
        this.runningRepl = null
        this.repls = []
    }
 
    add (childProcess, options, onStart, onEnd) {
        this.repls.push({ childProcess, options, onStart, onEnd })
    }
 
    next () {
        if (this.isRunning || this.repls.length === 0) {
            return
        }
 
        const { childProcess, options, onStart, onEnd } = this.repls.shift()
        this.runningRepl = new WDIORepl(childProcess, options)
 
        onStart()
        this.runningRepl.start().then(() => {
            const ev = {
                origin: 'debugger',
                name: 'stop'
            }
            this.runningRepl.childProcess.send(ev)
            onEnd(ev)
 
            delete this.runningRepl
            this.next()
        })
    }
 
    get isRunning () {
        return Boolean(this.runningRepl)
    }
}