improve test

master
pooya parsa 2019-03-24 17:09:48 +04:30
parent 671356baf9
commit 235d114e12
2 changed files with 6 additions and 9 deletions

View File

@ -17,10 +17,9 @@ async function setupNuxt(config) {
await builder.validatePages() await builder.validatePages()
await builder.generateRoutesAndFiles() await builder.generateRoutesAndFiles()
nuxt.builder = builder nuxt.builder = builder
await nuxt.listen(3000) await nuxt.ready()
return nuxt return nuxt
} }

View File

@ -1,4 +1,4 @@
const ky = require('ky-universal') const fetch = require('node-fetch')
const { setupNuxt } = require('./_utils') const { setupNuxt } = require('./_utils')
const url = path => `http://localhost:3000${path}` const url = path => `http://localhost:3000${path}`
@ -8,8 +8,8 @@ describe('module', () => {
test('setup', async () => { test('setup', async () => {
nuxt = await setupNuxt() nuxt = await setupNuxt()
await nuxt.builder.build() await nuxt.builder.build()
await nuxt.listen(3000)
}) })
afterAll(async () => { afterAll(async () => {
@ -25,7 +25,7 @@ describe('module', () => {
}) })
test('asyncData', async () => { test('asyncData', async () => {
const html = await ky.get(url('/asyncData')).text() const html = await fetch(url('/asyncData')).then(r => r.text())
expect(html).toContain('foo/bar') expect(html).toContain('foo/bar')
}) })
@ -46,8 +46,7 @@ describe('module', () => {
}) })
test('ssr', async () => { test('ssr', async () => {
const makeReq = login => ky const makeReq = login => fetch(url('/ssr' + (login ? '?login' : '')))
.get(url('/ssr' + (login ? '?login' : '')))
.then(r => r.text()) .then(r => r.text())
.then(h => /session-[0-9]+/.exec(h)) .then(h => /session-[0-9]+/.exec(h))
.then(m => (m && m[0] ? m[0] : null)) .then(m => (m && m[0] ? m[0] : null))
@ -65,8 +64,7 @@ describe('module', () => {
}) })
test('ssr no brotli', async () => { test('ssr no brotli', async () => {
const makeReq = login => ky const makeReq = login => fetch(url('/ssr' + (login ? '?login' : '')))
.get(url('/ssr' + (login ? '?login' : '')))
.then(r => r.text()) .then(r => r.text())
.then(h => /encoding-\$(.*)\$/.exec(h)) .then(h => /encoding-\$(.*)\$/.exec(h))
.then(m => (m && m[1] ? m[1] : null)) .then(m => (m && m[1] ? m[1] : null))