[tests] await for nuxt initialization

Nuxt constructor is now returning a promise, so we should await it before using
This commit is contained in:
Pooya Parsa 2017-05-12 00:19:02 +04:30
parent d57ea4de88
commit b0b9101a8d
11 changed files with 20 additions and 6323 deletions

View File

@ -13,7 +13,7 @@ test.before('Init Nuxt.js', async t => {
rootDir: resolve(__dirname, 'fixtures/basic'),
dev: true
}
nuxt = new Nuxt(options)
nuxt = await new Nuxt(options)
await nuxt.build()
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')

View File

@ -1,7 +1,7 @@
import test from 'ava'
import { resolve } from 'path'
test('Fail with routes() which throw an error', t => {
test('Fail with routes() which throw an error', async t => {
const Nuxt = require('../')
const options = {
rootDir: resolve(__dirname, 'fixtures/basic'),
@ -14,7 +14,7 @@ test('Fail with routes() which throw an error', t => {
}
}
}
const nuxt = new Nuxt(options)
const nuxt = await new Nuxt(options)
return new Promise((resolve) => {
var oldExit = process.exit
var oldCE = console.error // eslint-disable-line no-console

View File

@ -17,7 +17,7 @@ test.before('Init Nuxt.js', async t => {
let config = require(resolve(rootDir, 'nuxt.config.js'))
config.rootDir = rootDir
config.dev = false
nuxt = new Nuxt(config)
nuxt = await new Nuxt(config)
try {
await nuxt.generate() // throw an error (of /validate route)
} catch (err) {}

View File

@ -14,7 +14,7 @@ test.before('Init Nuxt.js', async t => {
rootDir: resolve(__dirname, 'fixtures/basic'),
dev: false
}
nuxt = new Nuxt(options)
nuxt = await new Nuxt(options)
await nuxt.build()
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')

View File

@ -13,7 +13,7 @@ test.before('Init Nuxt.js', async t => {
rootDir: resolve(__dirname, 'fixtures/children'),
dev: false
}
nuxt = new Nuxt(options)
nuxt = await new Nuxt(options)
await nuxt.build()
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')

View File

@ -7,7 +7,7 @@ const readFile = pify(fs.readFile)
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', async t => {
const Nuxt = require('../')
const nuxt = new Nuxt({
const nuxt = await new Nuxt({
rootDir: resolve(__dirname, 'fixtures/dynamic-routes'),
dev: false
})

View File

@ -13,7 +13,7 @@ test.before('Init Nuxt.js', async t => {
rootDir: resolve(__dirname, 'fixtures/error'),
dev: false
}
nuxt = new Nuxt(options)
nuxt = await new Nuxt(options)
await nuxt.build()
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')

View File

@ -7,16 +7,16 @@ test('Nuxt.js Class', t => {
t.is(typeof Nuxt, 'function')
})
test('Nuxt.js Instance', t => {
const nuxt = new Nuxt()
test('Nuxt.js Instance', async t => {
const nuxt = await new Nuxt()
t.is(typeof nuxt, 'object')
t.is(nuxt.dev, true)
t.is(typeof nuxt.build, 'function')
t.is(typeof nuxt.generate, 'function')
})
test.serial('Fail when build not done and try to render', t => {
const nuxt = new Nuxt({
test.serial('Fail when build not done and try to render', async t => {
const nuxt = await new Nuxt({
dev: false,
rootDir: resolve(__dirname, 'fixtures/empty')
})
@ -36,8 +36,8 @@ test.serial('Fail when build not done and try to render', t => {
})
})
test.serial('Fail to build when no pages/ directory but is in the parent', t => {
const nuxt = new Nuxt({
test.serial('Fail to build when no pages/ directory but is in the parent', async t => {
const nuxt = await new Nuxt({
dev: false,
rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages')
})
@ -57,8 +57,8 @@ test.serial('Fail to build when no pages/ directory but is in the parent', t =>
})
})
test.serial('Fail to build when no pages/ directory', t => {
const nuxt = new Nuxt({
test.serial('Fail to build when no pages/ directory', async t => {
const nuxt = await new Nuxt({
dev: false,
rootDir: resolve(__dirname)
})

View File

@ -5,7 +5,7 @@ let utils
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', async t => {
const Nuxt = require('../')
let nuxt = new Nuxt({ dev: false })
let nuxt = await new Nuxt({ dev: false })
utils = nuxt.utils
})

View File

@ -13,7 +13,7 @@ test.before('Init Nuxt.js', async t => {
let config = require(resolve(rootDir, 'nuxt.config.js'))
config.rootDir = rootDir
config.dev = false
nuxt = new Nuxt(config)
nuxt = await new Nuxt(config)
await nuxt.build()
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')
@ -96,11 +96,11 @@ test.after('Closing server and nuxt.js', t => {
nuxt.close()
})
test.after('Should be able to start Nuxt with build done', t => {
test.after('Should be able to start Nuxt with build done', async t => {
const Nuxt = require('../')
const rootDir = resolve(__dirname, 'fixtures/with-config')
let config = require(resolve(rootDir, 'nuxt.config.js'))
config.rootDir = rootDir
config.dev = false
nuxt = new Nuxt(config)
nuxt = await new Nuxt(config)
})

6303
yarn.lock

File diff suppressed because it is too large Load Diff