mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
Merge branch 'dev' into feat/reporters
This commit is contained in:
commit
45007a7c39
@ -21,9 +21,9 @@
|
|||||||
## Links
|
## Links
|
||||||
|
|
||||||
- 📘 Documentation: [https://nuxtjs.org](https://nuxtjs.org)
|
- 📘 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)
|
- 🎬 Video: [1 minute demo](https://www.youtube.com/watch?v=kmf-p-pTi40)
|
||||||
- 🐦 Twitter: [@nuxt_js](https://twitter.com/nuxt_js)
|
- 🐦 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)
|
- 📦 [Nuxt.js Modules](https://github.com/nuxt-community/modules)
|
||||||
- 👉 [Play with Nuxt.js online](https://glitch.com/edit/#!/nuxt-hello-world)
|
- 👉 [Play with Nuxt.js online](https://glitch.com/edit/#!/nuxt-hello-world)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ const layouts = { <%= Object.keys(layouts).map(key => `"_${key}": _${hash(key)}`
|
|||||||
<% if (splitChunks.layouts) { %>let resolvedLayouts = {}<% } %>
|
<% if (splitChunks.layouts) { %>let resolvedLayouts = {}<% } %>
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
head: <%= serialize(head).replace('head(', 'function(').replace('titleTemplate(', 'function(') %>,
|
head: <%= serialize(head).replace(/:\w+\(/gm, ':function(') %>,
|
||||||
render(h, props) {
|
render(h, props) {
|
||||||
<% if (loading) { %>const loadingEl = h('nuxt-loading', { ref: 'loading' })<% } %>
|
<% if (loading) { %>const loadingEl = h('nuxt-loading', { ref: 'loading' })<% } %>
|
||||||
const layoutEl = h(this.layout || 'nuxt')
|
const layoutEl = h(this.layout || 'nuxt')
|
||||||
@ -121,4 +121,3 @@ export default {
|
|||||||
<%= (loading ? 'NuxtLoading' : '') %>
|
<%= (loading ? 'NuxtLoading' : '') %>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,11 +191,12 @@ describe('basic browser', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Stop browser', async () => {
|
// Stop browser
|
||||||
|
afterAll(async () => {
|
||||||
await page.close()
|
await page.close()
|
||||||
await browser.close()
|
await browser.close()
|
||||||
})
|
})
|
||||||
|
@ -121,11 +121,12 @@ describe('children patch (browser)', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Stop browser', async () => {
|
// Stop browser
|
||||||
|
afterAll(async () => {
|
||||||
await page.close()
|
await page.close()
|
||||||
await browser.close()
|
await browser.close()
|
||||||
})
|
})
|
||||||
|
4
test/fixtures/deprecate/deprecate.test.js
vendored
4
test/fixtures/deprecate/deprecate.test.js
vendored
@ -1,3 +1,5 @@
|
|||||||
const { buildFixture } = require('../../utils/build')
|
const { buildFixture } = require('../../utils/build')
|
||||||
|
|
||||||
buildFixture('deprecate')
|
describe.skip('build deprecate fixture', () => {
|
||||||
|
buildFixture('deprecate')
|
||||||
|
})
|
||||||
|
@ -48,7 +48,7 @@ describe('basic dev', () => {
|
|||||||
// })
|
// })
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -181,7 +181,7 @@ describe('basic generate', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server', async () => {
|
afterAll(async () => {
|
||||||
await server.close()
|
await server.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -266,7 +266,7 @@ describe('basic ssr', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -48,7 +48,7 @@ describe('children', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -42,7 +42,7 @@ describe('custom-dirs', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -89,7 +89,7 @@ describe.skip('debug', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -5,7 +5,7 @@ let port
|
|||||||
let nuxt = null
|
let nuxt = null
|
||||||
// let buildSpies = null
|
// let buildSpies = null
|
||||||
|
|
||||||
describe('deprecate', () => {
|
describe.skip('deprecate', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const config = loadFixture('deprecate')
|
const config = loadFixture('deprecate')
|
||||||
|
|
||||||
@ -14,8 +14,10 @@ describe('deprecate', () => {
|
|||||||
await nuxt.listen(port, 'localhost')
|
await nuxt.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test()
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -39,7 +39,7 @@ describe('error', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -32,7 +32,7 @@ describe('express', () => {
|
|||||||
expect(html.includes('<h1>My component!</h1>')).toBe(true)
|
expect(html.includes('<h1>My component!</h1>')).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('close server', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
server.close(err => err ? reject(err) : resolve())
|
server.close(err => err ? reject(err) : resolve())
|
||||||
|
@ -75,7 +75,7 @@ describe('fallback generate', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server', async () => {
|
afterAll(async () => {
|
||||||
await server.close()
|
await server.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -7,52 +7,54 @@ const url = route => 'http://localhost:' + port + route
|
|||||||
let nuxt = null
|
let nuxt = null
|
||||||
// let buildSpies = null
|
// let buildSpies = null
|
||||||
|
|
||||||
beforeAll(async () => {
|
describe.skip('module', () => {
|
||||||
const config = loadFixture('module')
|
beforeAll(async () => {
|
||||||
nuxt = new Nuxt(config)
|
const config = loadFixture('module')
|
||||||
port = await getPort()
|
nuxt = new Nuxt(config)
|
||||||
await nuxt.listen(port, 'localhost')
|
port = await getPort()
|
||||||
})
|
await nuxt.listen(port, 'localhost')
|
||||||
|
})
|
||||||
test('Plugin', async () => {
|
|
||||||
expect(normalize(nuxt.options.plugins[0].src).includes(
|
test('Plugin', async () => {
|
||||||
normalize('fixtures/module/.nuxt/basic.reverse.')
|
expect(normalize(nuxt.options.plugins[0].src).includes(
|
||||||
)).toBe(true)
|
normalize('fixtures/module/.nuxt/basic.reverse.')
|
||||||
const { html } = await nuxt.renderRoute('/')
|
)).toBe(true)
|
||||||
expect(html.includes('<h1>TXUN</h1>')).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)
|
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)
|
const { html } = await nuxt.renderRoute('/layout')
|
||||||
})
|
expect(html.includes('<h1>Module Layouts</h1>')).toBe(true)
|
||||||
|
})
|
||||||
test('Hooks', async () => {
|
|
||||||
expect(nuxt.__module_hook).toBe(1)
|
test('Hooks', async () => {
|
||||||
expect(nuxt.__renderer_hook).toBe(2)
|
expect(nuxt.__module_hook).toBe(1)
|
||||||
})
|
expect(nuxt.__renderer_hook).toBe(2)
|
||||||
|
})
|
||||||
test('Hooks - Functional', async () => {
|
|
||||||
expect(nuxt.__ready_called__).toBe(true)
|
test('Hooks - Functional', async () => {
|
||||||
})
|
expect(nuxt.__ready_called__).toBe(true)
|
||||||
|
})
|
||||||
// test('Hooks - Error', async () => {
|
|
||||||
// expect(buildSpies.error.calledWithMatch(/build:extendRoutes/)).toBe(true)
|
// test('Hooks - Error', async () => {
|
||||||
// })
|
// expect(buildSpies.error.calledWithMatch(/build:extendRoutes/)).toBe(true)
|
||||||
|
// })
|
||||||
test('Middleware', async () => {
|
|
||||||
let response = await rp(url('/api'))
|
test('Middleware', async () => {
|
||||||
expect(response).toBe('It works!')
|
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'))
|
test('Hooks - Use external middleware before render', async () => {
|
||||||
expect(response).toBe('Use external middleware')
|
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 () => {
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
await nuxt.close()
|
afterAll(async () => {
|
||||||
|
await nuxt.close()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -71,7 +71,7 @@ describe.skip('spa', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -102,7 +102,7 @@ describe('ssr', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,42 @@
|
|||||||
|
|
||||||
import { Utils } from '../utils'
|
import { Utils } from '../utils'
|
||||||
|
import mockConsole from '../utils/console'
|
||||||
|
|
||||||
describe('utils', () => {
|
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', () => {
|
test('encodeHtml', () => {
|
||||||
const html = '<h1>Hello</h1>'
|
const html = '<h1>Hello</h1>'
|
||||||
expect(Utils.encodeHtml(html)).toBe('<h1>Hello</h1>')
|
expect(Utils.encodeHtml(html)).toBe('<h1>Hello</h1>')
|
||||||
|
@ -179,7 +179,7 @@ describe('with-config', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test('Closing server and nuxt.js', async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
22
test/utils/console.js
Normal file
22
test/utils/console.js
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user