Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
refactor: move some tests from all-options to UglifyHsPlugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jul 30, 2018
1 parent 5117df5 commit 2b1bd31
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 62 deletions.
6 changes: 3 additions & 3 deletions test/UglifyJsPlugin.test.js
Expand Up @@ -54,6 +54,7 @@ describe('UglifyJsPlugin', () => {
source: () => '/** @preserve Foo Bar */ function foo(longVariableName) { longVariableName = 1; }',
},
};
compilation.warnings = [];
compilation.errors = [];

eventBinding.handler(compilation);
Expand Down Expand Up @@ -89,7 +90,7 @@ describe('UglifyJsPlugin', () => {
});
});

it('early returns if private property is already set', () => {
it('empty asset', () => {
compilationEventBinding.handler([{
files: ['test.js'],
}], () => {
Expand Down Expand Up @@ -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'));
});
});

Expand Down
59 changes: 0 additions & 59 deletions test/all-options.test.js
@@ -1,4 +1,3 @@
import { SourceMapSource } from 'webpack-sources';
import UglifyJsPlugin from '../src/index';
import {
PluginEnvironment,
Expand Down Expand Up @@ -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'],
Expand All @@ -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'],
Expand All @@ -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 */
});
});
});
});
});
Expand Down

0 comments on commit 2b1bd31

Please sign in to comment.