Nuxt/test/dev/express.test.js

43 lines
904 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
2023-10-16 21:23:38 +00:00
const url = route => 'http://127.0.0.1:' + 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', () => {
2020-11-30 22:44:04 +00:00
// Init nuxt and create express server
2018-03-18 19:31:32 +00:00
beforeAll(async () => {
const config = await loadFixture('basic')
nuxt = new Nuxt(config)
await nuxt.ready()
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 { body: 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
})