Nuxt/test/unit/express.test.js

42 lines
884 B
JavaScript
Raw Normal View History

2017-07-22 19:13:44 +00:00
import express from 'express'
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 () => {
const config = await loadFixture('basic')
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-03-18 19:31:32 +00:00
expect(html.includes('<h1>My component!</h1>')).toBe(true)
})
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
})