mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
Merge pull request #2164 from clarkdo/dev
test: create a separate test for deprecated apis
This commit is contained in:
commit
785948ea80
55
test/deprecate.test.js
Executable file
55
test/deprecate.test.js
Executable 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()
|
||||
})
|
3
test/fixtures/debug/nuxt.config.js
vendored
3
test/fixtures/debug/nuxt.config.js
vendored
@ -3,6 +3,9 @@ module.exports = {
|
||||
base: '/test/'
|
||||
},
|
||||
debug: true,
|
||||
build: {
|
||||
scopeHoisting: true
|
||||
},
|
||||
editor: {
|
||||
cmd: 'echo',
|
||||
pattern: ''
|
||||
|
6
test/fixtures/deprecate/modules/hooks/index.js
vendored
Normal file
6
test/fixtures/deprecate/modules/hooks/index.js
vendored
Normal 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
12
test/fixtures/deprecate/nuxt.config.js
vendored
Executable 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
5
test/fixtures/deprecate/package.json
vendored
Executable file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "deprecated-apis",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {}
|
||||
}
|
6
test/fixtures/deprecate/pages/about.vue
vendored
Normal file
6
test/fixtures/deprecate/pages/about.vue
vendored
Normal 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
13
test/fixtures/deprecate/pages/index.vue
vendored
Executable 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>
|
3
test/fixtures/with-config/nuxt.config.js
vendored
3
test/fixtures/with-config/nuxt.config.js
vendored
@ -46,9 +46,6 @@ module.exports = {
|
||||
generateStatsFile: true
|
||||
},
|
||||
extend(config, options) {
|
||||
if (options.dev) {
|
||||
// Please use isDev instead of dev
|
||||
}
|
||||
return Object.assign({}, config, {
|
||||
devtool: 'nosources-source-map'
|
||||
})
|
||||
|
@ -63,13 +63,6 @@ test('Hooks - Error', async t => {
|
||||
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
|
||||
test.after('Closing server and nuxt.js', t => {
|
||||
nuxt.close()
|
||||
|
@ -1,6 +1,5 @@
|
||||
import test from 'ava'
|
||||
import { resolve } from 'path'
|
||||
import stdMocks from 'std-mocks'
|
||||
import rp from 'request-promise-native'
|
||||
import { Nuxt, Builder } from '../index.js'
|
||||
|
||||
@ -8,7 +7,6 @@ const port = 4007
|
||||
const url = (route) => 'http://localhost:' + port + route
|
||||
|
||||
let nuxt = null
|
||||
let builtErr = null
|
||||
|
||||
// Init nuxt.js and create server listening on localhost:4000
|
||||
test.before('Init Nuxt.js', async t => {
|
||||
@ -17,15 +15,7 @@ test.before('Init Nuxt.js', async t => {
|
||||
config.rootDir = rootDir
|
||||
config.dev = false
|
||||
nuxt = new Nuxt(config)
|
||||
|
||||
stdMocks.use({
|
||||
stdout: false,
|
||||
stderr: true
|
||||
})
|
||||
await new Builder(nuxt).build()
|
||||
stdMocks.restore()
|
||||
builtErr = stdMocks.flush().stderr
|
||||
|
||||
await nuxt.listen(port, 'localhost')
|
||||
})
|
||||
|
||||
@ -133,12 +123,6 @@ test('Check /test.txt should return 404', async t => {
|
||||
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
|
||||
test.after('Closing server and nuxt.js', t => {
|
||||
nuxt.close()
|
||||
|
Loading…
Reference in New Issue
Block a user