diff --git a/src/conductor/TestRun/TestNode.ts b/src/conductor/TestRun/TestNode.ts index 5b81364..7936b83 100644 --- a/src/conductor/TestRun/TestNode.ts +++ b/src/conductor/TestRun/TestNode.ts @@ -32,10 +32,10 @@ export abstract class TestNodeStack extends EventEmitter { } get previousNode(): TestNodeStack { - return this.previousSibling ?? this.parent ?? getLastLeaf(this) + return getPreviousNode(this) } get nextNode(): TestNodeStack { - return this.children?.first ?? getNextBranch(this) + return getNextNode(this) } } @@ -75,10 +75,10 @@ export abstract class TestNodeInstance extends EventEmitter{ } get previousNode(): TestNodeInstance { - return this.previousSibling ?? this.parent ?? getLastLeaf(this) + return getPreviousNode(this) } get nextNode(): TestNodeInstance { - return this.children?.first ?? getNextBranch(this) + return getNextNode(this) } } @@ -155,6 +155,19 @@ export class TestNodeChildren implements Iterable<[T, Ident, } } +function getPreviousNode(node: T) { + for (let n = node;;) { + const previousSibling = n.previousSibling + if (previousSibling) { + return getLastLeaf(previousSibling as T) + } else if (n.parent) { + return n.parent as T + } else { + return getLastLeaf(n) + } + } +} + function getLastLeaf(node: T) { for (let n = node;;) { const lastChild = n.children?.last @@ -166,6 +179,10 @@ function getLastLeaf(node: T) { } } +function getNextNode(node: T) { + return (node.children?.first ?? getNextBranch(node)) as T +} + function getNextBranch(node: T) { for (let n = node;;) { const nextSibling = n.nextSibling