From 0fd9774d1150737a4890be2bcbb5a31569e3d89b Mon Sep 17 00:00:00 2001 From: Clark Du Date: Mon, 20 Nov 2017 10:54:37 +0800 Subject: [PATCH 1/2] test: build with DllReferencePlugin --- test/dll.test.js | 19 ++++++++++++++++++- test/fixtures/dll/nuxt.config.js | 9 ++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/test/dll.test.js b/test/dll.test.js index 70137c950a..98d33bef99 100644 --- a/test/dll.test.js +++ b/test/dll.test.js @@ -2,6 +2,7 @@ import test from 'ava' import { resolve } from 'path' import fs from 'fs' import pify from 'pify' +import stdMocks from 'std-mocks' import { Nuxt, Builder } from '../index.js' const readFile = pify(fs.readFile) @@ -16,11 +17,13 @@ const checkCache = (lib) => { } } +let nuxt + test.before('Init Nuxt.js', async t => { let config = require(resolve(rootDir, 'nuxt.config.js')) config.rootDir = rootDir config.dev = true - const nuxt = new Nuxt(config) + nuxt = new Nuxt(config) await new Builder(nuxt).build() }) @@ -29,3 +32,17 @@ test('Check vue cache', checkCache('vue')) test('Check vue-meta cache', checkCache('vue-meta')) test('Check vue-router cache', checkCache('vue-router')) + +test('Build with DllReferencePlugin', async t => { + stdMocks.use() + 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) +}) + +// Close server and ask nuxt to stop listening to file changes +test.after('Closing nuxt.js', t => { + nuxt.close() +}) diff --git a/test/fixtures/dll/nuxt.config.js b/test/fixtures/dll/nuxt.config.js index 51f3132191..d2f540265b 100644 --- a/test/fixtures/dll/nuxt.config.js +++ b/test/fixtures/dll/nuxt.config.js @@ -1,5 +1,12 @@ module.exports = { build: { - dll: true + dll: true, + extend(config, options) { + if (options.isClient) { + const dlls = config.plugins.filter(plugin => plugin.constructor.name === 'DllReferencePlugin') + console.log('Using dll for ' + dlls.length + ' libs') // eslint-disable-line no-console + } + return config + } } } From adc6884ed1db2ca7ff3a9e44eafced598a42e1b4 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Mon, 20 Nov 2017 12:22:30 +0800 Subject: [PATCH 2/2] test: externals and deprecated dev in build.extend --- test/fixtures/with-config/nuxt.config.js | 6 ++++++ test/with-config.test.js | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index 44ec31ec13..5454ed2a36 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -1,3 +1,5 @@ +const path = require('path') + module.exports = { srcDir: __dirname, router: { @@ -14,6 +16,7 @@ module.exports = { ] } }, + modulesDir: path.join(__dirname, '..', '..', '..', 'node_modules'), transition: 'test', layoutTransition: 'test', offline: true, @@ -43,6 +46,9 @@ module.exports = { generateStatsFile: true }, extend(config, options) { + if (options.dev) { + // Please use isDev instead of dev + } return Object.assign({}, config, { devtool: 'nosources-source-map' }) diff --git a/test/with-config.test.js b/test/with-config.test.js index 1f6453f6bc..20c3a25bab 100644 --- a/test/with-config.test.js +++ b/test/with-config.test.js @@ -1,5 +1,6 @@ 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' @@ -7,6 +8,7 @@ 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 => { @@ -15,7 +17,14 @@ 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') }) @@ -124,6 +133,12 @@ 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()