test: await before asserting console logs (#24051)

This commit is contained in:
Daniel Roe 2023-10-31 13:56:28 +01:00 committed by GitHub
parent d7b1116443
commit dce8ebb336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 2 deletions

View File

@ -1200,6 +1200,8 @@ describe('nested suspense', () => {
const first = start.match(/\/suspense\/(?<parentType>a?sync)-(?<parentNum>\d)\/(?<childType>a?sync)-(?<childNum>\d)\//)!.groups! const first = start.match(/\/suspense\/(?<parentType>a?sync)-(?<parentNum>\d)\/(?<childType>a?sync)-(?<childNum>\d)\//)!.groups!
const last = nav.match(/\/suspense\/(?<parentType>a?sync)-(?<parentNum>\d)\//)!.groups! const last = nav.match(/\/suspense\/(?<parentType>a?sync)-(?<parentNum>\d)\//)!.groups!
await new Promise<void>(resolve => setTimeout(resolve, 50))
expect(consoleLogs.map(l => l.text).filter(i => !i.includes('[vite]') && !i.includes('<Suspense> is an experimental feature')).sort()).toEqual([ expect(consoleLogs.map(l => l.text).filter(i => !i.includes('[vite]') && !i.includes('<Suspense> is an experimental feature')).sort()).toEqual([
// [first load] from parent // [first load] from parent
`[${first.parentType}]`, `[${first.parentType}]`,

View File

@ -3,7 +3,7 @@ if (import.meta.client) {
console.log('[async] [async]') console.log('[async] [async]')
} }
const route = useRoute('suspense-async-parent-async-child') const route = useRoute('suspense-async-parent-async-child')
await new Promise(resolve => setTimeout(resolve, 500)) await new Promise(resolve => setTimeout(resolve, 50))
if (import.meta.client) { if (import.meta.client) {
console.log(`[async] [${route.params.parent}] [async] [${route.params.child}] running async data`) console.log(`[async] [${route.params.parent}] [async] [${route.params.child}] running async data`)
} }

View File

@ -3,7 +3,7 @@ if (import.meta.client) {
console.log('[sync] [async]') console.log('[sync] [async]')
} }
const route = useRoute('suspense-async-parent-sync-child') const route = useRoute('suspense-async-parent-sync-child')
await new Promise(resolve => setTimeout(resolve, 500)) await new Promise(resolve => setTimeout(resolve, 50))
if (import.meta.client) { if (import.meta.client) {
console.log(`[sync] [${route.params.parent}] [async] [${route.params.child}] running async data`) console.log(`[sync] [${route.params.parent}] [async] [${route.params.child}] running async data`)
} }