mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
test: remove unnecessary generate (#6301)
This commit is contained in:
parent
de71eee566
commit
c14bb35aad
@ -112,11 +112,21 @@ describe('config: options', () => {
|
|||||||
expect(pageTransition.appear).toEqual(true)
|
expect(pageTransition.appear).toEqual(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should return 404.html as default generate.fallback', () => {
|
test('should return 200.html as default generate.fallback', () => {
|
||||||
|
const { generate: { fallback } } = getNuxtConfig({})
|
||||||
|
expect(fallback).toEqual('200.html')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('should return 404.html when generate.fallback is true', () => {
|
||||||
const { generate: { fallback } } = getNuxtConfig({ generate: { fallback: true } })
|
const { generate: { fallback } } = getNuxtConfig({ generate: { fallback: true } })
|
||||||
expect(fallback).toEqual('404.html')
|
expect(fallback).toEqual('404.html')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should return fallback html when generate.fallback is string', () => {
|
||||||
|
const { generate: { fallback } } = getNuxtConfig({ generate: { fallback: 'fallback.html' } })
|
||||||
|
expect(fallback).toEqual('fallback.html')
|
||||||
|
})
|
||||||
|
|
||||||
test('should disable parallel if extractCSS is enabled', () => {
|
test('should disable parallel if extractCSS is enabled', () => {
|
||||||
const { build: { parallel } } = getNuxtConfig({ build: { extractCSS: true, parallel: true } })
|
const { build: { parallel } } = getNuxtConfig({ build: { extractCSS: true, parallel: true } })
|
||||||
expect(parallel).toEqual(false)
|
expect(parallel).toEqual(false)
|
||||||
|
@ -32,6 +32,7 @@ describe('generator: generate route', () => {
|
|||||||
const nuxt = createNuxt()
|
const nuxt = createNuxt()
|
||||||
nuxt.options.build.html = { minify: false }
|
nuxt.options.build.html = { minify: false }
|
||||||
nuxt.options.generate.minify = undefined
|
nuxt.options.generate.minify = undefined
|
||||||
|
nuxt.options.generate.subFolders = false
|
||||||
const generator = new Generator(nuxt)
|
const generator = new Generator(nuxt)
|
||||||
path.join.mockClear()
|
path.join.mockClear()
|
||||||
|
|
||||||
|
3
test/fixtures/basic/nuxt.config.js
vendored
3
test/fixtures/basic/nuxt.config.js
vendored
@ -34,8 +34,7 @@ export default {
|
|||||||
'/тест雨',
|
'/тест雨',
|
||||||
{ route: '/users/3', payload: { id: 3000 } }
|
{ route: '/users/3', payload: { id: 3000 } }
|
||||||
],
|
],
|
||||||
interval: 200,
|
interval: 200
|
||||||
subFolders: true
|
|
||||||
},
|
},
|
||||||
head () {
|
head () {
|
||||||
return {
|
return {
|
||||||
|
@ -204,20 +204,6 @@ describe('basic generate', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('nuxt re-generating with no subfolders', async () => {
|
|
||||||
generator.nuxt.options.generate.subFolders = false
|
|
||||||
await expect(generator.generate({ build: false })).resolves.toBeTruthy()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('/users/1.html', async () => {
|
|
||||||
const html = await rp(url('/users/1.html'))
|
|
||||||
expect(html).toContain('<h1>User: 1</h1>')
|
|
||||||
expect(existsSync(resolve(distDir, 'users/1.html'))).toBe(true)
|
|
||||||
expect(
|
|
||||||
existsSync(resolve(distDir, 'users/1/index.html'))
|
|
||||||
).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('/-ignored', async () => {
|
test('/-ignored', async () => {
|
||||||
await expect(rp(url('/-ignored'))).rejects.toMatchObject({
|
await expect(rp(url('/-ignored'))).rejects.toMatchObject({
|
||||||
statusCode: 404,
|
statusCode: 404,
|
||||||
@ -236,6 +222,14 @@ describe('basic generate', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('creates /200.html as fallback', async () => {
|
||||||
|
const html = await rp(url('/200.html'))
|
||||||
|
expect(html.includes('<h1>Index page</h1>')).toBe(false)
|
||||||
|
expect(html.includes('data-server-rendered')).toBe(false)
|
||||||
|
expect(existsSync(resolve(distDir, '200.html'))).toBe(true)
|
||||||
|
expect(existsSync(resolve(distDir, '404.html'))).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await server.close()
|
await server.close()
|
||||||
|
@ -1,107 +0,0 @@
|
|||||||
import http from 'http'
|
|
||||||
import { existsSync } from 'fs'
|
|
||||||
import { resolve } from 'path'
|
|
||||||
import serveStatic from 'serve-static'
|
|
||||||
import finalhandler from 'finalhandler'
|
|
||||||
import { loadFixture, getPort, Nuxt, Generator, getNuxtConfig, rp } from '../utils'
|
|
||||||
|
|
||||||
let port
|
|
||||||
const url = route => 'http://localhost:' + port + route
|
|
||||||
const distDir = resolve(__dirname, '..', 'fixtures/basic/.nuxt-generate-fallback')
|
|
||||||
|
|
||||||
let nuxt = null
|
|
||||||
let server = null
|
|
||||||
let generator = null
|
|
||||||
|
|
||||||
describe('fallback generate', () => {
|
|
||||||
beforeAll(async () => {
|
|
||||||
const config = await loadFixture('basic', { generate: { dir: '.nuxt-generate-fallback' } })
|
|
||||||
|
|
||||||
nuxt = new Nuxt(config)
|
|
||||||
generator = new Generator(nuxt)
|
|
||||||
|
|
||||||
await generator.generate({ build: false })
|
|
||||||
|
|
||||||
const serve = serveStatic(distDir)
|
|
||||||
server = http.createServer((req, res) => {
|
|
||||||
serve(req, res, finalhandler(req, res))
|
|
||||||
})
|
|
||||||
|
|
||||||
port = await getPort()
|
|
||||||
|
|
||||||
server.listen(port)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('default creates /200.html as fallback', async () => {
|
|
||||||
const html = await rp(url('/200.html'))
|
|
||||||
expect(html.includes('<h1>Index page</h1>')).toBe(false)
|
|
||||||
expect(html.includes('data-server-rendered')).toBe(false)
|
|
||||||
expect(existsSync(resolve(distDir, '200.html'))).toBe(true)
|
|
||||||
expect(existsSync(resolve(distDir, '404.html'))).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('nuxt re-generating with generate.fallback = false', async () => {
|
|
||||||
nuxt.options.generate.fallback = false
|
|
||||||
await expect(generator.generate({ build: false })).resolves.toBeTruthy()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('false creates no fallback', async () => {
|
|
||||||
await expect(rp(url('/200.html'))).rejects.toMatchObject({
|
|
||||||
statusCode: 404,
|
|
||||||
response: {
|
|
||||||
body: expect.stringContaining('Cannot GET /200.html')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(existsSync(resolve(distDir, '200.html'))).toBe(false)
|
|
||||||
expect(existsSync(resolve(distDir, '404.html'))).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('nuxt re-generating with generate.fallback = \'\'', async () => {
|
|
||||||
nuxt.options.generate.fallback = ''
|
|
||||||
await expect(generator.generate({ build: false })).resolves.toBeTruthy()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('empty string creates no fallback', async () => {
|
|
||||||
await expect(rp(url('/200.html'))).rejects.toMatchObject({
|
|
||||||
statusCode: 404,
|
|
||||||
response: {
|
|
||||||
body: expect.stringContaining('Cannot GET /200.html')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(existsSync(resolve(distDir, '200.html'))).toBe(false)
|
|
||||||
expect(existsSync(resolve(distDir, '404.html'))).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('generate.fallback = true is transformed to /404.html', () => {
|
|
||||||
const options = getNuxtConfig({
|
|
||||||
generate: {
|
|
||||||
fallback: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
expect(options.generate.fallback).toBe('404.html')
|
|
||||||
})
|
|
||||||
|
|
||||||
test(
|
|
||||||
'nuxt re-generating with generate.fallback = "spa-fallback.html"',
|
|
||||||
async () => {
|
|
||||||
nuxt.options.generate.fallback = 'spa-fallback.html'
|
|
||||||
await expect(generator.generate({ build: false })).resolves.toBeTruthy()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
test('spa-fallback.html was created', async () => {
|
|
||||||
const html = await rp(url('/spa-fallback.html'))
|
|
||||||
expect(html.includes('<h1>Index page</h1>')).toBe(false)
|
|
||||||
expect(html.includes('data-server-rendered')).toBe(false)
|
|
||||||
expect(existsSync(resolve(distDir, 'spa-fallback.html'))).toBe(true)
|
|
||||||
expect(existsSync(resolve(distDir, '200.html'))).toBe(false)
|
|
||||||
expect(existsSync(resolve(distDir, '404.html'))).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
|
||||||
afterAll(async () => {
|
|
||||||
await server.close()
|
|
||||||
})
|
|
||||||
})
|
|
Loading…
Reference in New Issue
Block a user