Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,26 @@ describe('ReviewDecisionRail', () => {
// note id cannot resolve for a later test that expects it to be absent.
const cleanups: Array<() => void> = []

function drainCleanups(): void {
const errors: unknown[] = []
while (cleanups.length > 0) {
const cleanup = cleanups.pop()
if (!cleanup) continue
try {
cleanup()
} catch (error: unknown) {
errors.push(error)
}
}

if (errors.length === 1) throw errors[0]
if (errors.length > 1) {
throw new AggregateError(errors, 'One or more cleanup callbacks failed')
}
}

afterEach(() => {
for (const cleanup of cleanups.splice(0).reverse()) cleanup()
drainCleanups()
})

function renderExternalNote(): void {
Expand All @@ -392,6 +410,21 @@ describe('ReviewDecisionRail', () => {
cleanups.push(() => note.remove())
}

it('drains every cleanup when one callback throws', () => {
const events: string[] = []
const throwingCleanup = new Error('cleanup failed')
cleanups.push(() => events.push('oldest'))
cleanups.push(() => {
events.push('throwing')
throw throwingCleanup
})
cleanups.push(() => events.push('newest'))

expect(drainCleanups).toThrow(throwingCleanup)
expect(events).toEqual(['newest', 'throwing', 'oldest'])
expect(cleanups).toHaveLength(0)
})

it('describes every disabled decision control with the external explanation', () => {
renderExternalNote()
const wrapper = mountRail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,26 @@ describe('ReviewMain', () => {
// note id cannot resolve for a later test that expects it to be absent.
const cleanups: Array<() => void> = []

function drainCleanups(): void {
const errors: unknown[] = []
while (cleanups.length > 0) {
const cleanup = cleanups.pop()
if (!cleanup) continue
try {
cleanup()
} catch (error: unknown) {
errors.push(error)
}
}

if (errors.length === 1) throw errors[0]
if (errors.length > 1) {
throw new AggregateError(errors, 'One or more cleanup callbacks failed')
}
}

afterEach(() => {
for (const cleanup of cleanups.splice(0).reverse()) cleanup()
drainCleanups()
})

function renderLockNote(): void {
Expand All @@ -269,6 +287,21 @@ describe('ReviewMain', () => {
cleanups.push(() => note.remove())
}

it('drains every cleanup when one callback throws', () => {
const events: string[] = []
const throwingCleanup = new Error('cleanup failed')
cleanups.push(() => events.push('oldest'))
cleanups.push(() => {
events.push('throwing')
throw throwingCleanup
})
cleanups.push(() => events.push('newest'))

expect(drainCleanups).toThrow(throwingCleanup)
expect(events).toEqual(['newest', 'throwing', 'oldest'])
expect(cleanups).toHaveLength(0)
})

it('forwards the column description ids to every disabled decision control', () => {
renderLockNote()

Expand Down
Loading