2017-07-22 19:13:44 +00:00
|
|
|
import { resolve } from 'path'
|
2018-03-16 19:52:17 +00:00
|
|
|
|
|
|
|
import test from 'ava'
|
2017-07-22 19:13:44 +00:00
|
|
|
import express from 'express'
|
|
|
|
import rp from 'request-promise-native'
|
2018-03-16 19:52:17 +00:00
|
|
|
|
|
|
|
import { Nuxt, Builder } from '..'
|
2017-12-17 19:30:26 +00:00
|
|
|
import { interceptLog } from './helpers/console'
|
2017-07-22 19:13:44 +00:00
|
|
|
|
|
|
|
const port = 4000
|
2018-01-13 05:22:11 +00:00
|
|
|
const url = route => 'http://localhost:' + port + route
|
2017-07-22 19:13:44 +00:00
|
|
|
|
|
|
|
let nuxt
|
|
|
|
let app
|
|
|
|
|
|
|
|
// Init nuxt.js and create express server
|
2017-12-17 19:30:26 +00:00
|
|
|
test.serial('Init Nuxt.js', async t => {
|
|
|
|
const config = {
|
2017-07-22 19:13:44 +00:00
|
|
|
rootDir: resolve(__dirname, 'fixtures/basic'),
|
2017-12-17 19:30:26 +00:00
|
|
|
buildDir: '.nuxt-express',
|
|
|
|
dev: false,
|
|
|
|
build: {
|
|
|
|
stats: false
|
|
|
|
}
|
2017-07-22 19:13:44 +00:00
|
|
|
}
|
|
|
|
|
2017-12-17 19:30:26 +00:00
|
|
|
const logSpy = await interceptLog(async () => {
|
|
|
|
nuxt = new Nuxt(config)
|
|
|
|
await new Builder(nuxt).build()
|
|
|
|
})
|
|
|
|
t.true(logSpy.calledWithMatch('DONE'))
|
2017-07-22 19:13:44 +00:00
|
|
|
|
|
|
|
// Create express app
|
|
|
|
app = express()
|
|
|
|
|
|
|
|
// Register nuxt
|
|
|
|
app.use(nuxt.render)
|
|
|
|
|
|
|
|
// Start listening on localhost:4000
|
|
|
|
app.listen(port)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/stateless with express', async t => {
|
|
|
|
const html = await rp(url('/stateless'))
|
|
|
|
|
|
|
|
t.true(html.includes('<h1>My component!</h1>'))
|
|
|
|
})
|