Fix tests

This commit is contained in:
Sébastien Chopin 2017-06-18 19:33:23 +02:00
parent 840a6cfe00
commit c26daa9e8f
10 changed files with 27 additions and 35 deletions

View File

@ -1,7 +1,7 @@
import test from 'ava' import test from 'ava'
import { resolve } from 'path' import { resolve } from 'path'
import rp from 'request-promise-native' import rp from 'request-promise-native'
import { Nuxt, Server } from '../index.js' import { Nuxt, Server, Builder } from '../index.js'
const port = 4001 const port = 4001
const url = (route) => 'http://localhost:' + port + route const url = (route) => 'http://localhost:' + port + route
@ -16,7 +16,7 @@ test.before('Init Nuxt.js', async t => {
dev: true dev: true
} }
nuxt = new Nuxt(options) nuxt = new Nuxt(options)
await nuxt.ready() await new Builder(nuxt).build()
server = new Server(nuxt) server = new Server(nuxt)
server.listen(port, 'localhost') server.listen(port, 'localhost')
}) })
@ -37,8 +37,7 @@ test('/_nuxt/test.hot-update.json should returns empty html', async t => {
}) })
// Close server and ask nuxt to stop listening to file changes // Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => { test.after('Closing server and nuxt.js', async t => {
server.close() server.close()
nuxt.close(() => { await nuxt.close(() => {})
})
}) })

View File

@ -1,6 +1,6 @@
import test from 'ava' import test from 'ava'
import { resolve } from 'path' import { resolve } from 'path'
import { Nuxt } from '../index.js' import { Nuxt, Builder, Generator } from '../index.js'
test('Fail with routes() which throw an error', async t => { test('Fail with routes() which throw an error', async t => {
const options = { const options = {
@ -14,7 +14,9 @@ test('Fail with routes() which throw an error', async t => {
} }
} }
const nuxt = new Nuxt(options) const nuxt = new Nuxt(options)
return nuxt.generate() const builder = new Builder(nuxt)
const generator = new Generator(nuxt, builder)
return generator.generate()
.catch((e) => { .catch((e) => {
t.true(e.message === 'Not today!') t.true(e.message === 'Not today!')
}) })

View File

@ -4,7 +4,7 @@ import http from 'http'
import serveStatic from 'serve-static' import serveStatic from 'serve-static'
import finalhandler from 'finalhandler' import finalhandler from 'finalhandler'
import rp from 'request-promise-native' import rp from 'request-promise-native'
import { Nuxt } from '../index.js' import { Nuxt, Builder, Generator } from '../index.js'
const port = 4002 const port = 4002
const url = (route) => 'http://localhost:' + port + route const url = (route) => 'http://localhost:' + port + route
@ -20,8 +20,10 @@ test.before('Init Nuxt.js', async t => {
config.dev = false config.dev = false
config.runBuild = true config.runBuild = true
nuxt = new Nuxt(config) nuxt = new Nuxt(config)
const builder = new Builder(nuxt)
const generator = new Generator(nuxt, builder)
try { try {
await nuxt.generate() // throw an error (of /validate route) await generator.generate() // throw an error (of /validate route)
} catch (err) { } catch (err) {
} }
const serve = serveStatic(resolve(__dirname, 'fixtures/basic/dist')) const serve = serveStatic(resolve(__dirname, 'fixtures/basic/dist'))

View File

@ -2,7 +2,7 @@ import test from 'ava'
import { resolve } from 'path' import { resolve } from 'path'
import rp from 'request-promise-native' import rp from 'request-promise-native'
import stdMocks from 'std-mocks' import stdMocks from 'std-mocks'
import { Nuxt, Server } from '../index.js' import { Nuxt, Server, Builder } from '../index.js'
const port = 4003 const port = 4003
const url = (route) => 'http://localhost:' + port + route const url = (route) => 'http://localhost:' + port + route
@ -18,7 +18,7 @@ test.before('Init Nuxt.js', async t => {
runBuild: true runBuild: true
} }
nuxt = new Nuxt(options) nuxt = new Nuxt(options)
await nuxt.ready() await new Builder(nuxt).build()
server = new Server(nuxt) server = new Server(nuxt)
server.listen(port, 'localhost') server.listen(port, 'localhost')
}) })

View File

@ -1,6 +1,6 @@
import test from 'ava' import test from 'ava'
import { resolve } from 'path' import { resolve } from 'path'
import { Nuxt, Server } from '../index.js' import { Nuxt, Server, Builder } from '../index.js'
const port = 4004 const port = 4004
// const url = (route) => 'http://localhost:' + port + route // const url = (route) => 'http://localhost:' + port + route
@ -16,7 +16,7 @@ test.before('Init Nuxt.js', async t => {
runBuild: true runBuild: true
} }
nuxt = new Nuxt(options) nuxt = new Nuxt(options)
await nuxt.ready() await new Builder(nuxt).build()
server = new Server(nuxt) server = new Server(nuxt)
server.listen(port, 'localhost') server.listen(port, 'localhost')
}) })

View File

@ -2,7 +2,7 @@ import test from 'ava'
import { resolve } from 'path' import { resolve } from 'path'
import fs from 'fs' import fs from 'fs'
import pify from 'pify' import pify from 'pify'
import { Nuxt } from '../index.js' import { Nuxt, Builder } from '../index.js'
const readFile = pify(fs.readFile) const readFile = pify(fs.readFile)
@ -12,7 +12,7 @@ test.before('Init Nuxt.js', async t => {
dev: false, dev: false,
runBuild: true runBuild: true
}) })
await nuxt.ready() await new Builder(nuxt).build()
}) })
test('Check .nuxt/router.js', t => { test('Check .nuxt/router.js', t => {

View File

@ -1,6 +1,6 @@
import test from 'ava' import test from 'ava'
import { resolve } from 'path' import { resolve } from 'path'
import { Nuxt, Server } from '../index.js' import { Nuxt, Server, Builder } from '../index.js'
const port = 4005 const port = 4005
const url = (route) => 'http://localhost:' + port + route const url = (route) => 'http://localhost:' + port + route
@ -16,7 +16,7 @@ test.before('Init Nuxt.js', async t => {
runBuild: true runBuild: true
} }
nuxt = new Nuxt(options) nuxt = new Nuxt(options)
await nuxt.ready() await new Builder(nuxt).build()
server = new Server(nuxt) server = new Server(nuxt)
server.listen(port, 'localhost') server.listen(port, 'localhost')
}) })

View File

@ -1,6 +1,6 @@
import test from 'ava' import test from 'ava'
import { resolve } from 'path' import { resolve } from 'path'
import { Nuxt } from '../index.js' import { Nuxt, Builder } from '../index.js'
test('Nuxt.js Class', t => { test('Nuxt.js Class', t => {
t.is(typeof Nuxt, 'function') t.is(typeof Nuxt, 'function')
@ -12,7 +12,6 @@ test.serial('Nuxt.js Instance', async t => {
}) })
t.is(typeof nuxt, 'object') t.is(typeof nuxt, 'object')
t.is(nuxt.options.dev, true) t.is(nuxt.options.dev, true)
t.is(typeof nuxt.generate, 'function')
t.is(typeof nuxt._ready.then, 'function') t.is(typeof nuxt._ready.then, 'function')
await nuxt.ready() await nuxt.ready()
t.is(nuxt.initialized, true) t.is(nuxt.initialized, true)
@ -24,7 +23,7 @@ test.serial('Fail to build when no pages/ directory but is in the parent', t =>
runBuild: true, runBuild: true,
rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages') rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages')
}) })
return nuxt.ready().catch(err => { return new Builder(nuxt).build().catch(err => {
let s = String(err) let s = String(err)
t.true(s.includes('No `pages` directory found')) t.true(s.includes('No `pages` directory found'))
t.true(s.includes('Did you mean to run `nuxt` in the parent (`../`) directory?')) t.true(s.includes('Did you mean to run `nuxt` in the parent (`../`) directory?'))
@ -37,7 +36,7 @@ test.serial('Fail to build when no pages/ directory', t => {
runBuild: true, runBuild: true,
rootDir: resolve(__dirname) rootDir: resolve(__dirname)
}) })
return nuxt.ready().catch(err => { return new Builder(nuxt).build().catch(err => {
let s = String(err) let s = String(err)
t.true(s.includes('Couldn\'t find a `pages` directory')) t.true(s.includes('Couldn\'t find a `pages` directory'))
t.true(s.includes('Please create one under the project root')) t.true(s.includes('Please create one under the project root'))

View File

@ -1,7 +1,7 @@
import test from 'ava' import test from 'ava'
import { resolve, normalize } from 'path' import { resolve, normalize } from 'path'
import rp from 'request-promise-native' import rp from 'request-promise-native'
import { Nuxt, Server } from '../index.js' import { Nuxt, Server, Builder } from '../index.js'
const port = 4006 const port = 4006
const url = (route) => 'http://localhost:' + port + route const url = (route) => 'http://localhost:' + port + route
@ -17,7 +17,7 @@ test.before('Init Nuxt.js', async t => {
config.dev = false config.dev = false
config.runBuild = true config.runBuild = true
nuxt = new Nuxt(config) nuxt = new Nuxt(config)
await nuxt.ready() await new Builder(nuxt).build()
server = new Server(nuxt) server = new Server(nuxt)
server.listen(port, 'localhost') server.listen(port, 'localhost')
}) })

View File

@ -1,7 +1,7 @@
import test from 'ava' import test from 'ava'
import { resolve } from 'path' import { resolve } from 'path'
import rp from 'request-promise-native' import rp from 'request-promise-native'
import { Nuxt, Server } from '../index.js' import { Nuxt, Server, Builder } from '../index.js'
const port = 4007 const port = 4007
const url = (route) => 'http://localhost:' + port + route const url = (route) => 'http://localhost:' + port + route
@ -17,7 +17,7 @@ test.before('Init Nuxt.js', async t => {
config.dev = false config.dev = false
config.runBuild = true config.runBuild = true
nuxt = new Nuxt(config) nuxt = new Nuxt(config)
await nuxt.ready() await new Builder(nuxt).build()
server = new Server(nuxt) server = new Server(nuxt)
server.listen(port, 'localhost') server.listen(port, 'localhost')
}) })
@ -104,13 +104,3 @@ test.after('Closing server and nuxt.js', t => {
server.close() server.close()
nuxt.close() nuxt.close()
}) })
test.after('Should be able to start Nuxt with build done', async t => {
const rootDir = resolve(__dirname, 'fixtures/with-config')
let config = require(resolve(rootDir, 'nuxt.config.js'))
config.rootDir = rootDir
config.dev = false
config.runBuild = true
nuxt = new Nuxt(config)
await nuxt.ready()
})