2024-12-09 14:09:15 +00:00
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { isWindows } from 'std-env'
|
2024-12-18 12:09:12 +00:00
|
|
|
import { $fetch, createPage, fetch, setup, url } from '@nuxt/test-utils/e2e'
|
|
|
|
import { expectWithPolling } from '../utils'
|
2024-12-09 14:09:15 +00:00
|
|
|
|
|
|
|
const isWebpack =
|
|
|
|
process.env.TEST_BUILDER === 'webpack' ||
|
|
|
|
process.env.TEST_BUILDER === 'rspack'
|
|
|
|
|
|
|
|
const isDev = process.env.TEST_ENV === 'dev'
|
|
|
|
|
|
|
|
await setup({
|
|
|
|
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
|
|
|
|
dev: isDev,
|
|
|
|
server: true,
|
|
|
|
browser: true,
|
|
|
|
setupTimeout: (isWindows ? 360 : 120) * 1000,
|
|
|
|
nuxtConfig: {
|
|
|
|
builder: isWebpack ? 'webpack' : 'vite',
|
|
|
|
spaLoadingTemplate: true,
|
|
|
|
experimental: {
|
|
|
|
spaLoadingTemplateLocation: 'within',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('spaLoadingTemplateLocation flag is set to `within`', () => {
|
2024-12-18 12:09:12 +00:00
|
|
|
it.runIf(isDev)('should load dev server', async () => {
|
|
|
|
await expectWithPolling(() => fetch('/').then(r => r.status === 200).catch(() => null), true)
|
|
|
|
})
|
2024-12-09 21:40:23 +00:00
|
|
|
it('should render loader inside appTag', async () => {
|
2024-12-09 14:09:15 +00:00
|
|
|
const html = await $fetch<string>('/spa')
|
2024-12-10 20:45:00 +00:00
|
|
|
expect(html).toContain(`<div id="__nuxt"><div data-testid="loader">loading...</div></div>`)
|
2024-12-09 14:09:15 +00:00
|
|
|
})
|
|
|
|
|
2024-12-09 21:40:23 +00:00
|
|
|
it('spa-loader does not appear while the app is mounting', async () => {
|
2024-12-10 20:45:00 +00:00
|
|
|
const page = await createPage()
|
2024-12-09 21:40:23 +00:00
|
|
|
await page.goto(url('/spa'))
|
2024-12-09 14:09:15 +00:00
|
|
|
|
|
|
|
const loader = page.getByTestId('loader')
|
2024-12-10 20:45:00 +00:00
|
|
|
const content = page.getByTestId('content')
|
|
|
|
|
|
|
|
await loader.waitFor({ state: 'visible' })
|
|
|
|
expect(await content.isHidden()).toBeTruthy()
|
2024-12-09 21:40:23 +00:00
|
|
|
|
|
|
|
await page.waitForFunction(() => window.useNuxtApp?.() && window.useNuxtApp?.().isHydrating)
|
2024-12-10 20:45:00 +00:00
|
|
|
|
|
|
|
expect(await content.isHidden()).toBeTruthy()
|
|
|
|
|
|
|
|
await content.waitFor({ state: 'visible' })
|
2024-12-09 14:09:15 +00:00
|
|
|
|
|
|
|
await page.close()
|
|
|
|
}, 60_000)
|
|
|
|
})
|