diff --git a/tests/e2e/source-control-discard-confirmation.spec.ts b/tests/e2e/source-control-discard-confirmation.spec.ts index 2db4f4b1a0a..484532af866 100644 --- a/tests/e2e/source-control-discard-confirmation.spec.ts +++ b/tests/e2e/source-control-discard-confirmation.spec.ts @@ -20,7 +20,7 @@ async function seedUntrackedFile( page: Page, requestedFileName?: string ): Promise { - 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 { - await page.evaluate(async () => { +async function refreshGitStatus(page: Page): Promise { + 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 { .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) }) }