2017-07-22 19:13:44 +00:00
|
|
|
import express from 'express'
|
2018-03-27 22:28:17 +00:00
|
|
|
import { loadFixture, getPort, Nuxt, rp } from '../utils'
|
2018-03-16 19:52:17 +00:00
|
|
|
|
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-07-22 19:13:44 +00:00
|
|
|
|
|
|
|
let nuxt
|
|
|
|
let app
|
2018-03-18 23:41:14 +00:00
|
|
|
let server
|
2017-07-22 19:13:44 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
describe('express', () => {
|
|
|
|
// Init nuxt.js and create express server
|
|
|
|
beforeAll(async () => {
|
2018-08-17 20:25:23 +00:00
|
|
|
const config = await loadFixture('basic')
|
2017-12-17 19:30:26 +00:00
|
|
|
nuxt = new Nuxt(config)
|
2018-03-18 23:41:14 +00:00
|
|
|
|
|
|
|
port = await getPort()
|
2017-07-22 19:13:44 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
// Create express app
|
|
|
|
app = express()
|
2017-07-22 19:13:44 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
// Register nuxt
|
|
|
|
app.use(nuxt.render)
|
2017-07-22 19:13:44 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
// Start listening on localhost:4000
|
2018-03-18 23:41:14 +00:00
|
|
|
server = app.listen(port)
|
|
|
|
})
|
2017-07-22 19:13:44 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/stateless with express', async () => {
|
|
|
|
const html = await rp(url('/stateless'))
|
2017-07-22 19:13:44 +00:00
|
|
|
|
2018-11-08 09:41:24 +00:00
|
|
|
expect(html).toContain('<h1>My component!</h1>')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
2018-03-18 23:41:14 +00:00
|
|
|
|
2018-03-30 09:20:16 +00:00
|
|
|
afterAll(async () => {
|
2018-03-18 23:41:14 +00:00
|
|
|
await nuxt.close()
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
server.close(err => err ? reject(err) : resolve())
|
|
|
|
})
|
|
|
|
})
|
2017-07-22 19:13:44 +00:00
|
|
|
})
|