mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
66 lines
1.8 KiB
JavaScript
Executable File
66 lines
1.8 KiB
JavaScript
Executable File
import test from 'ava'
|
|
import jsdom from 'jsdom'
|
|
import { resolve } from 'path'
|
|
const port = 4002
|
|
const url = (route) => 'http://localhost:' + port + route
|
|
|
|
let nuxt = null
|
|
let server = null
|
|
|
|
// Init nuxt.js and create server listening on localhost:4000
|
|
test.before('Init Nuxt.js', t => {
|
|
const Nuxt = require('../')
|
|
const options = {
|
|
rootDir: resolve(__dirname, 'basic'),
|
|
dev: false
|
|
}
|
|
nuxt = new Nuxt(options)
|
|
return nuxt.build()
|
|
.then(function () {
|
|
server = new nuxt.Server(nuxt)
|
|
server.listen(port, 'localhost')
|
|
})
|
|
})
|
|
|
|
test('/stateless', async t => {
|
|
const { html } = await nuxt.renderRoute('/stateless')
|
|
t.true(html.includes('<h1>My component!</h1>'))
|
|
})
|
|
|
|
/*
|
|
** Example of testing via dom checking
|
|
*/
|
|
test('/css', async t => {
|
|
const window = await nuxt.renderAndGetWindow(jsdom, url('/css'))
|
|
const element = window.document.querySelector('.red')
|
|
t.not(element, null)
|
|
t.is(element.textContent, 'This is red')
|
|
t.is(element.className, 'red')
|
|
t.is(window.getComputedStyle(element).color, 'red')
|
|
})
|
|
|
|
test('/stateful', async t => {
|
|
const { html } = await nuxt.renderRoute('/stateful')
|
|
t.true(html.includes('<div><p>The answer is 42</p></div>'))
|
|
})
|
|
|
|
test('/head', async t => {
|
|
const window = await nuxt.renderAndGetWindow(jsdom, url('/head'))
|
|
const html = window.document.body.innerHTML
|
|
const metas = window.document.getElementsByTagName('meta')
|
|
t.is(window.document.title, 'My title')
|
|
t.is(metas[0].getAttribute('content'), 'my meta')
|
|
t.true(html.includes('<div><h1>I can haz meta tags</h1></div>'))
|
|
})
|
|
|
|
test('/async-data', async t => {
|
|
const { html } = await nuxt.renderRoute('/async-data')
|
|
t.true(html.includes('<p>Nuxt.js</p>'))
|
|
})
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
test.after('Closing server and nuxt.js', t => {
|
|
server.close()
|
|
nuxt.close()
|
|
})
|