Nuxt/test/express.test.js

45 lines
899 B
JavaScript
Raw Normal View History

2017-07-22 19:13:44 +00:00
import { resolve } from 'path'
2018-03-16 19:52:17 +00:00
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-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
2018-03-18 19:31:32 +00:00
describe('express', () => {
// Init nuxt.js and create express server
beforeAll(async () => {
const config = {
rootDir: resolve(__dirname, 'fixtures/basic'),
buildDir: '.nuxt-express',
dev: false,
build: {
stats: false
}
}
2017-07-22 19:13:44 +00:00
nuxt = new Nuxt(config)
2018-03-18 19:31:32 +00:00
new Builder(nuxt).build()
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
app.listen(port)
}, 30000)
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)
})
2017-07-22 19:13:44 +00:00
})