mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
Move to fixtures and add generate test
This commit is contained in:
parent
a7e2a87ee4
commit
a03b13c2c1
@ -37,7 +37,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "nyc ava test/",
|
"test": "nyc ava test/",
|
||||||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
"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",
|
"build": "webpack",
|
||||||
"watch": "webpack --watch",
|
"watch": "webpack --watch",
|
||||||
"precommit": "npm run lint",
|
"precommit": "npm run lint",
|
||||||
|
23
test/basic.generate.test.js
Normal file
23
test/basic.generate.test.js
Normal 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>'))
|
||||||
|
})
|
@ -7,19 +7,17 @@ let nuxt = null
|
|||||||
let server = null
|
let server = null
|
||||||
|
|
||||||
// Init nuxt.js and create server listening on localhost:4000
|
// 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 Nuxt = require('../')
|
||||||
const options = {
|
const options = {
|
||||||
rootDir: resolve(__dirname, 'basic'),
|
rootDir: resolve(__dirname, 'fixtures/basic'),
|
||||||
dev: false
|
dev: false
|
||||||
}
|
}
|
||||||
nuxt = new Nuxt(options)
|
nuxt = new Nuxt(options)
|
||||||
return nuxt.build()
|
await nuxt.build()
|
||||||
.then(function () {
|
|
||||||
server = new nuxt.Server(nuxt)
|
server = new nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
test('/stateless', async t => {
|
test('/stateless', async t => {
|
||||||
const { html } = await nuxt.renderRoute('/stateless')
|
const { html } = await nuxt.renderRoute('/stateless')
|
||||||
|
@ -7,19 +7,17 @@ let nuxt = null
|
|||||||
let server = null
|
let server = null
|
||||||
|
|
||||||
// Init nuxt.js and create server listening on localhost:4000
|
// 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 Nuxt = require('../')
|
||||||
const options = {
|
const options = {
|
||||||
rootDir: resolve(__dirname, 'children'),
|
rootDir: resolve(__dirname, 'fixtures/children'),
|
||||||
dev: false
|
dev: false
|
||||||
}
|
}
|
||||||
nuxt = new Nuxt(options)
|
nuxt = new Nuxt(options)
|
||||||
return nuxt.build()
|
await nuxt.build()
|
||||||
.then(function () {
|
|
||||||
server = new nuxt.Server(nuxt)
|
server = new nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
test('/parent', async t => {
|
test('/parent', async t => {
|
||||||
const { html } = await nuxt.renderRoute('/parent')
|
const { html } = await nuxt.renderRoute('/parent')
|
||||||
|
@ -7,19 +7,17 @@ let nuxt = null
|
|||||||
let server = null
|
let server = null
|
||||||
|
|
||||||
// Init nuxt.js and create server listening on localhost:4000
|
// 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 Nuxt = require('../')
|
||||||
const options = {
|
const options = {
|
||||||
rootDir: resolve(__dirname, 'error'),
|
rootDir: resolve(__dirname, 'fixtures/error'),
|
||||||
dev: false
|
dev: false
|
||||||
}
|
}
|
||||||
nuxt = new Nuxt(options)
|
nuxt = new Nuxt(options)
|
||||||
return nuxt.build()
|
await nuxt.build()
|
||||||
.then(function () {
|
|
||||||
server = new nuxt.Server(nuxt)
|
server = new nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
test('/ should display an error', async t => {
|
test('/ should display an error', async t => {
|
||||||
try {
|
try {
|
||||||
|
@ -15,10 +15,10 @@ test('Nuxt.js Instance', t => {
|
|||||||
t.is(typeof nuxt.generate, 'function')
|
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({
|
const nuxt = new Nuxt({
|
||||||
dev: false,
|
dev: false,
|
||||||
rootDir: resolve(__dirname, 'empty')
|
rootDir: resolve(__dirname, 'fixtures/empty')
|
||||||
})
|
})
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
var oldExit = process.exit
|
var oldExit = process.exit
|
||||||
@ -36,11 +36,12 @@ 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({
|
const nuxt = new Nuxt({
|
||||||
dev: false,
|
dev: false,
|
||||||
rootDir: resolve(__dirname, 'empty', 'pages')
|
rootDir: resolve(__dirname, 'empty', 'pages')
|
||||||
})
|
})
|
||||||
|
return new Promise((resolve) => {
|
||||||
var oldExit = process.exit
|
var oldExit = process.exit
|
||||||
var oldCE = console.error // eslint-disable-line no-console
|
var oldCE = console.error // eslint-disable-line no-console
|
||||||
var _log = ''
|
var _log = ''
|
||||||
@ -54,12 +55,14 @@ test('Fail to build when no pages/ directory but is in the parent', async t => {
|
|||||||
}
|
}
|
||||||
nuxt.build()
|
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({
|
const nuxt = new Nuxt({
|
||||||
dev: false,
|
dev: false,
|
||||||
rootDir: resolve(__dirname)
|
rootDir: resolve(__dirname)
|
||||||
})
|
})
|
||||||
|
return new Promise((resolve) => {
|
||||||
var oldExit = process.exit
|
var oldExit = process.exit
|
||||||
var oldCE = console.error // eslint-disable-line no-console
|
var oldCE = console.error // eslint-disable-line no-console
|
||||||
var _log = ''
|
var _log = ''
|
||||||
@ -73,3 +76,4 @@ test('Fail to build when no pages/ directory', async t => {
|
|||||||
}
|
}
|
||||||
nuxt.build()
|
nuxt.build()
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user