Merge pull request #2164 from clarkdo/dev

test: create a separate test for deprecated apis
This commit is contained in:
Sébastien Chopin 2017-11-20 08:53:17 +01:00 committed by GitHub
commit 785948ea80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 100 additions and 26 deletions

55
test/deprecate.test.js Executable file
View File

@ -0,0 +1,55 @@
import test from 'ava'
import stdMocks from 'std-mocks'
import { resolve } from 'path'
import rp from 'request-promise-native'
import { Nuxt, Builder } from '../index.js'
const port = 4010
const url = (route) => 'http://localhost:' + port + route
let nuxt = null
let builder = null
let builtErr = null
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', async t => {
const rootDir = resolve(__dirname, 'fixtures/deprecate')
let config = require(resolve(rootDir, 'nuxt.config.js'))
config.rootDir = rootDir
config.dev = false
nuxt = new Nuxt(config)
builder = new Builder(nuxt)
stdMocks.use({
stdout: false,
stderr: true
})
await builder.build()
stdMocks.restore()
builtErr = stdMocks.flush().stderr
await nuxt.listen(port, 'localhost')
})
test('Deprecated: context.isServer and context.isClient', async t => {
stdMocks.use()
await rp(url('/'))
stdMocks.restore()
const output = stdMocks.flush()
t.true(output.stderr.length === 2)
})
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)
})
test('Deprecated: nuxt.plugin()', async t => {
t.true(nuxt.__builder_plugin)
})
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => {
nuxt.close()
})

View File

@ -3,6 +3,9 @@ module.exports = {
base: '/test/' base: '/test/'
}, },
debug: true, debug: true,
build: {
scopeHoisting: true
},
editor: { editor: {
cmd: 'echo', cmd: 'echo',
pattern: '' pattern: ''

View File

@ -0,0 +1,6 @@
module.exports = function () {
// Note: Plugin is deprecated. Please use new hooks system.
this.nuxt.plugin('built', (builder) => {
this.nuxt.__builder_plugin = true
})
}

12
test/fixtures/deprecate/nuxt.config.js vendored Executable file
View File

@ -0,0 +1,12 @@
module.exports = {
modules: [
'~/modules/hooks'
],
build: {
extend(config, options) {
if (options.dev) {
// Please use isDev instead of dev
}
}
}
}

5
test/fixtures/deprecate/package.json vendored Executable file
View File

@ -0,0 +1,5 @@
{
"name": "deprecated-apis",
"version": "1.0.0",
"dependencies": {}
}

View File

@ -0,0 +1,6 @@
<template>
<div>
<h1>About page</h1>
<nuxt-link to="/">Home page</nuxt-link>
</div>
</template>

13
test/fixtures/deprecate/pages/index.vue vendored Executable file
View File

@ -0,0 +1,13 @@
<template>
<div>
<h1>Home page</h1>
<nuxt-link to="/about">About page</nuxt-link>
</div>
</template>
<script>
export default {
// context.isServer and context.isClient has been deprecated
fetch({ isServer, isClient }) {}
}
</script>

View File

@ -46,9 +46,6 @@ module.exports = {
generateStatsFile: true generateStatsFile: true
}, },
extend(config, options) { extend(config, options) {
if (options.dev) {
// Please use isDev instead of dev
}
return Object.assign({}, config, { return Object.assign({}, config, {
devtool: 'nosources-source-map' devtool: 'nosources-source-map'
}) })

View File

@ -63,13 +63,6 @@ test('Hooks - Error', async t => {
t.true(errors.length === 1) t.true(errors.length === 1)
}) })
// Note: Plugin is deprecated. Please use new hooks system.
test('Plugin', async t => {
t.is(nuxt.__builder_plugin, 4)
const error = builtErr.filter(value => value.indexOf('deprecated') >= 0)
t.true(error.length === 1)
})
// Close server and ask nuxt to stop listening to file changes // Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => { test.after('Closing server and nuxt.js', t => {
nuxt.close() nuxt.close()

View File

@ -1,6 +1,5 @@
import test from 'ava' import test from 'ava'
import { resolve } from 'path' import { resolve } from 'path'
import stdMocks from 'std-mocks'
import rp from 'request-promise-native' import rp from 'request-promise-native'
import { Nuxt, Builder } from '../index.js' import { Nuxt, Builder } from '../index.js'
@ -8,7 +7,6 @@ const port = 4007
const url = (route) => 'http://localhost:' + port + route const url = (route) => 'http://localhost:' + port + route
let nuxt = null let nuxt = null
let builtErr = 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 => {
@ -17,15 +15,7 @@ test.before('Init Nuxt.js', async t => {
config.rootDir = rootDir config.rootDir = rootDir
config.dev = false config.dev = false
nuxt = new Nuxt(config) nuxt = new Nuxt(config)
stdMocks.use({
stdout: false,
stderr: true
})
await new Builder(nuxt).build() await new Builder(nuxt).build()
stdMocks.restore()
builtErr = stdMocks.flush().stderr
await nuxt.listen(port, 'localhost') await nuxt.listen(port, 'localhost')
}) })
@ -133,12 +123,6 @@ test('Check /test.txt should return 404', async t => {
t.is(err.response.statusCode, 404) t.is(err.response.statusCode, 404)
}) })
test('Check deprecated dev in build.extend()', async t => {
const deprecatedMsg = 'dev has been deprecated in build.extend(), please use isDev\n'
const errors = builtErr.filter(value => value === deprecatedMsg)
t.true(errors.length === 2)
})
// Close server and ask nuxt to stop listening to file changes // Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => { test.after('Closing server and nuxt.js', t => {
nuxt.close() nuxt.close()