From 9380975ec6516cef84dc55ed22762d80e1c2161d Mon Sep 17 00:00:00 2001 From: Philipp Fritsche Date: Wed, 18 Dec 2024 16:24:45 +0000 Subject: [PATCH] fix(TestRun): get previous node --- src/conductor/TestRun/TestNode.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) 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