This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
Refactor stuff #333
Merged
Merged
Refactor stuff #333
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3e4285c
refactor: stuff
alexander-akait bb92218
refactor: equal name convention for tests
alexander-akait 9a96017
refactor: move test from `invalid` option to `UglifyJsPlugin` test
alexander-akait bb18e26
refactor: more tests
alexander-akait 0f302a9
refactor: sort validate option as in docs
alexander-akait File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,238 @@ | ||
import UglifyJsPlugin from '../src/index'; | ||
import { cleanErrorStack, compile, createCompiler } from './helpers'; | ||
|
||
describe('UglifyJsPlugin', () => { | ||
it('has apply function', () => { | ||
it('export as function', () => { | ||
expect(typeof new UglifyJsPlugin().apply).toBe('function'); | ||
}); | ||
|
||
it('validation errors', () => { | ||
/* eslint-disable no-new */ | ||
expect(() => { | ||
new UglifyJsPlugin({ test: /foo/ }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ test: [/foo/] }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ include: /foo/ }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ include: [/foo/] }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ exclude: /foo/ }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ exclude: [/foo/] }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ doesntExist: true }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ cache: true }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ cache: false }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ cache: 'path/to/cache/directory' }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ cache: {} }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ cacheKeys() {} }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ parallel: true }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ parallel: false }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ parallel: 2 }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ parallel: '2' }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ parallel: {} }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ sourceMap: true }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ sourceMap: false }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ sourceMap: 'true' }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ minify() {} }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: null }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: {} }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ | ||
uglifyOptions: { | ||
ecma: 5, | ||
warnings: false, | ||
parse: {}, | ||
compress: true, | ||
mangle: { inline: false }, | ||
output: { comments: /^\**!|@preserve|@license|@cc_on/ }, | ||
toplevel: false, | ||
nameCache: {}, | ||
ie8: false, | ||
keep_classnames: false, | ||
keep_fnames: false, | ||
safari10: false, | ||
}, | ||
}); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: { ie8: false } }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: { ie8: true } }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: { ie8: 'false' } }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: { emca: 5 } }); | ||
}).not.toThrow(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: { emca: 8 } }); | ||
}).not.toThrow(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: { ecma: 7.5 } }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: { ecma: true } }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: { ecma: '5' } }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: { ecma: 3 } }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ uglifyOptions: { ecma: 10 } }); | ||
}).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ extractComments: true }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ extractComments: false }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ extractComments: /comment/ }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ extractComments() {} }); | ||
}).not.toThrow('Validation Error'); | ||
|
||
expect(() => { | ||
new UglifyJsPlugin({ warningsFilter() {} }); | ||
}).not.toThrow('Validation Error'); | ||
}); | ||
|
||
it('contain errors when uglify has unknown option', () => { | ||
const compiler = createCompiler(); | ||
new UglifyJsPlugin({ | ||
uglifyOptions: { | ||
output: { | ||
unknown: 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('isSourceMap method', () => { | ||
const rawSourceMap = { | ||
version: 3, | ||
file: 'min.js', | ||
names: ['bar', 'baz', 'n'], | ||
sources: ['one.js', 'two.js'], | ||
sourceRoot: 'http://example.com/www/js/', | ||
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA', | ||
}; | ||
const emptyRawSourceMap = { | ||
version: 3, | ||
sources: [], | ||
mappings: '', | ||
}; | ||
|
||
expect(UglifyJsPlugin.isSourceMap(null)).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap()).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap({})).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap([])).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap('foo')).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap({ version: 3 })).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap({ sources: '' })).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap({ mappings: [] })).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap({ version: 3, sources: '' })).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap({ version: 3, mappings: [] })).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap({ sources: '', mappings: [] })).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap({ version: 3, sources: '', mappings: [] })).toBe(false); | ||
expect(UglifyJsPlugin.isSourceMap(rawSourceMap)).toBe(true); | ||
expect(UglifyJsPlugin.isSourceMap(emptyRawSourceMap)).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the function as a helper. If you expose it it becomes a public API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ooflorent yep, why:
AbstractMinimizerWebpackPlugin
can be based on this code and this helper should be public (I'm preparing to release it next week).AbstractMinimizerWebpackPlugin
).