From c14bb35aad591683597d38a4755576a60ba0a47d Mon Sep 17 00:00:00 2001 From: "Xin Du (Clark)" Date: Sun, 25 Aug 2019 23:41:32 +0100 Subject: [PATCH] test: remove unnecessary generate (#6301) --- packages/config/test/options.test.js | 12 +- .../generator/test/generator.route.test.js | 1 + test/fixtures/basic/nuxt.config.js | 3 +- test/unit/basic.generate.test.js | 22 ++-- test/unit/fallback.generate.test.js | 107 ------------------ 5 files changed, 21 insertions(+), 124 deletions(-) delete mode 100644 test/unit/fallback.generate.test.js diff --git a/packages/config/test/options.test.js b/packages/config/test/options.test.js index 7c9d5ace17..ab0b1e771a 100644 --- a/packages/config/test/options.test.js +++ b/packages/config/test/options.test.js @@ -112,11 +112,21 @@ describe('config: options', () => { 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 } }) 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', () => { const { build: { parallel } } = getNuxtConfig({ build: { extractCSS: true, parallel: true } }) expect(parallel).toEqual(false) diff --git a/packages/generator/test/generator.route.test.js b/packages/generator/test/generator.route.test.js index 567fa9552f..aaa877892b 100644 --- a/packages/generator/test/generator.route.test.js +++ b/packages/generator/test/generator.route.test.js @@ -32,6 +32,7 @@ describe('generator: generate route', () => { const nuxt = createNuxt() nuxt.options.build.html = { minify: false } nuxt.options.generate.minify = undefined + nuxt.options.generate.subFolders = false const generator = new Generator(nuxt) path.join.mockClear() diff --git a/test/fixtures/basic/nuxt.config.js b/test/fixtures/basic/nuxt.config.js index b4b829f070..74d5a6e74b 100644 --- a/test/fixtures/basic/nuxt.config.js +++ b/test/fixtures/basic/nuxt.config.js @@ -34,8 +34,7 @@ export default { '/тест雨', { route: '/users/3', payload: { id: 3000 } } ], - interval: 200, - subFolders: true + interval: 200 }, head () { return { diff --git a/test/unit/basic.generate.test.js b/test/unit/basic.generate.test.js index 9831ca5c10..e12fedde9e 100644 --- a/test/unit/basic.generate.test.js +++ b/test/unit/basic.generate.test.js @@ -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('

User: 1

') - expect(existsSync(resolve(distDir, 'users/1.html'))).toBe(true) - expect( - existsSync(resolve(distDir, 'users/1/index.html')) - ).toBe(false) - }) - test('/-ignored', async () => { await expect(rp(url('/-ignored'))).rejects.toMatchObject({ 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('

Index page

')).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 afterAll(async () => { await server.close() diff --git a/test/unit/fallback.generate.test.js b/test/unit/fallback.generate.test.js deleted file mode 100644 index 0dc16dc501..0000000000 --- a/test/unit/fallback.generate.test.js +++ /dev/null @@ -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('

Index page

')).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('

Index page

')).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() - }) -})