test(e2e): wait for git status to show the seeded file before the discard confirmation test acts (#30165)

This commit is contained in:
Jinwoo Hong
2026-10-17 20:59:19 -07:00
committed by GitHub
parent 3d03c33f9d
commit bb0f229aa5
@@ -20,7 +20,7 @@ async function seedUntrackedFile(
page: Page,
requestedFileName?: string
): Promise<SeededUntrackedFile> {
return page.evaluate(async (requestedFileName) => {
const seeded = await page.evaluate(async (requestedFileName) => {
const store = window.__store
if (!store) {
throw new Error('window.__store is not available')
@@ -43,24 +43,26 @@ async function seedUntrackedFile(
content: 'delete me\n'
})
const status = await window.api.git.status({ worktreePath: worktree.path })
state.setGitStatus(worktree.id, status)
const statusEntry = status.entries.find((entry) => entry.path.endsWith(fileName))
if (!statusEntry) {
throw new Error(`git status did not include ${fileName}`)
}
return {
fileName
}
}, requestedFileName)
// Why: a status read already in flight when the file was written can be joined and miss it.
await expect
.poll(
async () => (await refreshGitStatus(page)).some((path) => path.endsWith(seeded.fileName)),
{ timeout: 10_000, message: `git status did not include ${seeded.fileName}` }
)
.toBe(true)
return seeded
}
async function refreshGitStatus(page: Page): Promise<void> {
await page.evaluate(async () => {
async function refreshGitStatus(page: Page): Promise<string[]> {
return page.evaluate(async () => {
const store = window.__store
if (!store) {
return
throw new Error('window.__store is not available')
}
const state = store.getState()
const worktreeId = state.activeWorktreeId
@@ -68,9 +70,11 @@ async function refreshGitStatus(page: Page): Promise<void> {
.flat()
.find((entry) => entry.id === worktreeId)
if (!worktree) {
return
throw new Error('active worktree not found')
}
state.setGitStatus(worktree.id, await window.api.git.status({ worktreePath: worktree.path }))
const status = await window.api.git.status({ worktreePath: worktree.path })
state.setGitStatus(worktree.id, status)
return status.entries.map((entry) => entry.path)
})
}