From 2b1bd31cb7ab0e14cb2acadafb18215e8bb0df45 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Mon, 30 Jul 2018 20:59:28 +0300 Subject: [PATCH] refactor: move some tests from `all-options` to `UglifyHsPlugin` tests --- test/UglifyJsPlugin.test.js | 6 ++-- test/all-options.test.js | 59 ------------------------------------- 2 files changed, 3 insertions(+), 62 deletions(-) diff --git a/test/UglifyJsPlugin.test.js b/test/UglifyJsPlugin.test.js index 48a5aa21..27ec597c 100644 --- a/test/UglifyJsPlugin.test.js +++ b/test/UglifyJsPlugin.test.js @@ -54,6 +54,7 @@ describe('UglifyJsPlugin', () => { source: () => '/** @preserve Foo Bar */ function foo(longVariableName) { longVariableName = 1; }', }, }; + compilation.warnings = []; compilation.errors = []; eventBinding.handler(compilation); @@ -89,7 +90,7 @@ describe('UglifyJsPlugin', () => { }); }); - it('early returns if private property is already set', () => { + it('empty asset', () => { compilationEventBinding.handler([{ files: ['test.js'], }], () => { @@ -139,8 +140,7 @@ describe('UglifyJsPlugin', () => { files: ['test3.js'], }], () => { // eslint-disable-next-line no-underscore-dangle - expect(compilation.assets['test3.js']._value) - .not.toEqual(expect.stringContaining('longVariableName')); + expect(compilation.assets['test3.js']._value).not.toEqual(expect.stringContaining('longVariableName')); }); }); diff --git a/test/all-options.test.js b/test/all-options.test.js index d5cb2361..00f13fd9 100644 --- a/test/all-options.test.js +++ b/test/all-options.test.js @@ -1,4 +1,3 @@ -import { SourceMapSource } from 'webpack-sources'; import UglifyJsPlugin from '../src/index'; import { PluginEnvironment, @@ -207,32 +206,6 @@ describe('when applied with all options', () => { }); }); - it('outputs SourceMapSource for valid javascript', () => { - compilationEventBinding.handler([{ - files: ['test.js'], - }], () => { - expect(compilation.assets['test.js']).toBeInstanceOf(SourceMapSource); - }); - }); - - it('does not output mangled javascript', () => { - compilationEventBinding.handler([{ - files: ['test.js'], - }], () => { - // eslint-disable-next-line no-underscore-dangle - expect(compilation.assets['test.js']._value).toEqual(expect.stringContaining('longVariableName')); - }); - }); - - it('outputs beautified javascript', () => { - compilationEventBinding.handler([{ - files: ['test.js'], - }], () => { - // eslint-disable-next-line no-underscore-dangle - expect(compilation.assets['test.js']._value).toEqual(expect.stringContaining('\n')); - }); - }); - it('does not preserve comments', () => { compilationEventBinding.handler([{ files: ['test.js'], @@ -242,16 +215,6 @@ describe('when applied with all options', () => { }); }); - it('outputs parsing errors', () => { - compilationEventBinding.handler([{ - files: ['test1.js'], - }], () => { - expect(compilation.errors.length).toBe(1); - expect(compilation.errors[0]).toBeInstanceOf(Error); - expect(compilation.errors[0].message).toEqual(expect.stringContaining('[test1.js:1,0][test1.js:1,8]')); - }); - }); - it('outputs warnings for unreachable code', () => { compilationEventBinding.handler([{ files: ['test2.js'], @@ -261,28 +224,6 @@ describe('when applied with all options', () => { expect(compilation.warnings[0].message).toEqual(expect.stringContaining('Dropping unreachable code')); }); }); - - it('works with sourceAndMap assets as well', () => { - compilationEventBinding.handler([{ - files: ['test3.js'], - }], () => { - expect(compilation.errors.length).toBe(0); - expect(compilation.assets['test3.js']).toBeInstanceOf(SourceMapSource); - }); - }); - - it('extracts license information to separate file', () => { - compilationEventBinding.handler([{ - files: ['test4.js'], - }], () => { - expect(compilation.errors.length).toBe(0); - /* eslint-disable no-underscore-dangle */ - expect(compilation.assets['test4.license.js'].source()).toContain('/*! this comment should be extracted */'); - expect(compilation.assets['test4.license.js'].source()).toContain('// another comment that should be extracted to a separate file'); - expect(compilation.assets['test4.license.js'].source()).not.toEqual(expect.stringContaining('/* this will not be extracted */')); - /* eslint-enable no-underscore-dangle */ - }); - }); }); }); });