mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-21 07:59:33 +00:00
Merge pull request #2382 from clarkdo/sinon_console
test: use sinon instead of std-mocks
This commit is contained in:
commit
126b58be00
@ -141,7 +141,6 @@
|
|||||||
"request": "^2.83.0",
|
"request": "^2.83.0",
|
||||||
"request-promise-native": "^1.0.5",
|
"request-promise-native": "^1.0.5",
|
||||||
"sinon": "^4.1.2",
|
"sinon": "^4.1.2",
|
||||||
"std-mocks": "^1.0.1",
|
|
||||||
"uglify-js": "^3.2.2"
|
"uglify-js": "^3.2.2"
|
||||||
},
|
},
|
||||||
"collective": {
|
"collective": {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import stdMocks from 'std-mocks'
|
import { interceptLog, release } from './helpers/console'
|
||||||
// import rp from 'request-promise-native'
|
|
||||||
import { Nuxt, Builder, Utils } from '..'
|
import { Nuxt, Builder, Utils } from '..'
|
||||||
import { truncateSync, readFileSync, writeFileSync } from 'fs'
|
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 => {
|
test('remove mixins in live reloading', async t => {
|
||||||
stdMocks.use()
|
const logSpy = await interceptLog()
|
||||||
await nuxt.renderRoute(url('/'))
|
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)
|
truncateSync(pluginPath)
|
||||||
await new Promise(async (resolve, reject) => {
|
await new Promise(async (resolve, reject) => {
|
||||||
let waitTimes = 0
|
let waitTimes = 0
|
||||||
while (!stdMocks.flush().stdout.some(v => ~v.indexOf('Compiled successfully'))) {
|
while (logSpy.neverCalledWithMatch(/Compiled successfully/)) {
|
||||||
await Utils.waitFor(100) && waitTimes++
|
if (waitTimes++ >= 20) {
|
||||||
if (waitTimes === 20) {
|
t.fail('Dev server doesn\'t reload after 2000ms')
|
||||||
reject(Error('Dev server doesn\'t reload after 2000ms'))
|
reject(Error())
|
||||||
}
|
}
|
||||||
|
await Utils.waitFor(100)
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
|
logSpy.reset()
|
||||||
await nuxt.renderRoute(url('/'))
|
await nuxt.renderRoute(url('/'))
|
||||||
t.false(stdMocks.flush().stdout.some(v => v === 'I am mixin\n'))
|
t.true(logSpy.neverCalledWith('I am mixin'))
|
||||||
|
release()
|
||||||
stdMocks.restore()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('/stateless', async t => {
|
test('/stateless', async t => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
import stdMocks from 'std-mocks'
|
import { interceptWarn, release } from './helpers/console'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import rp from 'request-promise-native'
|
import rp from 'request-promise-native'
|
||||||
import { Nuxt, Builder } from '..'
|
import { Nuxt, Builder } from '..'
|
||||||
@ -9,7 +9,7 @@ const url = (route) => 'http://localhost:' + port + route
|
|||||||
|
|
||||||
let nuxt = null
|
let nuxt = null
|
||||||
let builder = null
|
let builder = null
|
||||||
let builtErr = null
|
let buildLog = null
|
||||||
|
|
||||||
// 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 => {
|
||||||
@ -20,29 +20,24 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
nuxt = new Nuxt(config)
|
nuxt = new Nuxt(config)
|
||||||
builder = new Builder(nuxt)
|
builder = new Builder(nuxt)
|
||||||
|
|
||||||
stdMocks.use({
|
buildLog = await interceptWarn()
|
||||||
stdout: false,
|
|
||||||
stderr: true
|
|
||||||
})
|
|
||||||
await builder.build()
|
await builder.build()
|
||||||
stdMocks.restore()
|
release()
|
||||||
builtErr = stdMocks.flush().stderr
|
|
||||||
|
|
||||||
await nuxt.listen(port, 'localhost')
|
await nuxt.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Deprecated: context.isServer and context.isClient', async t => {
|
test('Deprecated: context.isServer and context.isClient', async t => {
|
||||||
stdMocks.use()
|
const logSpy = await interceptWarn()
|
||||||
await rp(url('/'))
|
await rp(url('/'))
|
||||||
stdMocks.restore()
|
t.true(logSpy.calledWith('context.isServer has been deprecated, please use process.server instead.'))
|
||||||
const output = stdMocks.flush()
|
t.true(logSpy.calledWith('context.isClient has been deprecated, please use process.client instead.'))
|
||||||
t.true(output.stderr.length === 2)
|
t.true(logSpy.calledTwice)
|
||||||
|
release()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Deprecated: dev in build.extend()', async t => {
|
test('Deprecated: dev in build.extend()', async t => {
|
||||||
const deprecatedMsg = 'dev has been deprecated in build.extend(), please use isDev'
|
t.true(buildLog.withArgs('dev has been deprecated in build.extend(), please use isDev').calledTwice)
|
||||||
const errors = builtErr.filter(value => value.indexOf(deprecatedMsg) === 0)
|
|
||||||
t.true(errors.length === 2)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Deprecated: nuxt.plugin()', async t => {
|
test('Deprecated: nuxt.plugin()', async t => {
|
||||||
|
@ -2,8 +2,8 @@ import { promisify } from 'util'
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import stdMocks from 'std-mocks'
|
|
||||||
import { Nuxt, Builder } from '..'
|
import { Nuxt, Builder } from '..'
|
||||||
|
import { interceptLog, release } from './helpers/console'
|
||||||
|
|
||||||
const readFile = promisify(fs.readFile)
|
const readFile = promisify(fs.readFile)
|
||||||
const rootDir = resolve(__dirname, './fixtures/dll')
|
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('Check vue-router cache', checkCache('vue-router'))
|
||||||
|
|
||||||
test('Build with DllReferencePlugin', async t => {
|
test('Build with DllReferencePlugin', async t => {
|
||||||
stdMocks.use()
|
const logSpy = await interceptLog()
|
||||||
await new Builder(nuxt).build()
|
await new Builder(nuxt).build()
|
||||||
stdMocks.restore()
|
release()
|
||||||
const output = stdMocks.flush()
|
t.true(logSpy.withArgs('Using dll for 3 libs').calledOnce)
|
||||||
const dllLog = output.stdout.filter(value => value === 'Using dll for 3 libs\n')
|
|
||||||
t.true(dllLog.length === 1)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
import stdMocks from 'std-mocks'
|
|
||||||
import { resolve, normalize } from 'path'
|
import { resolve, normalize } from 'path'
|
||||||
import rp from 'request-promise-native'
|
import rp from 'request-promise-native'
|
||||||
import { Nuxt, Builder } from '..'
|
import { Nuxt, Builder } from '..'
|
||||||
|
import { interceptError, release } from './helpers/console'
|
||||||
|
|
||||||
const port = 4006
|
const port = 4006
|
||||||
const url = (route) => 'http://localhost:' + port + route
|
const url = (route) => 'http://localhost:' + port + route
|
||||||
@ -20,13 +20,9 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
nuxt = new Nuxt(config)
|
nuxt = new Nuxt(config)
|
||||||
builder = new Builder(nuxt)
|
builder = new Builder(nuxt)
|
||||||
|
|
||||||
stdMocks.use({
|
builtErr = await interceptError()
|
||||||
stdout: false,
|
|
||||||
stderr: true
|
|
||||||
})
|
|
||||||
await builder.build()
|
await builder.build()
|
||||||
stdMocks.restore()
|
release()
|
||||||
builtErr = stdMocks.flush().stderr
|
|
||||||
|
|
||||||
await nuxt.listen(port, 'localhost')
|
await nuxt.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
@ -59,8 +55,7 @@ test('Hooks - Functional', async t => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('Hooks - Error', async t => {
|
test('Hooks - Error', async t => {
|
||||||
const errors = builtErr.filter(value => value.indexOf('build:extendRoutes') >= 0)
|
t.true(builtErr.calledWithMatch(/build:extendRoutes/))
|
||||||
t.true(errors.length === 1)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Hooks - Use external middleware before render', async t => {
|
test('Hooks - Use external middleware before render', async t => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import test from 'ava'
|
import test from 'ava'
|
||||||
import stdMocks from 'std-mocks'
|
|
||||||
import { Nuxt, Builder } from '..'
|
import { Nuxt, Builder } from '..'
|
||||||
|
import { interceptLog, release } from './helpers/console'
|
||||||
|
|
||||||
let nuxt = null
|
let nuxt = null
|
||||||
|
|
||||||
@ -37,14 +37,11 @@ test('/custom (not default layout)', async t => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('/custom (call mounted and created once)', async t => {
|
test('/custom (call mounted and created once)', async t => {
|
||||||
stdMocks.use()
|
const logSpy = await interceptLog()
|
||||||
await renderRoute('/custom')
|
await renderRoute('/custom')
|
||||||
stdMocks.restore()
|
release()
|
||||||
const output = stdMocks.flush()
|
t.true(logSpy.withArgs('created').calledOnce)
|
||||||
const creates = output.stdout.filter(value => value === 'created\n')
|
t.true(logSpy.withArgs('mounted').calledOnce)
|
||||||
t.true(creates.length === 1)
|
|
||||||
const mounts = output.stdout.filter(value => value === 'mounted\n')
|
|
||||||
t.true(mounts.length === 1)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('/_nuxt/ (access publicPath in spa mode)', async t => {
|
test('/_nuxt/ (access publicPath in spa mode)', async t => {
|
||||||
|
@ -4233,7 +4233,7 @@ lodash.uniq@^4.5.0:
|
|||||||
version "4.5.0"
|
version "4.5.0"
|
||||||
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
|
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"
|
version "4.17.4"
|
||||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
|
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
|
||||||
|
|
||||||
@ -6494,12 +6494,6 @@ statuses@~1.3.1:
|
|||||||
version "1.3.1"
|
version "1.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"
|
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:
|
stealthy-require@^1.1.0:
|
||||||
version "1.1.1"
|
version "1.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
|
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
|
||||||
|
Loading…
Reference in New Issue
Block a user