Skip to content

Commit

Permalink
fix(TestRun): get previous node
Browse files Browse the repository at this point in the history
  • Loading branch information
ph-fritsche committed Dec 18, 2024
1 parent 2c0e928 commit 9380975
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/conductor/TestRun/TestNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export abstract class TestNodeStack extends EventEmitter<TestEventMap> {
}

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)
}
}

Expand Down Expand Up @@ -75,10 +75,10 @@ export abstract class TestNodeInstance extends EventEmitter<TestEventMap>{
}

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)
}
}

Expand Down Expand Up @@ -155,6 +155,19 @@ export class TestNodeChildren<T, Ident = string> implements Iterable<[T, Ident,
}
}

function getPreviousNode<T extends TestNodeStack|TestNodeInstance>(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<T extends TestNodeStack|TestNodeInstance>(node: T) {
for (let n = node;;) {
const lastChild = n.children?.last
Expand All @@ -166,6 +179,10 @@ function getLastLeaf<T extends TestNodeStack|TestNodeInstance>(node: T) {
}
}

function getNextNode<T extends TestNodeStack|TestNodeInstance>(node: T) {
return (node.children?.first ?? getNextBranch(node)) as T
}

function getNextBranch<T extends TestNodeStack|TestNodeInstance>(node: T) {
for (let n = node;;) {
const nextSibling = n.nextSibling
Expand Down

0 comments on commit 9380975

Please sign in to comment.