Move to fixtures and add generate test

This commit is contained in:
Sébastien Chopin 2016-12-20 20:44:42 +01:00
parent a7e2a87ee4
commit a03b13c2c1
21 changed files with 71 additions and 50 deletions

View File

@ -37,7 +37,7 @@
"scripts": {
"test": "nyc ava test/",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"lint": "eslint --ext .js,.vue bin lib pages test --ignore-pattern lib/app",
"lint": "eslint --ext .js,.vue bin lib pages test/*.js --ignore-pattern lib/app",
"build": "webpack",
"watch": "webpack --watch",
"precommit": "npm run lint",

View File

@ -0,0 +1,23 @@
import test from 'ava'
import { resolve } from 'path'
import pify from 'pify'
import fs from 'fs'
const readFile = pify(fs.readFile)
let nuxt = null
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', async t => {
const Nuxt = require('../')
const options = {
rootDir: resolve(__dirname, 'fixtures/basic'),
dev: false
}
nuxt = new Nuxt(options)
await nuxt.generate()
})
test('/stateless', async t => {
const html = await readFile(resolve(__dirname, 'fixtures/basic/dist/stateless/index.html'), 'utf8')
t.true(html.includes('<h1>My component!</h1>'))
})

View File

@ -7,18 +7,16 @@ let nuxt = null
let server = null
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', t => {
test.before('Init Nuxt.js', async t => {
const Nuxt = require('../')
const options = {
rootDir: resolve(__dirname, 'basic'),
rootDir: resolve(__dirname, 'fixtures/basic'),
dev: false
}
nuxt = new Nuxt(options)
return nuxt.build()
.then(function () {
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')
})
await nuxt.build()
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')
})
test('/stateless', async t => {

View File

@ -7,18 +7,16 @@ let nuxt = null
let server = null
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', t => {
test.before('Init Nuxt.js', async t => {
const Nuxt = require('../')
const options = {
rootDir: resolve(__dirname, 'children'),
rootDir: resolve(__dirname, 'fixtures/children'),
dev: false
}
nuxt = new Nuxt(options)
return nuxt.build()
.then(function () {
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')
})
await nuxt.build()
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')
})
test('/parent', async t => {

View File

@ -7,18 +7,16 @@ let nuxt = null
let server = null
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', t => {
test.before('Init Nuxt.js', async t => {
const Nuxt = require('../')
const options = {
rootDir: resolve(__dirname, 'error'),
rootDir: resolve(__dirname, 'fixtures/error'),
dev: false
}
nuxt = new Nuxt(options)
return nuxt.build()
.then(function () {
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')
})
await nuxt.build()
server = new nuxt.Server(nuxt)
server.listen(port, 'localhost')
})
test('/ should display an error', async t => {

View File

@ -15,10 +15,10 @@ test('Nuxt.js Instance', t => {
t.is(typeof nuxt.generate, 'function')
})
test('Fail when build not done and try to render', async t => {
test.serial('Fail when build not done and try to render', t => {
const nuxt = new Nuxt({
dev: false,
rootDir: resolve(__dirname, 'empty')
rootDir: resolve(__dirname, 'fixtures/empty')
})
return new Promise((resolve) => {
var oldExit = process.exit
@ -36,40 +36,44 @@ test('Fail when build not done and try to render', async t => {
})
})
test('Fail to build when no pages/ directory but is in the parent', async t => {
test.serial('Fail to build when no pages/ directory but is in the parent', t => {
const nuxt = new Nuxt({
dev: false,
rootDir: resolve(__dirname, 'empty', 'pages')
})
var oldExit = process.exit
var oldCE = console.error // eslint-disable-line no-console
var _log = ''
console.error = (s) => { _log += s } // eslint-disable-line no-console
process.exit = (code) => {
process.exit = oldExit
console.error = oldCE // eslint-disable-line no-console
t.is(code, 1)
t.true(_log.includes('No `pages` directory found. Did you mean to run `nuxt` in the parent (`../`) directory?'))
resolve()
}
nuxt.build()
return new Promise((resolve) => {
var oldExit = process.exit
var oldCE = console.error // eslint-disable-line no-console
var _log = ''
console.error = (s) => { _log += s } // eslint-disable-line no-console
process.exit = (code) => {
process.exit = oldExit
console.error = oldCE // eslint-disable-line no-console
t.is(code, 1)
t.true(_log.includes('No `pages` directory found. Did you mean to run `nuxt` in the parent (`../`) directory?'))
resolve()
}
nuxt.build()
})
})
test('Fail to build when no pages/ directory', async t => {
test.serial('Fail to build when no pages/ directory', t => {
const nuxt = new Nuxt({
dev: false,
rootDir: resolve(__dirname)
})
var oldExit = process.exit
var oldCE = console.error // eslint-disable-line no-console
var _log = ''
console.error = (s) => { _log += s } // eslint-disable-line no-console
process.exit = (code) => {
process.exit = oldExit
console.error = oldCE // eslint-disable-line no-console
t.is(code, 1)
t.true(_log.includes('Couldn\'t find a `pages` directory. Please create one under the project root'))
resolve()
}
nuxt.build()
return new Promise((resolve) => {
var oldExit = process.exit
var oldCE = console.error // eslint-disable-line no-console
var _log = ''
console.error = (s) => { _log += s } // eslint-disable-line no-console
process.exit = (code) => {
process.exit = oldExit
console.error = oldCE // eslint-disable-line no-console
t.is(code, 1)
t.true(_log.includes('Couldn\'t find a `pages` directory. Please create one under the project root'))
resolve()
}
nuxt.build()
})
})