mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
test: use sinon instead of std-mocks
This commit is contained in:
parent
4adfdf3313
commit
ff53769829
@ -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": {
|
||||
|
@ -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'
|
||||
|
||||
@ -29,26 +28,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 => {
|
||||
|
@ -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 => {
|
||||
|
@ -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
|
||||
|
@ -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 => {
|
||||
|
@ -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 => {
|
||||
|
74
yarn.lock
74
yarn.lock
@ -2186,6 +2186,10 @@ detect-libc@^1.0.2:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b"
|
||||
|
||||
diff@^3.1.0:
|
||||
version "3.4.0"
|
||||
resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c"
|
||||
|
||||
diffie-hellman@^5.0.0:
|
||||
version "5.0.2"
|
||||
resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.2.tgz#b5835739270cfe26acf632099fded2a07f209e5e"
|
||||
@ -2987,6 +2991,12 @@ form-data@~2.3.1:
|
||||
combined-stream "^1.0.5"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
formatio@1.2.0, formatio@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/formatio/-/formatio-1.2.0.tgz#f3b2167d9068c4698a8d51f4f760a39a54d818eb"
|
||||
dependencies:
|
||||
samsam "1.x"
|
||||
|
||||
forwarded@~0.1.2:
|
||||
version "0.1.2"
|
||||
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"
|
||||
@ -4013,6 +4023,10 @@ jsx-ast-utils@^2.0.0:
|
||||
dependencies:
|
||||
array-includes "^3.0.3"
|
||||
|
||||
just-extend@^1.1.26:
|
||||
version "1.1.27"
|
||||
resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-1.1.27.tgz#ec6e79410ff914e472652abfa0e603c03d60e905"
|
||||
|
||||
kind-of@^3.0.2:
|
||||
version "3.2.2"
|
||||
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
|
||||
@ -4141,6 +4155,10 @@ lodash.flattendeep@^4.4.0:
|
||||
version "4.4.0"
|
||||
resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"
|
||||
|
||||
lodash.get@^4.4.2:
|
||||
version "4.4.2"
|
||||
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
|
||||
|
||||
lodash.isequal@^4.5.0:
|
||||
version "4.5.0"
|
||||
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
|
||||
@ -4178,10 +4196,18 @@ 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"
|
||||
|
||||
lolex@^1.6.0:
|
||||
version "1.6.0"
|
||||
resolved "https://registry.yarnpkg.com/lolex/-/lolex-1.6.0.tgz#3a9a0283452a47d7439e72731b9e07d7386e49f6"
|
||||
|
||||
lolex@^2.2.0:
|
||||
version "2.3.1"
|
||||
resolved "https://registry.yarnpkg.com/lolex/-/lolex-2.3.1.tgz#3d2319894471ea0950ef64692ead2a5318cff362"
|
||||
|
||||
longest@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
|
||||
@ -4465,6 +4491,16 @@ negotiator@0.6.1:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
|
||||
|
||||
nise@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/nise/-/nise-1.2.0.tgz#079d6cadbbcb12ba30e38f1c999f36ad4d6baa53"
|
||||
dependencies:
|
||||
formatio "^1.2.0"
|
||||
just-extend "^1.1.26"
|
||||
lolex "^1.6.0"
|
||||
path-to-regexp "^1.7.0"
|
||||
text-encoding "^0.6.4"
|
||||
|
||||
no-case@^2.2.0:
|
||||
version "2.3.2"
|
||||
resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.2.tgz#60b813396be39b3f1288a4c1ed5d1e7d28b464ac"
|
||||
@ -4900,6 +4936,12 @@ path-to-regexp@0.1.7:
|
||||
version "0.1.7"
|
||||
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
|
||||
|
||||
path-to-regexp@^1.7.0:
|
||||
version "1.7.0"
|
||||
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
|
||||
dependencies:
|
||||
isarray "0.0.1"
|
||||
|
||||
path-type@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441"
|
||||
@ -6128,6 +6170,10 @@ safe-buffer@5.1.1, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, s
|
||||
version "5.1.1"
|
||||
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"
|
||||
|
||||
samsam@1.x:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.3.0.tgz#8d1d9350e25622da30de3e44ba692b5221ab7c50"
|
||||
|
||||
sax@^1.2.1, sax@~1.2.1:
|
||||
version "1.2.4"
|
||||
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
|
||||
@ -6234,6 +6280,18 @@ simple-swizzle@^0.2.2:
|
||||
dependencies:
|
||||
is-arrayish "^0.3.1"
|
||||
|
||||
sinon@^4.1.2:
|
||||
version "4.1.3"
|
||||
resolved "https://registry.yarnpkg.com/sinon/-/sinon-4.1.3.tgz#fc599eda47ed9f1a694ce774b94ab44260bd7ac5"
|
||||
dependencies:
|
||||
diff "^3.1.0"
|
||||
formatio "1.2.0"
|
||||
lodash.get "^4.4.2"
|
||||
lolex "^2.2.0"
|
||||
nise "^1.2.0"
|
||||
supports-color "^4.4.0"
|
||||
type-detect "^4.0.5"
|
||||
|
||||
slash@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
|
||||
@ -6375,12 +6433,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"
|
||||
@ -6607,6 +6659,10 @@ test-exclude@^4.1.1:
|
||||
read-pkg-up "^1.0.1"
|
||||
require-main-filename "^1.0.1"
|
||||
|
||||
text-encoding@^0.6.4:
|
||||
version "0.6.4"
|
||||
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
|
||||
|
||||
text-table@^0.2.0, text-table@~0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
|
||||
@ -6719,6 +6775,10 @@ type-check@~0.3.2:
|
||||
dependencies:
|
||||
prelude-ls "~1.1.2"
|
||||
|
||||
type-detect@^4.0.5:
|
||||
version "4.0.5"
|
||||
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.5.tgz#d70e5bc81db6de2a381bcaca0c6e0cbdc7635de2"
|
||||
|
||||
type-is@~1.6.15:
|
||||
version "1.6.15"
|
||||
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.15.tgz#cab10fb4909e441c82842eafe1ad646c81804410"
|
||||
|
Loading…
Reference in New Issue
Block a user