mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
[CI] Clean up runtime test callbacks (#27483)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { expect, it } from 'vitest'
|
||||
import {
|
||||
registerWorktreeChangeInvalidator,
|
||||
runWorktreeChangeInvalidators
|
||||
} from './worktree-change-invalidators'
|
||||
|
||||
it('retires one worktree invalidator while keeping another active', () => {
|
||||
const first: string[] = []
|
||||
const second: string[] = []
|
||||
const unsubscribeFirst = registerWorktreeChangeInvalidator((repoId) => first.push(repoId))
|
||||
const unsubscribeSecond = registerWorktreeChangeInvalidator((repoId) => second.push(repoId))
|
||||
|
||||
try {
|
||||
runWorktreeChangeInvalidators('repo-1')
|
||||
expect(first).toEqual(['repo-1'])
|
||||
expect(second).toEqual(['repo-1'])
|
||||
|
||||
unsubscribeFirst()
|
||||
runWorktreeChangeInvalidators('repo-2')
|
||||
expect(first).toEqual(['repo-1'])
|
||||
expect(second).toEqual(['repo-1', 'repo-2'])
|
||||
} finally {
|
||||
unsubscribeFirst()
|
||||
unsubscribeSecond()
|
||||
}
|
||||
})
|
||||
@@ -1,6 +1,11 @@
|
||||
import * as mocks from './orca-runtime-test-mocks.spec'
|
||||
import type { MockInstance } from 'vitest'
|
||||
import * as worktreeChangeInvalidators from '../ipc/worktree-change-invalidators'
|
||||
import { awaitBackgroundRemovalsInRuntimeTests } from './orca-runtime-background-removal-test-support'
|
||||
import { _resetPendingWorktreeRemovalsForTests } from '../worktree-background-removal'
|
||||
import {
|
||||
_resetPendingWorktreeRemovalsForTests,
|
||||
_settlePendingWorktreeRemovalsForTests
|
||||
} from '../worktree-background-removal'
|
||||
import { _resetCanonicalRepoKeyCacheForTests } from '../git/canonical-repo-key'
|
||||
|
||||
const { MOCK_GIT_WORKTREES, RuntimeBrowserCommands, _resetTerminalViewAttributesForTest } = mocks
|
||||
@@ -338,7 +343,31 @@ function resetRuntimeTestMocks(): void {
|
||||
getIssueMock.mockResolvedValue(null)
|
||||
}
|
||||
|
||||
beforeEach(resetRuntimeTestMocks)
|
||||
afterEach(resetRuntimeTestMocks)
|
||||
let registrationSpy:
|
||||
| MockInstance<typeof worktreeChangeInvalidators.registerWorktreeChangeInvalidator>
|
||||
| undefined
|
||||
|
||||
beforeEach(() => {
|
||||
resetRuntimeTestMocks()
|
||||
registrationSpy = vi.spyOn(worktreeChangeInvalidators, 'registerWorktreeChangeInvalidator')
|
||||
})
|
||||
afterEach(async () => {
|
||||
try {
|
||||
await _settlePendingWorktreeRemovalsForTests()
|
||||
} finally {
|
||||
try {
|
||||
// Runtime fixtures share a process; invalidators must end with their case.
|
||||
for (const result of registrationSpy?.mock.results ?? []) {
|
||||
if (result.type === 'return') {
|
||||
result.value()
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
registrationSpy?.mockRestore()
|
||||
registrationSpy = undefined
|
||||
resetRuntimeTestMocks()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export { resetRuntimeTestMocks }
|
||||
|
||||
Reference in New Issue
Block a user