From 005f3cb9db2c070084a4f0fe2de461319f5b3600 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Fri, 30 Mar 2018 16:38:22 +0800 Subject: [PATCH] refactor: move nuxt.close to afterAll --- test/e2e/basic.browser.test.js | 4 +- test/e2e/children.patch.browser.test.js | 4 +- test/unit/basic.dev.test.js | 2 +- test/unit/basic.generate.test.js | 2 +- test/unit/basic.ssr.test.js | 2 +- test/unit/children.test.js | 2 +- test/unit/custom-dirs.test.js | 2 +- test/unit/debug.test.js | 2 +- test/unit/deprecate.test.js | 2 +- test/unit/error.test.js | 2 +- test/unit/express.test.js | 2 +- test/unit/fallback.generate.test.js | 2 +- test/unit/module.test.js | 98 +++++++++++++------------ test/unit/spa.test.js | 2 +- test/unit/ssr.test.js | 2 +- test/unit/with-config.test.js | 2 +- 16 files changed, 67 insertions(+), 65 deletions(-) diff --git a/test/e2e/basic.browser.test.js b/test/e2e/basic.browser.test.js index 1adabd7387..69e584648d 100644 --- a/test/e2e/basic.browser.test.js +++ b/test/e2e/basic.browser.test.js @@ -191,11 +191,11 @@ describe('basic browser', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) - test('Stop browser', async () => { + afterAll('Stop browser', async () => { await page.close() await browser.close() }) diff --git a/test/e2e/children.patch.browser.test.js b/test/e2e/children.patch.browser.test.js index 757096a798..f303545918 100644 --- a/test/e2e/children.patch.browser.test.js +++ b/test/e2e/children.patch.browser.test.js @@ -121,11 +121,11 @@ describe('children patch (browser)', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) - test('Stop browser', async () => { + afterAll('Stop browser', async () => { await page.close() await browser.close() }) diff --git a/test/unit/basic.dev.test.js b/test/unit/basic.dev.test.js index 151f1a01b9..2fed94d1f3 100644 --- a/test/unit/basic.dev.test.js +++ b/test/unit/basic.dev.test.js @@ -48,7 +48,7 @@ describe('basic dev', () => { // }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) }) diff --git a/test/unit/basic.generate.test.js b/test/unit/basic.generate.test.js index 680ff62f85..29968a004e 100644 --- a/test/unit/basic.generate.test.js +++ b/test/unit/basic.generate.test.js @@ -181,7 +181,7 @@ describe('basic generate', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server', async () => { + afterAll('Closing server', async () => { await server.close() }) }) diff --git a/test/unit/basic.ssr.test.js b/test/unit/basic.ssr.test.js index b6b7078ab7..88389ef868 100644 --- a/test/unit/basic.ssr.test.js +++ b/test/unit/basic.ssr.test.js @@ -266,7 +266,7 @@ describe('basic ssr', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) }) diff --git a/test/unit/children.test.js b/test/unit/children.test.js index 3b93a36477..c5dc86d9a1 100644 --- a/test/unit/children.test.js +++ b/test/unit/children.test.js @@ -48,7 +48,7 @@ describe('children', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) }) diff --git a/test/unit/custom-dirs.test.js b/test/unit/custom-dirs.test.js index 0f1df8c686..789491f269 100644 --- a/test/unit/custom-dirs.test.js +++ b/test/unit/custom-dirs.test.js @@ -42,7 +42,7 @@ describe('custom-dirs', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) }) diff --git a/test/unit/debug.test.js b/test/unit/debug.test.js index 0791af4f4a..0438c76319 100644 --- a/test/unit/debug.test.js +++ b/test/unit/debug.test.js @@ -89,7 +89,7 @@ describe.skip('debug', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) }) diff --git a/test/unit/deprecate.test.js b/test/unit/deprecate.test.js index 2acedae074..f9e7ed2fb9 100644 --- a/test/unit/deprecate.test.js +++ b/test/unit/deprecate.test.js @@ -15,7 +15,7 @@ describe('deprecate', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) }) diff --git a/test/unit/error.test.js b/test/unit/error.test.js index 9d7872a753..43bf15ed69 100644 --- a/test/unit/error.test.js +++ b/test/unit/error.test.js @@ -39,7 +39,7 @@ describe('error', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) }) diff --git a/test/unit/express.test.js b/test/unit/express.test.js index 2fae69742c..1f770394dc 100644 --- a/test/unit/express.test.js +++ b/test/unit/express.test.js @@ -32,7 +32,7 @@ describe('express', () => { expect(html.includes('

My component!

')).toBe(true) }) - test('close server', async () => { + afterAll('close server', async () => { await nuxt.close() await new Promise((resolve, reject) => { server.close(err => err ? reject(err) : resolve()) diff --git a/test/unit/fallback.generate.test.js b/test/unit/fallback.generate.test.js index 842f3a060a..6975b85f23 100644 --- a/test/unit/fallback.generate.test.js +++ b/test/unit/fallback.generate.test.js @@ -75,7 +75,7 @@ describe('fallback generate', () => { ) // Close server and ask nuxt to stop listening to file changes - test('Closing server', async () => { + afterAll('Closing server', async () => { await server.close() }) }) diff --git a/test/unit/module.test.js b/test/unit/module.test.js index d98daa73c6..96573c978f 100644 --- a/test/unit/module.test.js +++ b/test/unit/module.test.js @@ -7,52 +7,54 @@ const url = route => 'http://localhost:' + port + route let nuxt = null // let buildSpies = null -beforeAll(async () => { - const config = loadFixture('module') - nuxt = new Nuxt(config) - port = await getPort() - await nuxt.listen(port, 'localhost') -}) - -test('Plugin', async () => { - expect(normalize(nuxt.options.plugins[0].src).includes( - normalize('fixtures/module/.nuxt/basic.reverse.') - )).toBe(true) - const { html } = await nuxt.renderRoute('/') - expect(html.includes('

TXUN

')).toBe(true) -}) - -test('Layout', async () => { - expect(nuxt.options.layouts.layout.includes('layout')).toBe(true) - - const { html } = await nuxt.renderRoute('/layout') - expect(html.includes('

Module Layouts

')).toBe(true) -}) - -test('Hooks', async () => { - expect(nuxt.__module_hook).toBe(1) - expect(nuxt.__renderer_hook).toBe(2) -}) - -test('Hooks - Functional', async () => { - expect(nuxt.__ready_called__).toBe(true) -}) - -// test('Hooks - Error', async () => { -// expect(buildSpies.error.calledWithMatch(/build:extendRoutes/)).toBe(true) -// }) - -test('Middleware', async () => { - let response = await rp(url('/api')) - expect(response).toBe('It works!') -}) - -test('Hooks - Use external middleware before render', async () => { - let response = await rp(url('/use-middleware')) - expect(response).toBe('Use external middleware') -}) - -// Close server and ask nuxt to stop listening to file changes -test('Closing server and nuxt.js', async () => { - await nuxt.close() +describe.skip('module', () => { + beforeAll(async () => { + const config = loadFixture('module') + nuxt = new Nuxt(config) + port = await getPort() + await nuxt.listen(port, 'localhost') + }) + + test('Plugin', async () => { + expect(normalize(nuxt.options.plugins[0].src).includes( + normalize('fixtures/module/.nuxt/basic.reverse.') + )).toBe(true) + const { html } = await nuxt.renderRoute('/') + expect(html.includes('

TXUN

')).toBe(true) + }) + + test('Layout', async () => { + expect(nuxt.options.layouts.layout.includes('layout')).toBe(true) + + const { html } = await nuxt.renderRoute('/layout') + expect(html.includes('

Module Layouts

')).toBe(true) + }) + + test('Hooks', async () => { + expect(nuxt.__module_hook).toBe(1) + expect(nuxt.__renderer_hook).toBe(2) + }) + + test('Hooks - Functional', async () => { + expect(nuxt.__ready_called__).toBe(true) + }) + + // test('Hooks - Error', async () => { + // expect(buildSpies.error.calledWithMatch(/build:extendRoutes/)).toBe(true) + // }) + + test('Middleware', async () => { + let response = await rp(url('/api')) + expect(response).toBe('It works!') + }) + + test('Hooks - Use external middleware before render', async () => { + let response = await rp(url('/use-middleware')) + expect(response).toBe('Use external middleware') + }) + + // Close server and ask nuxt to stop listening to file changes + afterAll('Closing server and nuxt.js', async () => { + await nuxt.close() + }) }) diff --git a/test/unit/spa.test.js b/test/unit/spa.test.js index fe9fe8689f..629f08d810 100644 --- a/test/unit/spa.test.js +++ b/test/unit/spa.test.js @@ -71,7 +71,7 @@ describe.skip('spa', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) }) diff --git a/test/unit/ssr.test.js b/test/unit/ssr.test.js index c49b4cbbc5..fd03d302f2 100644 --- a/test/unit/ssr.test.js +++ b/test/unit/ssr.test.js @@ -102,7 +102,7 @@ describe('ssr', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) }) diff --git a/test/unit/with-config.test.js b/test/unit/with-config.test.js index 9082963f0d..2e7b85b011 100644 --- a/test/unit/with-config.test.js +++ b/test/unit/with-config.test.js @@ -179,7 +179,7 @@ describe('with-config', () => { }) // Close server and ask nuxt to stop listening to file changes - test('Closing server and nuxt.js', async () => { + afterAll('Closing server and nuxt.js', async () => { await nuxt.close() }) })