mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
test: add tests for spa
This commit is contained in:
parent
f6d09642d7
commit
75350cdd78
7
test/fixtures/spa/layouts/custom.vue
vendored
Normal file
7
test/fixtures/spa/layouts/custom.vue
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
Custom layout
|
||||||
|
<br>
|
||||||
|
<nuxt/>
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/spa/nuxt.config.js
vendored
Normal file
5
test/fixtures/spa/nuxt.config.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
rootDir: __dirname,
|
||||||
|
mode: 'spa',
|
||||||
|
dev: false
|
||||||
|
}
|
15
test/fixtures/spa/pages/index.vue
vendored
Normal file
15
test/fixtures/spa/pages/index.vue
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
Hello SPA!
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
layout: 'custom',
|
||||||
|
mounted () {
|
||||||
|
window.indexMounted = (+window.indexMounted) + 1
|
||||||
|
console.log('mounted')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
36
test/spa.test.js
Executable file
36
test/spa.test.js
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
import test from 'ava'
|
||||||
|
import { resolve } from 'path'
|
||||||
|
import { Nuxt, Builder } from '../index.js'
|
||||||
|
|
||||||
|
let nuxt = null
|
||||||
|
|
||||||
|
const port = 4004
|
||||||
|
const url = (route) => 'http://localhost:' + port + route
|
||||||
|
|
||||||
|
const renderRoute = async _url => {
|
||||||
|
const window = await nuxt.renderAndGetWindow(url(_url))
|
||||||
|
const html = window.document.body.innerHTML
|
||||||
|
return { window, html }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init nuxt.js and create server listening on localhost:4000
|
||||||
|
test.before('Init Nuxt.js', async t => {
|
||||||
|
nuxt = new Nuxt(require('./fixtures/spa/nuxt.config'))
|
||||||
|
await new Builder(nuxt).build()
|
||||||
|
await nuxt.listen(port, 'localhost')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('/ (basic spa)', async t => {
|
||||||
|
const { html } = await renderRoute('/')
|
||||||
|
t.true(html.includes('Hello SPA!'))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('/ (custom layout)', async t => {
|
||||||
|
const { html } = await renderRoute('/')
|
||||||
|
t.true(html.includes('Custom layout'))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
|
test.after('Closing server and nuxt.js', t => {
|
||||||
|
nuxt.close()
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user