update tests

This commit is contained in:
Pooya Parsa 2017-06-13 00:45:28 +04:30
parent 84350e59c5
commit 754fcc2f59
2 changed files with 31 additions and 33 deletions

View File

@ -1,6 +1,7 @@
import test from 'ava' import test from 'ava'
import { resolve } from 'path' import { resolve, normalize } from 'path'
import rp from 'request-promise-native' import rp from 'request-promise-native'
import Nuxt from '..'
const port = 4006 const port = 4006
const url = (route) => 'http://localhost:' + port + route const url = (route) => 'http://localhost:' + port + route
@ -8,11 +9,8 @@ const url = (route) => 'http://localhost:' + port + route
let nuxt = null let nuxt = null
let server = 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 // Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', async t => { test.before('Init Nuxt.js', async t => {
const Nuxt = require('../')
const rootDir = resolve(__dirname, 'fixtures/module') const rootDir = resolve(__dirname, 'fixtures/module')
let config = require(resolve(rootDir, 'nuxt.config.js')) let config = require(resolve(rootDir, 'nuxt.config.js'))
config.rootDir = rootDir config.rootDir = rootDir
@ -28,7 +26,7 @@ test('Vendor', async t => {
}) })
test('Plugin', 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('/') const { html } = await nuxt.renderRoute('/')
t.true(html.includes('<h1>TXUN</h1>'), 'plugin works') t.true(html.includes('<h1>TXUN</h1>'), 'plugin works')
}) })

View File

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