diff --git a/packages/credentials/credentials-local/tests/watcher.spec.ts b/packages/credentials/credentials-local/tests/watcher.spec.ts index 7a77e7952a..314d425d1f 100644 --- a/packages/credentials/credentials-local/tests/watcher.spec.ts +++ b/packages/credentials/credentials-local/tests/watcher.spec.ts @@ -145,15 +145,9 @@ describe('watcher pipeline', () => { const dir = await tempDir() const path = join(dir, '.credentials.yaml') const ctx = await boot({ path, debounceMs: 5 }) - const firstUpdate = Promise.withResolvers() - const secondUpdate = Promise.withResolvers() let arm = true ctx.on('credentials/reference-updated', () => { - if (!arm) { - secondUpdate.resolve(undefined) - return - } - firstUpdate.resolve(undefined) + if (!arm) return throw Object.assign(new Error('forged relation'), { code: 'INVARIANT' }) }) const [instance] = await fakeInstances() @@ -162,14 +156,16 @@ describe('watcher pipeline', () => { instance!.watcher.emit('all', 'change', path) // The snapshot commits before the fan-out, so the value lands even though // the listener threw out of the refresh. - await firstUpdate.promise - expect(await ctx.credentials.resolve(KEY)).toEqual({ value: 'first', source: 'file' }) + await vi.waitFor(async () => { + expect(await ctx.credentials.resolve(KEY)).toEqual({ value: 'first', source: 'file' }) + }) arm = false await writeCredentials(path, 'version: 1\nrefs:\n DSH_CRED_PIPE: second\n') instance!.watcher.emit('all', 'change', path) - await secondUpdate.promise - expect(await ctx.credentials.resolve(KEY)).toEqual({ value: 'second', source: 'file' }) + await vi.waitFor(async () => { + expect(await ctx.credentials.resolve(KEY)).toEqual({ value: 'second', source: 'file' }) + }) }) it('quiesces the refresh pipeline before dispose completes', async () => {