2018-03-27 22:28:17 +00:00
|
|
|
import { loadFixture, getPort, Nuxt } from '../utils'
|
2017-10-07 09:07:52 +00:00
|
|
|
|
|
|
|
let nuxt = null
|
|
|
|
|
2018-03-18 23:41:14 +00:00
|
|
|
let port
|
2018-01-13 05:22:11 +00:00
|
|
|
const url = route => 'http://localhost:' + port + route
|
2017-10-07 09:07:52 +00:00
|
|
|
|
2018-03-18 23:41:14 +00:00
|
|
|
const renderRoute = async _url => {
|
|
|
|
const window = await nuxt.renderAndGetWindow(url(_url))
|
|
|
|
const head = window.document.head.innerHTML
|
|
|
|
const html = window.document.body.innerHTML
|
|
|
|
return { window, head, html }
|
|
|
|
}
|
2017-10-07 09:07:52 +00:00
|
|
|
|
2018-03-19 06:33:46 +00:00
|
|
|
describe.skip('spa', () => {
|
2018-03-18 19:31:32 +00:00
|
|
|
beforeAll(async () => {
|
2018-03-18 23:41:14 +00:00
|
|
|
const config = loadFixture('spa')
|
2017-12-17 19:30:26 +00:00
|
|
|
nuxt = new Nuxt(config)
|
2018-03-18 23:41:14 +00:00
|
|
|
port = await getPort()
|
2017-12-17 19:30:26 +00:00
|
|
|
await nuxt.listen(port, 'localhost')
|
2018-03-18 23:41:14 +00:00
|
|
|
})
|
2017-10-07 09:07:52 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/ (basic spa)', async () => {
|
|
|
|
// const logSpy = await interceptLog()
|
|
|
|
const { html } = await renderRoute('/')
|
|
|
|
expect(html.includes('Hello SPA!')).toBe(true)
|
|
|
|
// release()
|
|
|
|
// expect(logSpy.withArgs('created').notCalled).toBe(true)
|
|
|
|
// expect(logSpy.withArgs('mounted').calledOnce).toBe(true)
|
|
|
|
})
|
2017-10-07 09:07:52 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/custom (custom layout)', async () => {
|
|
|
|
// const logSpy = await interceptLog()
|
|
|
|
const { html } = await renderRoute('/custom')
|
|
|
|
expect(html.includes('Custom layout')).toBe(true)
|
|
|
|
// release()
|
|
|
|
// expect(logSpy.withArgs('created').calledOnce).toBe(true)
|
|
|
|
// expect(logSpy.withArgs('mounted').calledOnce).toBe(true)
|
|
|
|
})
|
2017-10-07 09:07:52 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/custom (not default layout)', async () => {
|
|
|
|
// const logSpy = await interceptLog()
|
|
|
|
const { head } = await renderRoute('/custom')
|
|
|
|
expect(head.includes('src="/_nuxt/layouts/default.')).toBe(false)
|
|
|
|
// release()
|
|
|
|
// expect(logSpy.withArgs('created').calledOnce).toBe(true)
|
|
|
|
// expect(logSpy.withArgs('mounted').calledOnce).toBe(true)
|
|
|
|
})
|
2017-11-14 08:53:01 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/custom (call mounted and created once)', async () => {
|
|
|
|
// const logSpy = await interceptLog()
|
|
|
|
await renderRoute('/custom')
|
|
|
|
// release()
|
|
|
|
// expect(logSpy.withArgs('created').calledOnce).toBe(true)
|
|
|
|
// expect(logSpy.withArgs('mounted').calledOnce).toBe(true)
|
|
|
|
})
|
2017-11-17 08:27:34 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/mounted', async () => {
|
|
|
|
const { html } = await renderRoute('/mounted')
|
2018-01-04 15:40:34 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(html.includes('<h1>Test: updated</h1>')).toBe(true)
|
|
|
|
})
|
2018-01-04 15:40:34 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/_nuxt/ (access publicPath in spa mode)', async () => {
|
|
|
|
await expect(renderRoute('/_nuxt/')).rejects.toMatchObject({
|
|
|
|
response: {
|
|
|
|
statusCode: 404,
|
|
|
|
statusMessage: 'ResourceNotFound'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2017-12-07 09:10:06 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
|
|
test('Closing server and nuxt.js', async () => {
|
|
|
|
await nuxt.close()
|
|
|
|
})
|
2017-10-07 09:07:52 +00:00
|
|
|
})
|