This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 179
test: add test for MultiCompiler
usage
#74
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f1856b0
added countPlugins test helper, converted export syntax to es2015 format
hulkish 3a8ce1f
fixed breaking change for MultiCompiler support
hulkish 351cbfa
added regression test for MultiCompiler support
hulkish bb5f4f2
using path.resolve instead of process.cwd() for new RequestShortener
hulkish 5b5e122
simplified countPLugins() test helper
hulkish 50bf746
changed RequestShortener defaulting behavior for compiler.context sin…
hulkish 0e1c0f1
updated snapshots
hulkish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`compiler plugin count 1`] = ` | ||
Object { | ||
"after-emit": 1, | ||
"after-resolvers": 2, | ||
"before-run": 1, | ||
"compilation": 32, | ||
"done": 1, | ||
"entry-option": 1, | ||
"invalid": 1, | ||
"make": 1, | ||
"this-compilation": 1, | ||
} | ||
`; | ||
|
||
exports[`errors 1`] = `Array []`; | ||
|
||
exports[`errors 2`] = `Array []`; | ||
|
||
exports[`errors 3`] = `Array []`; | ||
|
||
exports[`main.4e5a10269ba18219d140.js 1`] = ` | ||
"/******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) { | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ i: moduleId, | ||
/******/ l: false, | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.l = true; | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/******/ | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
/******/ | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
/******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { | ||
/******/ configurable: false, | ||
/******/ enumerable: true, | ||
/******/ get: getter | ||
/******/ }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function getDefault() { return module['default']; } : | ||
/******/ function getModuleExports() { return module; }; | ||
/******/ __webpack_require__.d(getter, 'a', getter); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ | ||
/******/ // Object.prototype.hasOwnProperty.call | ||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||
/******/ | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = \\"\\"; | ||
/******/ | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 0); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ([ | ||
/* 0 */ | ||
/***/ (function(module, exports) { | ||
|
||
// foo | ||
/* @preserve*/ | ||
// bar | ||
const a = 2 + 2; | ||
|
||
module.exports = function Foo() { | ||
const b = 2 + 2; | ||
console.log(b + 1 + 2); | ||
}; | ||
|
||
|
||
/***/ }) | ||
/******/ ]);" | ||
`; | ||
|
||
exports[`main.4e5a10269ba18219d140.js 2`] = `"!function(n){function t(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var e={};t.m=n,t.c=e,t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:r})},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,\\"a\\",e),e},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.p=\\"\\",t(t.s=0)}([function(n,t){n.exports=function(){console.log(7)}}]);"`; | ||
|
||
exports[`main.db8335aef59d7a30f804.js 1`] = `"!function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var r={};e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,\\"a\\",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p=\\"\\",e(e.s=0)}([function(t,e,r){\\"use strict\\";Object.defineProperty(e,\\"__esModule\\",{value:!0});var n=r(1);e.default=function(){const t=n.b,e=\`baz\${Math.random()}\`;return()=>({a:t+n.a+e,b:t,baz:e})}},function(t,e,r){\\"use strict\\";e.a=\\"bar\\",e.b=\\"foo\\"}]);"`; | ||
|
||
exports[`warnings 1`] = `Array []`; | ||
|
||
exports[`warnings 2`] = `Array []`; | ||
|
||
exports[`warnings 3`] = `Array []`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import MultiCompiler from 'webpack/lib/MultiCompiler'; | ||
import MultiStats from 'webpack/lib/MultiStats'; | ||
import UglifyJsPlugin from '../src/index'; | ||
import { | ||
cleanErrorStack, | ||
createCompiler, | ||
countPlugins, | ||
compile, | ||
} from './helpers'; | ||
|
||
describe('when using MultiCompiler with empty options', () => { | ||
it('matches snapshot', () => { | ||
const multiCompiler = createCompiler([ | ||
{ | ||
bail: true, | ||
cache: false, | ||
entry: `${__dirname}/fixtures/entry.js`, | ||
output: { | ||
path: `${__dirname}/dist`, | ||
filename: '[name].[chunkhash].js', | ||
chunkFilename: '[id].[name].[chunkhash].js', | ||
}, | ||
}, | ||
{ | ||
bail: true, | ||
cache: false, | ||
entry: `${__dirname}/fixtures/entry.js`, | ||
output: { | ||
path: `${__dirname}/dist`, | ||
filename: '[name].[chunkhash].js', | ||
chunkFilename: '[id].[name].[chunkhash].js', | ||
}, | ||
plugins: [new UglifyJsPlugin()], | ||
}, | ||
{ | ||
bail: true, | ||
cache: false, | ||
entry: `${__dirname}/fixtures/es2015/entry.js`, | ||
output: { | ||
path: `${__dirname}/dist-MultiCompiler`, | ||
filename: '[name].[chunkhash].js', | ||
chunkFilename: '[id].[name].[chunkhash].js', | ||
}, | ||
plugins: [new UglifyJsPlugin()], | ||
}, | ||
]); | ||
|
||
const emptyPluginCount = countPlugins(multiCompiler.compilers[0]); | ||
const expectedPluginCount = countPlugins(multiCompiler.compilers[1]); | ||
|
||
expect(emptyPluginCount).not.toEqual(expectedPluginCount); | ||
expect(multiCompiler).toBeInstanceOf(MultiCompiler); | ||
|
||
multiCompiler.compilers.slice(2).forEach((compiler) => { | ||
const pluginCount = countPlugins(compiler); | ||
expect(pluginCount).not.toEqual(emptyPluginCount); | ||
expect(pluginCount).toEqual(expectedPluginCount); | ||
expect(pluginCount).toMatchSnapshot('compiler plugin count'); | ||
}); | ||
|
||
expect(multiCompiler).toBeInstanceOf(MultiCompiler); | ||
|
||
return compile(multiCompiler).then((multiStats) => { | ||
expect(multiStats).toBeInstanceOf(MultiStats); | ||
|
||
multiStats.stats.forEach((stats) => { | ||
const errors = stats.compilation.errors.map(cleanErrorStack); | ||
const warnings = stats.compilation.warnings.map(cleanErrorStack); | ||
|
||
expect(errors.length).toEqual(0); | ||
expect(warnings.length).toEqual(0); | ||
|
||
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); | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
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.
Where is this used?
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.
What is the usecase here ? :)
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.
@Kovensky @michael-ciniawsky Was for the test I hadn't added at first to this pr. But, I have since added it: https://github.com/webpack-contrib/uglifyjs-webpack-plugin/pull/74/files#diff-0570d5214a7cbff246a7ad90d119f15c