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 { createPage, fetch, setup, url } from '@nuxt/test-utils/e2e'
|
2024-12-10 20:45:00 +00:00
|
|
|
import type { Page } from 'playwright-core'
|
2024-12-18 12:09:12 +00:00
|
|
|
import { expectWithPolling } from '../utils'
|
2024-12-09 14:09:15 +00:00
|
|
|
|
|
|
|
const isWebpack = process.env.TEST_BUILDER === 'webpack' || process.env.TEST_BUILDER === 'rspack'
|
2024-12-18 12:09:12 +00:00
|
|
|
const isDev = process.env.TEST_ENV === 'dev'
|
2024-12-09 14:09:15 +00:00
|
|
|
|
|
|
|
await setup({
|
|
|
|
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
|
2024-12-18 12:09:12 +00:00
|
|
|
dev: isDev,
|
2024-12-09 14:09:15 +00:00
|
|
|
server: true,
|
|
|
|
browser: true,
|
|
|
|
setupTimeout: (isWindows ? 360 : 120) * 1000,
|
|
|
|
nuxtConfig: {
|
|
|
|
builder: isWebpack ? 'webpack' : 'vite',
|
|
|
|
spaLoadingTemplate: true,
|
|
|
|
experimental: {
|
|
|
|
spaLoadingTemplateLocation: 'body',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('spaLoadingTemplateLocation flag is set to `body`', () => {
|
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 14:09:15 +00:00
|
|
|
it('should render spa-loader', async () => {
|
2024-12-10 20:45:00 +00:00
|
|
|
const page = await createPage()
|
|
|
|
await page.goto(url('/spa'), { waitUntil: 'domcontentloaded' })
|
2024-12-09 14:09:15 +00:00
|
|
|
|
2024-12-10 20:45:00 +00:00
|
|
|
const loader = page.getByTestId('loader')
|
2024-12-09 14:09:15 +00:00
|
|
|
const content = page.getByTestId('content')
|
2024-12-10 20:45:00 +00:00
|
|
|
|
|
|
|
await loader.waitFor({ state: 'visible' })
|
|
|
|
expect(await content.isHidden()).toBeTruthy()
|
|
|
|
|
2024-12-09 14:09:15 +00:00
|
|
|
await content.waitFor({ state: 'visible' })
|
|
|
|
expect(await loader.isHidden()).toBeTruthy()
|
|
|
|
|
|
|
|
await page.close()
|
|
|
|
}, 60_000)
|
|
|
|
|
|
|
|
it('should render content without spa-loader', async () => {
|
2024-12-10 20:45:00 +00:00
|
|
|
const page = await createPage()
|
|
|
|
await page.goto(url('/ssr'), { waitUntil: 'domcontentloaded' })
|
2024-12-09 14:09:15 +00:00
|
|
|
|
2024-12-10 20:45:00 +00:00
|
|
|
const [loaderIsHidden, contentIsHidden] = await getState(page)
|
2024-12-09 14:09:15 +00:00
|
|
|
|
2024-12-10 20:45:00 +00:00
|
|
|
expect(loaderIsHidden).toBeTruthy()
|
|
|
|
expect(contentIsHidden).toBeFalsy()
|
2024-12-09 14:09:15 +00:00
|
|
|
|
|
|
|
await page.close()
|
|
|
|
}, 60_000)
|
|
|
|
})
|
2024-12-10 20:45:00 +00:00
|
|
|
|
|
|
|
function getState (page: Page) {
|
|
|
|
const loader = page.getByTestId('loader')
|
|
|
|
const content = page.getByTestId('content')
|
|
|
|
|
|
|
|
return Promise.all([
|
|
|
|
loader.isHidden(),
|
|
|
|
content.isHidden(),
|
|
|
|
])
|
|
|
|
}
|