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
|
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 () => {
|
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)
|
2019-03-08 12:20:03 +00:00
|
|
|
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 () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
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
|
|
|
})
|