diff --git a/test/__snapshots__/uglifyOptions-option.test.js.snap b/test/__snapshots__/uglifyOptions-option.test.js.snap index bfdc46fd..d940f7b8 100644 --- a/test/__snapshots__/uglifyOptions-option.test.js.snap +++ b/test/__snapshots__/uglifyOptions-option.test.js.snap @@ -2,39 +2,43 @@ exports[`when applied with uglifyOptions options disable inline optimization by default (have a lot of problems): errors 1`] = `Array []`; -exports[`when applied with uglifyOptions options disable inline optimization by default (have a lot of problems): main.js 1`] = `"webpackJsonp([0],[function(o,c,n){\\"use strict\\";console.log(42)}],[0]);"`; +exports[`when applied with uglifyOptions options disable inline optimization by default (have a lot of problems): main.9150fdfbc7675d270df7.js 1`] = `"webpackJsonp([0],[function(o,c,n){\\"use strict\\";console.log(42)}],[0]);"`; -exports[`when applied with uglifyOptions options disable inline optimization by default (have a lot of problems): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a{return{a:t+a[\\"a\\"]+e,b:t,baz:e}}}e[\\"default\\"]=o},function(t,e,n){\\"use strict\\";const a=\\"bar\\";e[\\"a\\"]=a;e[\\"b\\"]=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`compress\` option (boolean \`false\` value): main.0c220ec66316af2c1b24.js 1`] = ` +"webpackJsonp([0],[function(o,n){ +/* @preserve*/ +const c=2+2;o.exports=function o(){const n=2+2;console.log(n+1+2)}}],[0]);" +`; -exports[`when applied with uglifyOptions options matches snapshot for \`compress\` option (boolean \`false\` value): manifest.js 1`] = `"(function(r){var e=window[\\"webpackJsonp\\"];window[\\"webpackJsonp\\"]=function n(f,i,u){var c,a,l=0,p=[],s;for(;l({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`compress\` option (boolean \`true\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`compress\` option (boolean \`true\` value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`compress\` option (object value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`compress\` option (object value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){var f,i,p,a=0,l=[];for(;a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`ie8\` option (boolean \`false\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`ie8\` option (boolean \`false\` value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`ie8\` option (boolean \`true\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`ie8\` option (boolean \`true\` value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`keep_classnames\` option (boolean \`false\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`keep_classnames\` option (boolean \`false\` value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`keep_classnames\` option (boolean \`true\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`keep_classnames\` option (boolean \`true\` value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`keep_fnames\` option (boolean \`false\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`keep_fnames\` option (boolean \`false\` value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+o.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`keep_fnames\` option (boolean \`true\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function Foo(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`keep_fnames\` option (boolean \`true\` value): manifest.js 1`] = `"!function(e){var r=window.webpackJsonp;window.webpackJsonp=function webpackJsonpCallback(_,n,o){for(var u,c,p,a=0,i=[];a<_.length;a++)c=_[a],t[c]&&i.push(t[c][0]),t[c]=0;for(u in n)Object.prototype.hasOwnProperty.call(n,u)&&(e[u]=n[u]);for(r&&r(_,n,o);i.length;)i.shift()();if(o)for(a=0;a({a:b+__WEBPACK_IMPORTED_MODULE_0__dep__.a+baz,b:b,baz:baz})}},function(module,__webpack_exports__,__webpack_require__){\\"use strict\\";__webpack_exports__.a=\\"bar\\",__webpack_exports__.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`mangle\` option (boolean \`false\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(module,exports){module.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`mangle\` option (boolean \`false\` value): manifest.js 1`] = `"!function(modules){var parentJsonpFunction=window.webpackJsonp;window.webpackJsonp=function(chunkIds,moreModules,executeModules){for(var moduleId,chunkId,result,i=0,resolves=[];i({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`mangle\` option (boolean \`true\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`mangle\` option (boolean \`true\` value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+baz,b:t,baz:baz})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`mangle\` option (object value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`mangle\` option (object value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`nameCache\` option (empty object value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`nameCache\` option (empty object value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a ({ - a: t + n.a + a, - b: t, - baz: a - }); +exports[`when applied with uglifyOptions options matches snapshot for \`output\` option (object value with \`true\` value for \`beautify\`): main.0c220ec66316af2c1b24.js 1`] = ` +"webpackJsonp([ 0 ], [ function(o, n) { + o.exports = function() { + console.log(7); }; -}, function(t, a, e) { - \\"use strict\\"; - a.a = \\"bar\\", a.b = \\"foo\\"; } ], [ 0 ]);" `; -exports[`when applied with uglifyOptions options matches snapshot for \`output\` option (object value): manifest.js 1`] = ` +exports[`when applied with uglifyOptions options matches snapshot for \`output\` option (object value with \`true\` value for \`beautify\`): manifest.d6857f782c13a99b5917.js 1`] = ` "!function(r) { var n = window.webpackJsonp; window.webpackJsonp = function(e, u, c) { @@ -454,65 +445,174 @@ exports[`when applied with uglifyOptions options matches snapshot for \`output\` }([]);" `; -exports[`when applied with uglifyOptions options matches snapshot for \`output\` option (object value): warnings 1`] = `Array []`; +exports[`when applied with uglifyOptions options matches snapshot for \`output\` option (object value with \`true\` value for \`beautify\`): warnings 1`] = `Array []`; + +exports[`when applied with uglifyOptions options matches snapshot for \`output\` option (object value with \`true\` value for \`comments\`): errors 1`] = `Array []`; + +exports[`when applied with uglifyOptions options matches snapshot for \`output\` option (object value with \`true\` value for \`comments\`): main.0c220ec66316af2c1b24.js 1`] = ` +"webpackJsonp([0],[ +/* 0 */ +/***/function(o,n){o.exports=function(){console.log(7)}}],[0]);" +`; + +exports[`when applied with uglifyOptions options matches snapshot for \`output\` option (object value with \`true\` value for \`comments\`): manifest.d6857f782c13a99b5917.js 1`] = ` +"/******/!function(r){// webpackBootstrap +/******/ // install a JSONP callback for chunk loading +/******/var n=window.webpackJsonp; +/******/window.webpackJsonp=function(e,u,c){ +/******/for( +/******/ // add \\"moreModules\\" to the modules object, +/******/ // then flag all \\"chunkIds\\" as loaded and fire callback +/******/var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`parse\` option (object value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`parse\` option (object value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`safari10\` option (boolean \`false\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`safari10\` option (boolean \`false\` value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`safari10\` option (boolean \`true\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`safari10\` option (boolean \`true\` value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`toplevel\` option (boolean \`false\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`toplevel\` option (boolean \`false\` value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; +exports[`when applied with uglifyOptions options matches snapshot for \`toplevel\` option (boolean \`true\` value): main.0c220ec66316af2c1b24.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; -exports[`when applied with uglifyOptions options matches snapshot for \`toplevel\` option (boolean \`true\` value): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a { - let eventBindings; - let eventBinding; - - beforeEach(() => { - const pluginEnvironment = new PluginEnvironment(); - const compilerEnv = pluginEnvironment.getEnvironmentStub(); - compilerEnv.context = ''; - - const plugin = new UglifyJsPlugin({ - sourceMap: true, - extractComments: { - condition: 'should be extracted', - filename(file) { - return file.replace(/(\.\w+)$/, '.license$1'); - }, - banner(licenseFile) { - return `License information can be found in ${licenseFile}`; - }, - }, - uglifyOptions: { - warnings: true, - mangle: false, - output: { - beautify: true, - }, - }, - }); - plugin.apply(compilerEnv); - eventBindings = pluginEnvironment.getEventBindings(); - }); - - it('matches snapshot', () => { - const compiler = createCompiler(); - new UglifyJsPlugin({ - sourceMap: true, - uglifyOptions: { - mangle: false, - output: { - beautify: true, - }, - warnings: true, - }, - extractComments: { - condition: 'should be extracted', - filename(file) { - return file.replace(/(\.\w+)$/, '.license$1'); - }, - banner(licenseFile) { - return `License information can be found in ${licenseFile}`; - }, - }, - }).apply(compiler); - - return compile(compiler).then((stats) => { - const errors = stats.compilation.errors.map(cleanErrorStack); - const warnings = stats.compilation.warnings.map(cleanErrorStack); - - expect(errors).toMatchSnapshot('errors'); - expect(warnings).toMatchSnapshot('warnings'); - - for (const file in stats.compilation.assets) { - if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { - expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); - } - } - }); - }); - - it('binds one event handler', () => { - expect(eventBindings.length).toBe(1); - }); - - describe('compilation handler', () => { - beforeEach(() => { - [eventBinding] = eventBindings; - }); - - it('binds to compilation event', () => { - expect(eventBinding.name).toBe('compilation'); - }); - - describe('when called', () => { - let chunkPluginEnvironment; - let compilationEventBindings; - let compilationEventBinding; - let compilation; - - beforeEach(() => { - chunkPluginEnvironment = new PluginEnvironment(); - compilation = chunkPluginEnvironment.getEnvironmentStub(); - compilation.assets = { - sourceAndMap: () => { - return { - source: '/** @preserve Foo Bar */ function foo(longVariableName) { longVariableName = 1; }', - map: { - version: 3, - sources: ['test.js'], - names: ['foo', 'longVariableName'], - mappings: 'AAAA,QAASA,KAAIC,kBACTA,iBAAmB', - }, - }; - }, - 'test1.js': { - sourceAndMap: () => { - return { - source: 'invalid javascript', - map: { - version: 3, - sources: ['test1.js'], - names: [''], - mappings: 'AAAA', - }, - }; - }, - }, - 'test2.js': { - sourceAndMap: () => { - return { - source: 'function foo(x) { if (x) { return bar(); not_called1(); } }', - map: { - version: 3, - sources: ['test1.js'], - names: ['foo', 'x', 'bar', 'not_called1'], - mappings: 'AAAA,QAASA,KAAIC,GACT,GAAIA,EAAG,CACH,MAAOC,MACPC', - }, - }; - }, - }, - 'test3.js': { - sourceAndMap: () => { - return { - source: '/** @preserve Foo Bar */ function foo(longVariableName) { longVariableName = 1; }', - map: { - version: 3, - sources: ['test.js'], - names: ['foo', 'longVariableName'], - mappings: 'AAAA,QAASA,KAAIC,kBACTA,iBAAmB', - }, - }; - }, - }, - 'test4.js': { - sourceAndMap: () => { - return { - source: '/*! this comment should be extracted */ function foo(longVariableName) { /* this will not be extracted */ longVariableName = 1; } // another comment that should be extracted to a separate file\n function foo2(bar) { return bar; }', - map: { - version: 3, - sources: ['test.js'], - names: ['foo', 'longVariableName'], - mappings: 'AAAA,QAASA,KAAIC,kBACTA,iBAAmB', - }, - }; - }, - }, - }; - compilation.errors = []; - compilation.warnings = []; - - eventBinding.handler(compilation); - compilationEventBindings = chunkPluginEnvironment.getEventBindings(); - }); - - it('binds two event handler', () => { - expect(compilationEventBindings.length).toBe(2); - }); - - describe('build-module handler', () => { - beforeEach(() => { - [compilationEventBinding] = compilationEventBindings; - }); - - it('binds to build-module event', () => { - expect(compilationEventBinding.name).toBe('build-module'); - }); - - it('sets the useSourceMap flag', () => { - const obj = {}; - compilationEventBinding.handler(obj); - expect(obj.useSourceMap).toBeTruthy(); - }); - }); - - describe('optimize-chunk-assets handler', () => { - beforeEach(() => { - [compilationEventBinding] = compilationEventBindings; - }); - - it('binds to optimize-chunk-assets event', () => { - expect(compilationEventBindings[1].name).toBe('optimize-chunk-assets'); - }); - - it('outputs no errors for valid javascript', () => { - compilationEventBinding.handler([{ - files: ['test.js'], - }], () => { - expect(compilation.errors.length).toBe(0); - }); - }); - - it('does not preserve comments', () => { - compilationEventBinding.handler([{ - files: ['test.js'], - }], () => { - // eslint-disable-next-line no-underscore-dangle - expect(compilation.assets['test.js']._value).not.toBe(expect.stringContaining('/**')); - }); - }); - - it('outputs warnings for unreachable code', () => { - compilationEventBinding.handler([{ - files: ['test2.js'], - }], () => { - expect(compilation.warnings.length).toBe(1); - expect(compilation.warnings[0]).toBeInstanceOf(Error); - expect(compilation.warnings[0].message).toEqual(expect.stringContaining('Dropping unreachable code')); - }); - }); - }); - }); - }); -}); diff --git a/test/uglifyOptions-option.test.js b/test/uglifyOptions-option.test.js index 3519fb0e..15320827 100644 --- a/test/uglifyOptions-option.test.js +++ b/test/uglifyOptions-option.test.js @@ -9,11 +9,6 @@ describe('when applied with uglifyOptions options', () => { it('matches snapshot for `ecma` option (value is `5`)', () => { const compiler = createCompiler({ entry: `${__dirname}/fixtures/ecma-5/entry.js`, - output: { - path: `${__dirname}/dist-ecma-5`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, }); new UglifyJsPlugin({ @@ -45,11 +40,6 @@ describe('when applied with uglifyOptions options', () => { it('matches snapshot for `ecma` option (value is `6`)', () => { const compiler = createCompiler({ entry: `${__dirname}/fixtures/ecma-6/entry.js`, - output: { - path: `${__dirname}/dist-ecma-6`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, }); new UglifyJsPlugin({ @@ -81,11 +71,6 @@ describe('when applied with uglifyOptions options', () => { it('matches snapshot for `ecma` option (value is `7`)', () => { const compiler = createCompiler({ entry: `${__dirname}/fixtures/ecma-7/entry.js`, - output: { - path: `${__dirname}/dist-ecma-7`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, }); new UglifyJsPlugin({ uglifyOptions: { @@ -116,11 +101,6 @@ describe('when applied with uglifyOptions options', () => { it('matches snapshot for `ecma` option (value is `8`)', () => { const compiler = createCompiler({ entry: `${__dirname}/fixtures/ecma-8/entry.js`, - output: { - path: `${__dirname}/dist-ecma-8`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, }); new UglifyJsPlugin({ @@ -152,11 +132,6 @@ describe('when applied with uglifyOptions options', () => { it('matches snapshot for `warnings` option (boolean `true` value)', () => { const compiler = createCompiler({ entry: `${__dirname}/fixtures/unreachable-code.js`, - output: { - path: `${__dirname}/dist`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, }); new UglifyJsPlugin({ @@ -183,11 +158,6 @@ describe('when applied with uglifyOptions options', () => { it('matches snapshot for `warnings` option (boolean `false` value)', () => { const compiler = createCompiler({ entry: `${__dirname}/fixtures/unreachable-code.js`, - output: { - path: `${__dirname}/dist`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, }); new UglifyJsPlugin({ @@ -212,14 +182,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `parse` option (object value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -245,14 +208,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `compress` option (boolean `true` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -276,14 +232,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `compress` option (boolean `false` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -307,14 +256,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `compress` option (object value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -340,14 +282,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `mangle` option (boolean `true` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -371,14 +306,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `mangle` option (boolean `false` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -402,14 +330,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `mangle` option (object value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -434,15 +355,8 @@ describe('when applied with uglifyOptions options', () => { }); }); - it('matches snapshot for `output` option (object value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + it('matches snapshot for `output` option (object value with `true` value for `beautify`)', () => { + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -467,15 +381,34 @@ describe('when applied with uglifyOptions options', () => { }); }); - it('matches snapshot for `toplevel` option (boolean `true` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', + it('matches snapshot for `output` option (object value with `true` value for `comments`)', () => { + const compiler = createCompiler(); + + new UglifyJsPlugin({ + uglifyOptions: { + output: { + comments: true, + }, }, + }).apply(compiler); + + return compile(compiler).then((stats) => { + const errors = stats.compilation.errors.map(cleanErrorStack); + const warnings = stats.compilation.warnings.map(cleanErrorStack); + + expect(errors).toMatchSnapshot('errors'); + expect(warnings).toMatchSnapshot('warnings'); + + for (const file in stats.compilation.assets) { + if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { + expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); + } + } }); + }); + + it('matches snapshot for `toplevel` option (boolean `true` value)', () => { + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -499,14 +432,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `toplevel` option (boolean `false` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -530,14 +456,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `nameCache` option (empty object value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -561,14 +480,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `ie8` option (boolean `true` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -592,14 +504,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `ie8` option (boolean `false` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -623,14 +528,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `keep_classnames` option (boolean `true` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -654,14 +552,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `keep_classnames` option (boolean `false` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -685,14 +576,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `keep_fnames` option (boolean `true` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -716,14 +600,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `keep_fnames` option (boolean `false` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -747,14 +624,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `safari10` option (boolean `true` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -778,14 +648,7 @@ describe('when applied with uglifyOptions options', () => { }); it('matches snapshot for `safari10` option (boolean `false` value)', () => { - const compiler = createCompiler({ - entry: `${__dirname}/fixtures/import-export/entry.js`, - output: { - path: `${__dirname}/dist-import-export`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, - }); + const compiler = createCompiler(); new UglifyJsPlugin({ uglifyOptions: { @@ -811,11 +674,6 @@ describe('when applied with uglifyOptions options', () => { it('disable inline optimization by default (have a lot of problems)', () => { const compiler = createCompiler({ entry: `${__dirname}/fixtures/inline-optimization.js`, - output: { - path: `${__dirname}/dist-inline-optimization`, - filename: '[name].js', - chunkFilename: '[id].[name].js', - }, }); new UglifyJsPlugin().apply(compiler);