From 754fcc2f59fce1ac324b362c049030e222d2fc23 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 13 Jun 2017 00:45:28 +0430 Subject: [PATCH] update tests --- test/module.test.js | 8 +++---- test/utils.test.js | 56 ++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/test/module.test.js b/test/module.test.js index 58e15de574..59fd0c4ee3 100755 --- a/test/module.test.js +++ b/test/module.test.js @@ -1,6 +1,7 @@ import test from 'ava' -import { resolve } from 'path' +import { resolve, normalize } from 'path' import rp from 'request-promise-native' +import Nuxt from '..' const port = 4006 const url = (route) => 'http://localhost:' + port + route @@ -8,11 +9,8 @@ const url = (route) => 'http://localhost:' + port + route let nuxt = null let server = null -const wp = p => /^win/.test(process.platform) ? p.replace(/[\\/]/g, '\\\\') : p - // Init nuxt.js and create server listening on localhost:4000 test.before('Init Nuxt.js', async t => { - const Nuxt = require('../') const rootDir = resolve(__dirname, 'fixtures/module') let config = require(resolve(rootDir, 'nuxt.config.js')) config.rootDir = rootDir @@ -28,7 +26,7 @@ test('Vendor', async t => { }) test('Plugin', async t => { - t.true(nuxt.options.plugins[0].src.includes(wp('fixtures/module/.nuxt/basic.reverse.')), 'plugin added to config') + t.true(nuxt.options.plugins[0].src.includes(normalize('fixtures/module/.nuxt/basic.reverse.')), 'plugin added to config') const { html } = await nuxt.renderRoute('/') t.true(html.includes('

TXUN

'), 'plugin works') }) diff --git a/test/utils.test.js b/test/utils.test.js index 71a269a27f..acd0b20c18 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -1,15 +1,15 @@ import test from 'ava' import ansiHTML from 'ansi-html' -import Nuxt from '..' +import { Utils } from '..' test('encodeHtml', t => { const html = '

Hello

' - t.is(Nuxt.utils.encodeHtml(html), '<h1>Hello</h1>') + t.is(Utils.encodeHtml(html), '<h1>Hello</h1>') }) test('getContext', t => { - let ctx = Nuxt.utils.getContext({ a: 1 }, { b: 2 }) - t.is(Nuxt.utils.getContext.length, 2) + let ctx = Utils.getContext({ a: 1 }, { b: 2 }) + t.is(Utils.getContext.length, 2) t.is(typeof ctx.req, 'object') t.is(typeof ctx.res, 'object') t.is(ctx.req.a, 1) @@ -17,29 +17,29 @@ test('getContext', t => { }) test('setAnsiColors', t => { - Nuxt.utils.setAnsiColors(ansiHTML) + Utils.setAnsiColors(ansiHTML) t.pass() }) test('waitFor', async (t) => { let s = Date.now() - await Nuxt.utils.waitFor(100) + await Utils.waitFor(100) t.true(Date.now() - s >= 100) - await Nuxt.utils.waitFor() + await Utils.waitFor() }) test('urlJoin', t => { - t.is(Nuxt.utils.urlJoin('test', '/about'), 'test/about') + t.is(Utils.urlJoin('test', '/about'), 'test/about') }) test('promisifyRoute (array)', t => { const array = [1] - const promise = Nuxt.utils.promisifyRoute(array) + const promise = Utils.promisifyRoute(array) t.is(typeof promise, 'object') return promise - .then((res) => { - t.is(res, array) - }) + .then((res) => { + t.is(res, array) + }) }) test('promisifyRoute (fn => array)', t => { @@ -47,12 +47,12 @@ test('promisifyRoute (fn => array)', t => { const fn = function () { return array } - const promise = Nuxt.utils.promisifyRoute(fn) + const promise = Utils.promisifyRoute(fn) t.is(typeof promise, 'object') return promise - .then((res) => { - t.is(res, array) - }) + .then((res) => { + t.is(res, array) + }) }) test('promisifyRoute (fn => promise)', t => { @@ -62,24 +62,24 @@ test('promisifyRoute (fn => promise)', t => { resolve(array) }) } - const promise = Nuxt.utils.promisifyRoute(fn) + const promise = Utils.promisifyRoute(fn) t.is(typeof promise, 'object') return promise - .then((res) => { - t.is(res, array) - }) + .then((res) => { + t.is(res, array) + }) }) test('promisifyRoute (fn(cb) with error)', t => { const fn = function (cb) { cb(new Error('Error here')) } - const promise = Nuxt.utils.promisifyRoute(fn) + const promise = Utils.promisifyRoute(fn) t.is(typeof promise, 'object') return promise - .catch((e) => { - t.is(e.message, 'Error here') - }) + .catch((e) => { + t.is(e.message, 'Error here') + }) }) test('promisifyRoute (fn(cb) with result)', t => { @@ -87,10 +87,10 @@ test('promisifyRoute (fn(cb) with result)', t => { const fn = function (cb) { cb(null, array) } - const promise = Nuxt.utils.promisifyRoute(fn) + const promise = Utils.promisifyRoute(fn) t.is(typeof promise, 'object') return promise - .then((res) => { - t.is(res, array) - }) + .then((res) => { + t.is(res, array) + }) })