Merge branch 'dev' into feat/reporters

This commit is contained in:
Pooya Parsa 2018-03-31 20:52:47 +04:30
commit 45007a7c39
21 changed files with 135 additions and 71 deletions

View File

@ -21,9 +21,9 @@
## Links
- 📘 Documentation: [https://nuxtjs.org](https://nuxtjs.org)
- 👥 [Community](https://nuxtjs.cmty.io)
- 🎬 Video: [1 minute demo](https://www.youtube.com/watch?v=kmf-p-pTi40)
- 🐦 Twitter: [@nuxt_js](https://twitter.com/nuxt_js)
- 👥 [Nuxt.js Community](https://github.com/nuxt-community)
- 📦 [Nuxt.js Modules](https://github.com/nuxt-community/modules)
- 👉 [Play with Nuxt.js online](https://glitch.com/edit/#!/nuxt-hello-world)

View File

@ -17,7 +17,7 @@ const layouts = { <%= Object.keys(layouts).map(key => `"_${key}": _${hash(key)}`
<% if (splitChunks.layouts) { %>let resolvedLayouts = {}<% } %>
export default {
head: <%= serialize(head).replace('head(', 'function(').replace('titleTemplate(', 'function(') %>,
head: <%= serialize(head).replace(/:\w+\(/gm, ':function(') %>,
render(h, props) {
<% if (loading) { %>const loadingEl = h('nuxt-loading', { ref: 'loading' })<% } %>
const layoutEl = h(this.layout || 'nuxt')
@ -121,4 +121,3 @@ export default {
<%= (loading ? 'NuxtLoading' : '') %>
}
}

View File

@ -191,11 +191,12 @@ describe('basic browser', () => {
})
// Close server and ask nuxt to stop listening to file changes
test('Closing server and nuxt.js', async () => {
afterAll(async () => {
await nuxt.close()
})
test('Stop browser', async () => {
// Stop browser
afterAll(async () => {
await page.close()
await browser.close()
})

View File

@ -121,11 +121,12 @@ describe('children patch (browser)', () => {
})
// Close server and ask nuxt to stop listening to file changes
test('Closing server and nuxt.js', async () => {
afterAll(async () => {
await nuxt.close()
})
test('Stop browser', async () => {
// Stop browser
afterAll(async () => {
await page.close()
await browser.close()
})

View File

@ -1,3 +1,5 @@
const { buildFixture } = require('../../utils/build')
buildFixture('deprecate')
describe.skip('build deprecate fixture', () => {
buildFixture('deprecate')
})

View File

@ -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(async () => {
await nuxt.close()
})
})

View File

@ -181,7 +181,7 @@ describe('basic generate', () => {
})
// Close server and ask nuxt to stop listening to file changes
test('Closing server', async () => {
afterAll(async () => {
await server.close()
})
})

View File

@ -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(async () => {
await nuxt.close()
})
})

View File

@ -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(async () => {
await nuxt.close()
})
})

View File

@ -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(async () => {
await nuxt.close()
})
})

View File

@ -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(async () => {
await nuxt.close()
})
})

View File

@ -5,7 +5,7 @@ let port
let nuxt = null
// let buildSpies = null
describe('deprecate', () => {
describe.skip('deprecate', () => {
beforeAll(async () => {
const config = loadFixture('deprecate')
@ -14,8 +14,10 @@ describe('deprecate', () => {
await nuxt.listen(port, 'localhost')
})
test()
// Close server and ask nuxt to stop listening to file changes
test('Closing server and nuxt.js', async () => {
afterAll(async () => {
await nuxt.close()
})
})

View File

@ -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(async () => {
await nuxt.close()
})
})

View File

@ -32,7 +32,7 @@ describe('express', () => {
expect(html.includes('<h1>My component!</h1>')).toBe(true)
})
test('close server', async () => {
afterAll(async () => {
await nuxt.close()
await new Promise((resolve, reject) => {
server.close(err => err ? reject(err) : resolve())

View File

@ -75,7 +75,7 @@ describe('fallback generate', () => {
)
// Close server and ask nuxt to stop listening to file changes
test('Closing server', async () => {
afterAll(async () => {
await server.close()
})
})

View File

@ -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('<h1>TXUN</h1>')).toBe(true)
})
test('Layout', async () => {
expect(nuxt.options.layouts.layout.includes('layout')).toBe(true)
const { html } = await nuxt.renderRoute('/layout')
expect(html.includes('<h1>Module Layouts</h1>')).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('<h1>TXUN</h1>')).toBe(true)
})
test('Layout', async () => {
expect(nuxt.options.layouts.layout.includes('layout')).toBe(true)
const { html } = await nuxt.renderRoute('/layout')
expect(html.includes('<h1>Module Layouts</h1>')).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(async () => {
await nuxt.close()
})
})

View File

@ -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(async () => {
await nuxt.close()
})
})

View File

@ -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(async () => {
await nuxt.close()
})
})

View File

@ -1,7 +1,42 @@
import { Utils } from '../utils'
import mockConsole from '../utils/console'
describe('utils', () => {
const console = mockConsole(['warn', 'error'])
test('printWarn', () => {
Utils.printWarn('Testing printWarn', 'utils.test.js')
expect(console.warn).toHaveBeenCalledTimes(1)
expect(console.warn.mock.calls[0][0]).toContain('WARN')
expect(console.warn.mock.calls[0][0]).toContain('Testing printWarn')
})
test('printError', () => {
Utils.printError(new Error('Error object'), 'utils.test.js')
expect(console.error).toHaveBeenCalledTimes(1)
expect(console.error.mock.calls[0][0]).toContain('Error: Error object')
console.error.mockClear()
Utils.printError('Error string', 'utils.test.js')
expect(console.error).toHaveBeenCalledTimes(1)
expect(console.error.mock.calls[0][0]).toContain('Error string')
})
test('fatalError', () => {
const exitSpy = jest.spyOn(process, 'exit').mockImplementation()
Utils.fatalError('Testing fatalError')
expect(console.error).toHaveBeenCalledTimes(1)
expect(console.error.mock.calls[0][0]).toContain('Testing fatalError')
expect(exitSpy).toHaveBeenCalledTimes(1)
expect(exitSpy).toHaveBeenCalledWith(1)
exitSpy.mockRestore()
})
test('encodeHtml', () => {
const html = '<h1>Hello</h1>'
expect(Utils.encodeHtml(html)).toBe('&lt;h1&gt;Hello&lt;/h1&gt;')

View File

@ -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(async () => {
await nuxt.close()
})
})

22
test/utils/console.js Normal file
View File

@ -0,0 +1,22 @@
/* eslint-disable no-console */
export default function mockConsole(levels = 'all') {
if (levels === 'all') {
levels = ['trace', 'debug', 'log', 'info', 'warn', 'error']
}
beforeAll(() => {
for (let level of levels) {
console[level] = jest.fn()
}
})
beforeEach(() => {
for (let level of levels) {
console[level].mockClear()
}
})
afterAll(() => {
for (let level of levels) {
console[level].mockRestore()
}
})
return console
}