Skip to content

Commit

Permalink
address Vlad's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Jun 29, 2021
1 parent bd3c1f7 commit ca74834
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/gatsby-worker/src/__tests__/task-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,41 @@ describe(`Task Queue`, () => {
]
`)
})

describe(`Removed node is not referenced in .next or .prev`, () => {
let taskQueue: TaskQueue<number>
beforeEach(() => {
taskQueue = new TaskQueue<number>()

taskQueue.enqueue(1)
taskQueue.enqueue(2)
taskQueue.enqueue(3)
})

it.each([
[`removed from head`, 1],
[`removed from middle`, 2],
[`removed from tail`, 3],
])(`%s`, (_label, itemToRemove) => {
for (const item of taskQueue) {
if (item.value === itemToRemove) {
taskQueue.remove(item)
}
}

for (const item of taskQueue) {
if (item.value === itemToRemove) {
fail(`"${itemToRemove}" found as value`)
}

if (item?.prev?.value === itemToRemove) {
fail(`"${itemToRemove}" found as value of previous node`)
}

if (item?.next?.value === itemToRemove) {
fail(`"${itemToRemove}" found as value of next node`)
}
}
})
})
})
3 changes: 3 additions & 0 deletions packages/gatsby-worker/src/task-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export class TaskQueue<ValueType> {
} else {
if (taskNode === this.tail) {
this.tail = taskNode.prev
} else {
// if node is not the tail then it will have .next
taskNode.next!.prev = taskNode.prev
}
// if node is not the head then it will have .prev
taskNode.prev!.next = taskNode.next
Expand Down

0 comments on commit ca74834

Please sign in to comment.