Nuxt/test/deprecate.test.js

82 lines
2.3 KiB
JavaScript
Raw Normal View History

import test from 'ava'
import { resolve } from 'path'
import rp from 'request-promise-native'
import { Nuxt, Builder } from '..'
import { intercept, interceptWarn, release } from './helpers/console'
const port = 4010
2018-01-13 05:22:11 +00:00
const url = route => 'http://localhost:' + port + route
let nuxt = null
let builder = null
let buildSpies = null
// Init nuxt.js and create server listening on localhost:4000
test.serial('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
buildSpies = await intercept(async () => {
nuxt = new Nuxt(config)
builder = await new Builder(nuxt)
await builder.build()
await nuxt.listen(port, 'localhost')
})
t.true(buildSpies.log.calledWithMatch('DONE'))
t.true(buildSpies.log.calledWithMatch('OPEN'))
})
test.serial('Deprecated: context.isServer and context.isClient', async t => {
const warnSpy = await interceptWarn()
await rp(url('/'))
2018-01-13 05:22:11 +00:00
t.true(
warnSpy.calledWith(
'context.isServer has been deprecated, please use process.server instead.'
)
)
t.true(
warnSpy.calledWith(
'context.isClient has been deprecated, please use process.client instead.'
)
)
t.true(warnSpy.calledTwice)
2017-12-13 05:38:46 +00:00
release()
})
test.serial('Deprecated: dev in build.extend()', async t => {
2018-01-13 05:22:11 +00:00
t.true(
2018-01-13 05:42:07 +00:00
buildSpies.warn.calledWithMatch(
2018-01-13 05:22:11 +00:00
'dev has been deprecated in build.extend(), please use isDev'
2018-01-13 05:42:07 +00:00
)
2018-01-13 05:22:11 +00:00
)
})
test.serial('Deprecated: nuxt.plugin()', async t => {
t.true(nuxt.__builder_plugin)
})
test.serial('Deprecated: module.addVendor()', async t => {
t.true(buildSpies.warn.calledWithMatch('module: addVendor is no longer necessary'))
})
test.serial('Deprecated: module callback', async t => {
t.true(
buildSpies.warn.calledWithMatch(
'Supporting callbacks is deprecated and will be removed in next releases. Consider using async/await.'
)
)
})
2018-01-27 14:53:00 +00:00
test.serial('Error: nuxt.plugin()', async t => {
const error = t.throws(() => nuxt.plugin('build:done', () => {}))
t.is(error.message, 'nuxt.plugin(\'build:done\',..) is not supported. Use new hooks system.')
})
// Close server and ask nuxt to stop listening to file changes
test.after.always('Closing server and nuxt.js', async t => {
await nuxt.close()
})