Update test

This commit is contained in:
Sébastien Chopin 2017-05-21 19:18:26 +02:00
parent 2247097b64
commit c5b5913402
20 changed files with 74 additions and 14 deletions

View File

@ -1,7 +1,7 @@
import test from 'ava'
import { resolve } from 'path'
import rp from 'request-promise-native'
const port = 4005
const port = 4000
const url = (route) => 'http://localhost:' + port + route
let nuxt = null
@ -38,5 +38,5 @@ test('/_nuxt/test.hot-update.json should returns empty html', async t => {
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => {
server.close()
nuxt.close()
nuxt.close(() => {})
})

View File

@ -4,7 +4,7 @@ import http from 'http'
import serveStatic from 'serve-static'
import finalhandler from 'finalhandler'
import rp from 'request-promise-native'
const port = 4003
const port = 4001
const url = (route) => 'http://localhost:' + port + route
let nuxt = null

View File

@ -3,7 +3,7 @@ import { resolve } from 'path'
import rp from 'request-promise-native'
import stdMocks from 'std-mocks'
const port = 4000
const port = 4002
const url = (route) => 'http://localhost:' + port + route
let nuxt = null

View File

@ -1,6 +1,6 @@
import test from 'ava'
import { resolve } from 'path'
const port = 4001
const port = 4003
// const url = (route) => 'http://localhost:' + port + route
let nuxt = null

View File

@ -4,7 +4,6 @@ import fs from 'fs'
import pify from 'pify'
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 = await new Nuxt({

View File

@ -1,6 +1,6 @@
import test from 'ava'
import { resolve } from 'path'
const port = 4002
const port = 4004
const url = (route) => 'http://localhost:' + port + route
let nuxt = null

View File

@ -8,12 +8,12 @@ module.exports = function basicModule (options, resolve) {
this.addPlugin(path.resolve(__dirname, 'reverse.js'))
// Extend build
this.extendBuild(({isClient, isServer}) => {
this.extendBuild((config, { isClient, isServer }) => {
// Do nothing!
})
// Extend build again
this.extendBuild(({isClient, isServer}) => {
this.extendBuild((config, { isClient, isServer }) => {
// Do nothing!
})

View File

@ -10,9 +10,11 @@ module.exports = function middlewareModule (options) {
})
// Add plain middleware
this.addServerMiddleware((req, res, next) => {
res.setHeader('x-nuxt', 'hello')
next()
})
// Resolve
// Add file middleware
this.addServerMiddleware('~/modules/middleware/midd1')
resolve()
})
}

View File

@ -0,0 +1,4 @@
module.exports = function (req, res, next) {
res.setHeader('x-midd-1', 'ok')
next()
}

View File

@ -0,0 +1,4 @@
module.exports = function (req, res, next) {
res.setHeader('x-midd-2', 'ok')
next()
}

View File

@ -0,0 +1,11 @@
const path = require('path')
module.exports = function () {
// Disable parsing pages/
this.nuxt.createRoutes = () => {}
// Add /api endpoint
this.addTemplate({
fileName: 'router.js',
src: path.resolve(this.nuxt.srcDir, 'router.js')
})
}

View File

@ -1,6 +1,11 @@
module.exports = {
loading: true,
modules: [
'~modules/basic',
'~modules/middleware'
'~/modules/middleware',
'./modules/template'
],
serverMiddleware: [
'./modules/middleware/midd2'
]
}

22
test/fixtures/module/router.js vendored Normal file
View File

@ -0,0 +1,22 @@
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export function createRouter () {
return new Router({
mode: 'history',
routes: [
{
path: "/",
component: require('~/views/index.vue'),
name: "index"
},
{
path: "/about",
component: require('~/views/about.vue'),
name: "about"
}
]
})
}

6
test/fixtures/module/views/about.vue vendored Normal file
View File

@ -0,0 +1,6 @@
<template>
<div>
<h1>About page</h1>
<nuxt-link to="/">Home page</nuxt-link>
</div>
</template>

View File

@ -1,5 +1,6 @@
<template>
<div>
<h1>{{ $reverseStr('NUXT') }}</h1>
<nuxt-link to="/about">About page</nuxt-link>
</div>
</template>

View File

@ -0,0 +1,3 @@
export default function () {
// NOOP!
}

View File

@ -1,6 +1,8 @@
module.exports = {
srcDir: __dirname,
router: {
base: '/test/',
middleware: 'noop',
extendRoutes (routes) {
routes.push({
name: 'about-bis',
@ -9,7 +11,7 @@ module.exports = {
})
}
},
cache: true,
transition: 'test',
offline: true,
plugins: [
'~plugins/test.js',

View File

@ -2,7 +2,7 @@ import test from 'ava'
import { resolve } from 'path'
import rp from 'request-promise-native'
const port = 4000
const port = 4005
const url = (route) => 'http://localhost:' + port + route
let nuxt = null

View File

@ -32,6 +32,7 @@ test('waitFor', async (t) => {
let s = Date.now()
await utils.waitFor(100)
t.true(Date.now() - s >= 100)
await utils.waitFor()
})
test('urlJoin', t => {

View File

@ -1,6 +1,6 @@
import test from 'ava'
import { resolve } from 'path'
const port = 4004
const port = 4006
const url = (route) => 'http://localhost:' + port + route
let nuxt = null