Merge pull request #2382 from clarkdo/sinon_console

test: use sinon instead of std-mocks
This commit is contained in:
Sébastien Chopin 2017-12-15 11:22:50 +01:00 committed by GitHub
commit 126b58be00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 58 deletions

View File

@ -141,7 +141,6 @@
"request": "^2.83.0",
"request-promise-native": "^1.0.5",
"sinon": "^4.1.2",
"std-mocks": "^1.0.1",
"uglify-js": "^3.2.2"
},
"collective": {

View File

@ -1,7 +1,6 @@
import test from 'ava'
import { resolve } from 'path'
import stdMocks from 'std-mocks'
// import rp from 'request-promise-native'
import { interceptLog, release } from './helpers/console'
import { Nuxt, Builder, Utils } from '..'
import { truncateSync, readFileSync, writeFileSync } from 'fs'
@ -32,26 +31,26 @@ test.before('Init Nuxt.js', async t => {
})
test('remove mixins in live reloading', async t => {
stdMocks.use()
const logSpy = await interceptLog()
await nuxt.renderRoute(url('/'))
t.true(stdMocks.flush().stdout.some(v => v === 'I am mixin\n'))
t.true(logSpy.calledWith('I am mixin'))
truncateSync(pluginPath)
await new Promise(async (resolve, reject) => {
let waitTimes = 0
while (!stdMocks.flush().stdout.some(v => ~v.indexOf('Compiled successfully'))) {
await Utils.waitFor(100) && waitTimes++
if (waitTimes === 20) {
reject(Error('Dev server doesn\'t reload after 2000ms'))
while (logSpy.neverCalledWithMatch(/Compiled successfully/)) {
if (waitTimes++ >= 20) {
t.fail('Dev server doesn\'t reload after 2000ms')
reject(Error())
}
await Utils.waitFor(100)
}
resolve()
})
logSpy.reset()
await nuxt.renderRoute(url('/'))
t.false(stdMocks.flush().stdout.some(v => v === 'I am mixin\n'))
stdMocks.restore()
t.true(logSpy.neverCalledWith('I am mixin'))
release()
})
test('/stateless', async t => {

View File

@ -1,5 +1,5 @@
import test from 'ava'
import stdMocks from 'std-mocks'
import { interceptWarn, release } from './helpers/console'
import { resolve } from 'path'
import rp from 'request-promise-native'
import { Nuxt, Builder } from '..'
@ -9,7 +9,7 @@ const url = (route) => 'http://localhost:' + port + route
let nuxt = null
let builder = null
let builtErr = null
let buildLog = null
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', async t => {
@ -20,29 +20,24 @@ test.before('Init Nuxt.js', async t => {
nuxt = new Nuxt(config)
builder = new Builder(nuxt)
stdMocks.use({
stdout: false,
stderr: true
})
buildLog = await interceptWarn()
await builder.build()
stdMocks.restore()
builtErr = stdMocks.flush().stderr
release()
await nuxt.listen(port, 'localhost')
})
test('Deprecated: context.isServer and context.isClient', async t => {
stdMocks.use()
const logSpy = await interceptWarn()
await rp(url('/'))
stdMocks.restore()
const output = stdMocks.flush()
t.true(output.stderr.length === 2)
t.true(logSpy.calledWith('context.isServer has been deprecated, please use process.server instead.'))
t.true(logSpy.calledWith('context.isClient has been deprecated, please use process.client instead.'))
t.true(logSpy.calledTwice)
release()
})
test('Deprecated: dev in build.extend()', async t => {
const deprecatedMsg = 'dev has been deprecated in build.extend(), please use isDev'
const errors = builtErr.filter(value => value.indexOf(deprecatedMsg) === 0)
t.true(errors.length === 2)
t.true(buildLog.withArgs('dev has been deprecated in build.extend(), please use isDev').calledTwice)
})
test('Deprecated: nuxt.plugin()', async t => {

View File

@ -2,8 +2,8 @@ import { promisify } from 'util'
import test from 'ava'
import { resolve } from 'path'
import fs from 'fs'
import stdMocks from 'std-mocks'
import { Nuxt, Builder } from '..'
import { interceptLog, release } from './helpers/console'
const readFile = promisify(fs.readFile)
const rootDir = resolve(__dirname, './fixtures/dll')
@ -34,12 +34,10 @@ test('Check vue-meta cache', checkCache('vue-meta'))
test('Check vue-router cache', checkCache('vue-router'))
test('Build with DllReferencePlugin', async t => {
stdMocks.use()
const logSpy = await interceptLog()
await new Builder(nuxt).build()
stdMocks.restore()
const output = stdMocks.flush()
const dllLog = output.stdout.filter(value => value === 'Using dll for 3 libs\n')
t.true(dllLog.length === 1)
release()
t.true(logSpy.withArgs('Using dll for 3 libs').calledOnce)
})
// Close server and ask nuxt to stop listening to file changes

View File

@ -1,8 +1,8 @@
import test from 'ava'
import stdMocks from 'std-mocks'
import { resolve, normalize } from 'path'
import rp from 'request-promise-native'
import { Nuxt, Builder } from '..'
import { interceptError, release } from './helpers/console'
const port = 4006
const url = (route) => 'http://localhost:' + port + route
@ -20,13 +20,9 @@ test.before('Init Nuxt.js', async t => {
nuxt = new Nuxt(config)
builder = new Builder(nuxt)
stdMocks.use({
stdout: false,
stderr: true
})
builtErr = await interceptError()
await builder.build()
stdMocks.restore()
builtErr = stdMocks.flush().stderr
release()
await nuxt.listen(port, 'localhost')
})
@ -59,8 +55,7 @@ test('Hooks - Functional', async t => {
})
test('Hooks - Error', async t => {
const errors = builtErr.filter(value => value.indexOf('build:extendRoutes') >= 0)
t.true(errors.length === 1)
t.true(builtErr.calledWithMatch(/build:extendRoutes/))
})
test('Hooks - Use external middleware before render', async t => {

View File

@ -1,6 +1,6 @@
import test from 'ava'
import stdMocks from 'std-mocks'
import { Nuxt, Builder } from '..'
import { interceptLog, release } from './helpers/console'
let nuxt = null
@ -37,14 +37,11 @@ test('/custom (not default layout)', async t => {
})
test('/custom (call mounted and created once)', async t => {
stdMocks.use()
const logSpy = await interceptLog()
await renderRoute('/custom')
stdMocks.restore()
const output = stdMocks.flush()
const creates = output.stdout.filter(value => value === 'created\n')
t.true(creates.length === 1)
const mounts = output.stdout.filter(value => value === 'mounted\n')
t.true(mounts.length === 1)
release()
t.true(logSpy.withArgs('created').calledOnce)
t.true(logSpy.withArgs('mounted').calledOnce)
})
test('/_nuxt/ (access publicPath in spa mode)', async t => {

View File

@ -4233,7 +4233,7 @@ lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
lodash@^4.11.1, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0:
lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
@ -6494,12 +6494,6 @@ statuses@~1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"
std-mocks@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/std-mocks/-/std-mocks-1.0.1.tgz#d3388876d7beeba3c70fbd8e2bcaf46eb07d79fe"
dependencies:
lodash "^4.11.1"
stealthy-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"