mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-22 11:22:43 +00:00
add tests for sapPreloaderOutside
This commit is contained in:
parent
ffe807bf39
commit
b4a279dec1
8
test/fixtures/spa-loader/nuxt.config.ts
vendored
8
test/fixtures/spa-loader/nuxt.config.ts
vendored
@ -1,6 +1,12 @@
|
|||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
ssr: false,
|
|
||||||
devtools: { enabled: false },
|
devtools: { enabled: false },
|
||||||
spaLoadingTemplate: true,
|
spaLoadingTemplate: true,
|
||||||
|
routeRules: {
|
||||||
|
'/spa': { ssr: false },
|
||||||
|
'/ssr': { ssr: true },
|
||||||
|
},
|
||||||
|
experimental: {
|
||||||
|
spaPreloaderOutside: false,
|
||||||
|
},
|
||||||
compatibilityDate: '2024-06-28',
|
compatibilityDate: '2024-06-28',
|
||||||
})
|
})
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
import { fileURLToPath } from 'node:url'
|
|
||||||
import { describe, expect, it } from 'vitest'
|
|
||||||
import { isWindows } from 'std-env'
|
|
||||||
import { getBrowser, setup, url } from '@nuxt/test-utils'
|
|
||||||
|
|
||||||
const isWebpack = process.env.TEST_BUILDER === 'webpack' || process.env.TEST_BUILDER === 'rspack'
|
|
||||||
|
|
||||||
await setup({
|
|
||||||
rootDir: fileURLToPath(new URL('./fixtures/spa-loader', import.meta.url)),
|
|
||||||
dev: process.env.TEST_ENV === 'dev',
|
|
||||||
server: true,
|
|
||||||
browser: true,
|
|
||||||
setupTimeout: (isWindows ? 360 : 120) * 1000,
|
|
||||||
nuxtConfig: {
|
|
||||||
builder: isWebpack ? 'webpack' : 'vite',
|
|
||||||
ssr: true,
|
|
||||||
spaLoadingTemplate: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('spa-loader with SSR', () => {
|
|
||||||
it('should render content without spa-loader', async () => {
|
|
||||||
const browser = await getBrowser()
|
|
||||||
const page = await browser.newPage({})
|
|
||||||
await page.goto(url('/'), { waitUntil: 'domcontentloaded' })
|
|
||||||
|
|
||||||
const loader = page.getByTestId('__nuxt-spa-loader')
|
|
||||||
expect(await loader.isVisible()).toBeFalsy()
|
|
||||||
|
|
||||||
const content = page.getByTestId('content')
|
|
||||||
await content.waitFor({ state: 'visible' })
|
|
||||||
expect(await loader.isHidden()).toBeTruthy()
|
|
||||||
|
|
||||||
await page.close()
|
|
||||||
}, 60_000)
|
|
||||||
})
|
|
41
test/spa-loader/spa-preloader-outside-disabled.test.ts
Normal file
41
test/spa-loader/spa-preloader-outside-disabled.test.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import { isWindows } from 'std-env'
|
||||||
|
import { $fetch, getBrowser, setup, url } from '@nuxt/test-utils'
|
||||||
|
|
||||||
|
const isWebpack =
|
||||||
|
process.env.TEST_BUILDER === 'webpack' ||
|
||||||
|
process.env.TEST_BUILDER === 'rspack'
|
||||||
|
|
||||||
|
await setup({
|
||||||
|
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
|
||||||
|
dev: process.env.TEST_ENV === 'dev',
|
||||||
|
server: true,
|
||||||
|
browser: true,
|
||||||
|
setupTimeout: (isWindows ? 360 : 120) * 1000,
|
||||||
|
nuxtConfig: {
|
||||||
|
builder: isWebpack ? 'webpack' : 'vite',
|
||||||
|
spaLoadingTemplate: true,
|
||||||
|
experimental: {
|
||||||
|
spaPreloaderOutside: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('spaPreloaderOutside flag is disabled', () => {
|
||||||
|
it('shoul be render loader inside appTag', async () => {
|
||||||
|
const html = await $fetch('/spa')
|
||||||
|
expect(html).toContain(`<div id="__nuxt"><div data-testid="loader">loading...</div>\n</div>`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('spa-loader does not appear while the app is mounting', async () => {
|
||||||
|
const browser = await getBrowser()
|
||||||
|
const page = await browser.newPage({})
|
||||||
|
await page.goto(url('/spa'), { waitUntil: 'domcontentloaded' })
|
||||||
|
|
||||||
|
const loader = page.getByTestId('__nuxt-spa-loader')
|
||||||
|
expect(await loader.isHidden()).toBeTruthy()
|
||||||
|
|
||||||
|
await page.close()
|
||||||
|
}, 60_000)
|
||||||
|
})
|
@ -6,24 +6,25 @@ import { getBrowser, setup, url } from '@nuxt/test-utils'
|
|||||||
const isWebpack = process.env.TEST_BUILDER === 'webpack' || process.env.TEST_BUILDER === 'rspack'
|
const isWebpack = process.env.TEST_BUILDER === 'webpack' || process.env.TEST_BUILDER === 'rspack'
|
||||||
|
|
||||||
await setup({
|
await setup({
|
||||||
rootDir: fileURLToPath(new URL('./fixtures/spa-loader', import.meta.url)),
|
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
|
||||||
dev: process.env.TEST_ENV === 'dev',
|
dev: process.env.TEST_ENV === 'dev',
|
||||||
server: true,
|
server: true,
|
||||||
browser: true,
|
browser: true,
|
||||||
setupTimeout: (isWindows ? 360 : 120) * 1000,
|
setupTimeout: (isWindows ? 360 : 120) * 1000,
|
||||||
nuxtConfig: {
|
nuxtConfig: {
|
||||||
builder: isWebpack ? 'webpack' : 'vite',
|
builder: isWebpack ? 'webpack' : 'vite',
|
||||||
ssr: false,
|
|
||||||
spaLoadingTemplate: true,
|
spaLoadingTemplate: true,
|
||||||
|
experimental: {
|
||||||
|
spaPreloaderOutside: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('spa-loader with SPA', () => {
|
describe('spaPreloaderOutside flag is enabled', () => {
|
||||||
it('should render spa-loader', async () => {
|
it('should render spa-loader', async () => {
|
||||||
const browser = await getBrowser()
|
const browser = await getBrowser()
|
||||||
const page = await browser.newPage({})
|
const page = await browser.newPage({})
|
||||||
await page.goto(url('/'), { waitUntil: 'domcontentloaded' })
|
await page.goto(url('/spa'), { waitUntil: 'domcontentloaded' })
|
||||||
|
|
||||||
const loader = page.getByTestId('loader')
|
const loader = page.getByTestId('loader')
|
||||||
expect(await loader.isVisible()).toBeTruthy()
|
expect(await loader.isVisible()).toBeTruthy()
|
||||||
|
|
||||||
@ -33,4 +34,19 @@ describe('spa-loader with SPA', () => {
|
|||||||
|
|
||||||
await page.close()
|
await page.close()
|
||||||
}, 60_000)
|
}, 60_000)
|
||||||
|
|
||||||
|
it('should render content without spa-loader', async () => {
|
||||||
|
const browser = await getBrowser()
|
||||||
|
const page = await browser.newPage({})
|
||||||
|
await page.goto(url('/ssr'), { waitUntil: 'domcontentloaded' })
|
||||||
|
|
||||||
|
const loader = page.getByTestId('__nuxt-spa-loader')
|
||||||
|
expect(await loader.isHidden()).toBeTruthy()
|
||||||
|
|
||||||
|
const content = page.getByTestId('content')
|
||||||
|
await content.waitFor({ state: 'visible' })
|
||||||
|
expect(await loader.isHidden()).toBeTruthy()
|
||||||
|
|
||||||
|
await page.close()
|
||||||
|
}, 60_000)
|
||||||
})
|
})
|
Loading…
Reference in New Issue
Block a user