From 3fc8aa9fca6db5ae2558ff71ff01e3556a89d5e3 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Tue, 5 Dec 2017 18:36:54 +0800 Subject: [PATCH] test: remove mixins in live reloading --- test/basic.dev.test.js | 38 +++++++++++++++++++++++++--- test/fixtures/basic/plugins/watch.js | 12 +++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/basic/plugins/watch.js diff --git a/test/basic.dev.test.js b/test/basic.dev.test.js index a415ed4322..1d046f00f8 100644 --- a/test/basic.dev.test.js +++ b/test/basic.dev.test.js @@ -1,18 +1,26 @@ 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' +import { Nuxt, Builder, Utils } from '../index.js' +import { truncateSync, readFileSync, writeFileSync } from 'fs' const port = 4001 const url = (route) => 'http://localhost:' + port + route +const rootDir = resolve(__dirname, 'fixtures/basic') +const pluginPath = resolve(rootDir, 'plugins', 'watch.js') +const pluginContent = readFileSync(pluginPath) let nuxt = null // Init nuxt.js and create server listening on localhost:4000 test.before('Init Nuxt.js', async t => { const options = { - rootDir: resolve(__dirname, 'fixtures/basic'), - dev: true + rootDir, + dev: true, + plugins: [ + '~/plugins/watch.js' + ] } nuxt = new Nuxt(options) await new Builder(nuxt).build() @@ -20,6 +28,29 @@ test.before('Init Nuxt.js', async t => { await nuxt.listen(port, 'localhost') }) +test('remove mixins in live reloading', async t => { + stdMocks.use() + await nuxt.renderRoute(url('/')) + t.true(stdMocks.flush().stdout.some(v => v === 'I am mixin\n')) + + 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')) + } + } + resolve() + }) + + await nuxt.renderRoute(url('/')) + t.false(stdMocks.flush().stdout.some(v => v === 'I am mixin\n')) + + stdMocks.restore() +}) + test('/stateless', async t => { const window = await nuxt.renderAndGetWindow(url('/stateless')) const html = window.document.body.innerHTML @@ -37,5 +68,6 @@ test('/stateless', async t => { // Close server and ask nuxt to stop listening to file changes test.after('Closing server and nuxt.js', async t => { + writeFileSync(pluginPath, pluginContent) await nuxt.close() }) diff --git a/test/fixtures/basic/plugins/watch.js b/test/fixtures/basic/plugins/watch.js new file mode 100644 index 0000000000..b243a212ab --- /dev/null +++ b/test/fixtures/basic/plugins/watch.js @@ -0,0 +1,12 @@ +import Vue from 'vue' + +const Plugin = { + install(Vue) { + Vue.mixin({ + created() { + console.log('I am mixin') // eslint-disable-line no-console + } + }) + } +} +Vue.use(Plugin)