From c5b5913402cfcf770ecc345a1fe3b9e14382fb5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Sun, 21 May 2017 19:18:26 +0200 Subject: [PATCH] Update test --- test/basic.dev.test.js | 4 ++-- test/basic.generate.test.js | 2 +- test/basic.test.js | 2 +- test/children.test.js | 2 +- test/dynamic-routes.test.js | 1 - test/error.test.js | 2 +- test/fixtures/module/modules/basic/index.js | 4 ++-- .../module/modules/middleware/index.js | 4 +++- .../module/modules/middleware/midd1.js | 4 ++++ .../module/modules/middleware/midd2.js | 4 ++++ .../fixtures/module/modules/template/index.js | 11 ++++++++++ test/fixtures/module/nuxt.config.js | 7 +++++- test/fixtures/module/router.js | 22 +++++++++++++++++++ test/fixtures/module/views/about.vue | 6 +++++ .../module/{pages => views}/index.vue | 1 + test/fixtures/with-config/middleware/noop.js | 3 +++ test/fixtures/with-config/nuxt.config.js | 4 +++- test/module.test.js | 2 +- test/utils.test.js | 1 + test/with-config.test.js | 2 +- 20 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 test/fixtures/module/modules/middleware/midd1.js create mode 100644 test/fixtures/module/modules/middleware/midd2.js create mode 100644 test/fixtures/module/modules/template/index.js create mode 100644 test/fixtures/module/router.js create mode 100644 test/fixtures/module/views/about.vue rename test/fixtures/module/{pages => views}/index.vue (61%) create mode 100644 test/fixtures/with-config/middleware/noop.js diff --git a/test/basic.dev.test.js b/test/basic.dev.test.js index ae9e528f2c..b66e74fcbb 100644 --- a/test/basic.dev.test.js +++ b/test/basic.dev.test.js @@ -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(() => {}) }) diff --git a/test/basic.generate.test.js b/test/basic.generate.test.js index 737de6f6d8..d771ebc167 100644 --- a/test/basic.generate.test.js +++ b/test/basic.generate.test.js @@ -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 diff --git a/test/basic.test.js b/test/basic.test.js index 6dfe898c03..ed5d7f3de2 100755 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -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 diff --git a/test/children.test.js b/test/children.test.js index fd6a73396b..2363392832 100644 --- a/test/children.test.js +++ b/test/children.test.js @@ -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 diff --git a/test/dynamic-routes.test.js b/test/dynamic-routes.test.js index 3613144821..126d433f88 100644 --- a/test/dynamic-routes.test.js +++ b/test/dynamic-routes.test.js @@ -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({ diff --git a/test/error.test.js b/test/error.test.js index 400f0f8de2..e78f36e8da 100644 --- a/test/error.test.js +++ b/test/error.test.js @@ -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 diff --git a/test/fixtures/module/modules/basic/index.js b/test/fixtures/module/modules/basic/index.js index 5e1513a782..1fe62535ac 100755 --- a/test/fixtures/module/modules/basic/index.js +++ b/test/fixtures/module/modules/basic/index.js @@ -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! }) diff --git a/test/fixtures/module/modules/middleware/index.js b/test/fixtures/module/modules/middleware/index.js index 2c5da9afaa..f747712f6e 100755 --- a/test/fixtures/module/modules/middleware/index.js +++ b/test/fixtures/module/modules/middleware/index.js @@ -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() }) } diff --git a/test/fixtures/module/modules/middleware/midd1.js b/test/fixtures/module/modules/middleware/midd1.js new file mode 100644 index 0000000000..4c109b5637 --- /dev/null +++ b/test/fixtures/module/modules/middleware/midd1.js @@ -0,0 +1,4 @@ +module.exports = function (req, res, next) { + res.setHeader('x-midd-1', 'ok') + next() +} \ No newline at end of file diff --git a/test/fixtures/module/modules/middleware/midd2.js b/test/fixtures/module/modules/middleware/midd2.js new file mode 100644 index 0000000000..95ae3940dc --- /dev/null +++ b/test/fixtures/module/modules/middleware/midd2.js @@ -0,0 +1,4 @@ +module.exports = function (req, res, next) { + res.setHeader('x-midd-2', 'ok') + next() +} \ No newline at end of file diff --git a/test/fixtures/module/modules/template/index.js b/test/fixtures/module/modules/template/index.js new file mode 100644 index 0000000000..7e85b80d56 --- /dev/null +++ b/test/fixtures/module/modules/template/index.js @@ -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') + }) +} diff --git a/test/fixtures/module/nuxt.config.js b/test/fixtures/module/nuxt.config.js index 22c1332ca2..9272e7ca93 100755 --- a/test/fixtures/module/nuxt.config.js +++ b/test/fixtures/module/nuxt.config.js @@ -1,6 +1,11 @@ module.exports = { + loading: true, modules: [ '~modules/basic', - '~modules/middleware' + '~/modules/middleware', + './modules/template' + ], + serverMiddleware: [ + './modules/middleware/midd2' ] } diff --git a/test/fixtures/module/router.js b/test/fixtures/module/router.js new file mode 100644 index 0000000000..629c9d4ffc --- /dev/null +++ b/test/fixtures/module/router.js @@ -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" + } + ] + }) +} diff --git a/test/fixtures/module/views/about.vue b/test/fixtures/module/views/about.vue new file mode 100644 index 0000000000..93009e1b3e --- /dev/null +++ b/test/fixtures/module/views/about.vue @@ -0,0 +1,6 @@ + diff --git a/test/fixtures/module/pages/index.vue b/test/fixtures/module/views/index.vue similarity index 61% rename from test/fixtures/module/pages/index.vue rename to test/fixtures/module/views/index.vue index 33eaab7339..a3da52e442 100755 --- a/test/fixtures/module/pages/index.vue +++ b/test/fixtures/module/views/index.vue @@ -1,5 +1,6 @@ diff --git a/test/fixtures/with-config/middleware/noop.js b/test/fixtures/with-config/middleware/noop.js new file mode 100644 index 0000000000..26f7210f3d --- /dev/null +++ b/test/fixtures/with-config/middleware/noop.js @@ -0,0 +1,3 @@ +export default function () { + // NOOP! +} \ No newline at end of file diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index d69accdc5c..ae0609669c 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -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', diff --git a/test/module.test.js b/test/module.test.js index 8d388669a8..5959316003 100755 --- a/test/module.test.js +++ b/test/module.test.js @@ -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 diff --git a/test/utils.test.js b/test/utils.test.js index 25e0cb45db..052db5a900 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -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 => { diff --git a/test/with-config.test.js b/test/with-config.test.js index 5d2b3a1294..2025554f24 100644 --- a/test/with-config.test.js +++ b/test/with-config.test.js @@ -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