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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add && backport tests from webpack core (#56)
* ported uglifyjs unit tests from webpack core repo added eslint-plugin-jest for tests, upgraded jest, babel-jest & webpack dev deps cleanup, corrected snapshot test fixed linting errors added eslintignore for test stubs corrected eslintignore paths added codecov config fixing codecov corrected jest test/src/coverage paths removed coverageDirectory: './coverage/' from jest config since it's default separated snapshot tests made createCompiler options replaceable, improved default options test separated tests by logic into separate test files improved snapshot tests cleaned up stacktraces in snapshot output, to allow snapshots to not fail just because paths change in error stack fix typo cleaned up test compilation error stacks to be more generic more cleanup * fixed tests & lint errors * removed yarn.lock * added package-lock.json
- Loading branch information
1 parent
0659f13
commit 46b0788
Showing
18 changed files
with
1,875 additions
and
417 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
*.snap | ||
/node_modules | ||
/dist | ||
/examples/build | ||
/coverage/ | ||
/__tests__/stubs |
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,8 @@ | ||
{ | ||
"plugins": [ | ||
"jest" | ||
], | ||
"env": { | ||
"jest/globals": true | ||
} | ||
} |
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,7 @@ | ||
import UglifyJsPlugin from '../src/index'; | ||
|
||
describe('UglifyJsPlugin', () => { | ||
it('has apply function', () => { | ||
expect(typeof new UglifyJsPlugin().apply).toBe('function'); | ||
}); | ||
}); |
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,86 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`errors 1`] = `Array []`; | ||
|
||
exports[`main.js 1`] = ` | ||
"webpackJsonp([ 0 ], [ function(module, exports) { | ||
module.exports = function() { | ||
console.log(7); | ||
}; | ||
} ], [ 0 ]);" | ||
`; | ||
|
||
exports[`manifest.js 1`] = ` | ||
"!function(modules) { | ||
function __webpack_require__(moduleId) { | ||
if (installedModules[moduleId]) return installedModules[moduleId].exports; | ||
var module = installedModules[moduleId] = { | ||
i: moduleId, | ||
l: !1, | ||
exports: {} | ||
}; | ||
return modules[moduleId].call(module.exports, module, module.exports, __webpack_require__), | ||
module.l = !0, module.exports; | ||
} | ||
var parentJsonpFunction = window.webpackJsonp; | ||
window.webpackJsonp = function(chunkIds, moreModules, executeModules) { | ||
for (var moduleId, chunkId, result, i = 0, resolves = []; i < chunkIds.length; i++) chunkId = chunkIds[i], | ||
installedChunks[chunkId] && resolves.push(installedChunks[chunkId][0]), installedChunks[chunkId] = 0; | ||
for (moduleId in moreModules) Object.prototype.hasOwnProperty.call(moreModules, moduleId) && (modules[moduleId] = moreModules[moduleId]); | ||
for (parentJsonpFunction && parentJsonpFunction(chunkIds, moreModules, executeModules); resolves.length; ) resolves.shift()(); | ||
if (executeModules) for (i = 0; i < executeModules.length; i++) result = __webpack_require__(__webpack_require__.s = executeModules[i]); | ||
return result; | ||
}; | ||
var installedModules = {}, installedChunks = { | ||
1: 0 | ||
}; | ||
__webpack_require__.e = function(chunkId) { | ||
function onScriptComplete() { | ||
script.onerror = script.onload = null, clearTimeout(timeout); | ||
var chunk = installedChunks[chunkId]; | ||
0 !== chunk && (chunk && chunk[1](new Error(\\"Loading chunk \\" + chunkId + \\" failed.\\")), | ||
installedChunks[chunkId] = void 0); | ||
} | ||
var installedChunkData = installedChunks[chunkId]; | ||
if (0 === installedChunkData) return new Promise(function(resolve) { | ||
resolve(); | ||
}); | ||
if (installedChunkData) return installedChunkData[2]; | ||
var promise = new Promise(function(resolve, reject) { | ||
installedChunkData = installedChunks[chunkId] = [ resolve, reject ]; | ||
}); | ||
installedChunkData[2] = promise; | ||
var head = document.getElementsByTagName(\\"head\\")[0], script = document.createElement(\\"script\\"); | ||
script.type = \\"text/javascript\\", script.charset = \\"utf-8\\", script.async = !0, script.timeout = 12e4, | ||
__webpack_require__.nc && script.setAttribute(\\"nonce\\", __webpack_require__.nc), | ||
script.src = __webpack_require__.p + \\"\\" + chunkId + \\".js\\"; | ||
var timeout = setTimeout(onScriptComplete, 12e4); | ||
return script.onerror = script.onload = onScriptComplete, head.appendChild(script), | ||
promise; | ||
}, __webpack_require__.m = modules, __webpack_require__.c = installedModules, __webpack_require__.d = function(exports, name, getter) { | ||
__webpack_require__.o(exports, name) || Object.defineProperty(exports, name, { | ||
configurable: !1, | ||
enumerable: !0, | ||
get: getter | ||
}); | ||
}, __webpack_require__.n = function(module) { | ||
var getter = module && module.__esModule ? function() { | ||
return module.default; | ||
} : function() { | ||
return module; | ||
}; | ||
return __webpack_require__.d(getter, \\"a\\", getter), getter; | ||
}, __webpack_require__.o = function(object, property) { | ||
return Object.prototype.hasOwnProperty.call(object, property); | ||
}, __webpack_require__.p = \\"\\", __webpack_require__.oe = function(err) { | ||
throw console.error(err), err; | ||
}; | ||
}([]);" | ||
`; | ||
|
||
exports[`warnings 1`] = ` | ||
Array [ | ||
"Error: main.js from UglifyJs | ||
Dropping unused variable a [./__tests__/stubs/entry.js:4,0]", | ||
] | ||
`; |
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,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`errors 1`] = `Array []`; | ||
|
||
exports[`main.js 1`] = `"webpackJsonp([0],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`; | ||
|
||
exports[`manifest.js 1`] = `"!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={1:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error(\\"Loading chunk \\"+e+\\" failed.\\")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName(\\"head\\")[0],i=document.createElement(\\"script\\");i.type=\\"text/javascript\\",i.charset=\\"utf-8\\",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute(\\"nonce\\",n.nc),i.src=n.p+\\"\\"+e+\\".js\\";var a=setTimeout(r,12e4);return i.onerror=i.onload=r,u.appendChild(i),c},n.m=e,n.c=t,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,\\"a\\",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p=\\"\\",n.oe=function(e){throw console.error(e),e}}([]);"`; | ||
|
||
exports[`warnings 1`] = `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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`errors 1`] = ` | ||
Array [ | ||
"Error: main.js from UglifyJs | ||
DefaultsError: \`invalid-option\` is not a supported option | ||
node_modules/uglify-js/tools/node.js:27:1, <anonymous>:86:23 | ||
src/index.js:243:82 | ||
native | ||
src/index.js:53:25 | ||
node_modules/tapable/lib/Tapable.js:142:13 | ||
node_modules/webpack/lib/Compilation.js:641:10 | ||
node_modules/tapable/lib/Tapable.js:131:46 | ||
node_modules/webpack/lib/Compilation.js:637:9 | ||
node_modules/tapable/lib/Tapable.js:131:46 | ||
node_modules/webpack/lib/Compilation.js:580:8", | ||
"Error: manifest.js from UglifyJs | ||
DefaultsError: \`invalid-option\` is not a supported option | ||
node_modules/uglify-js/tools/node.js:27:1, <anonymous>:86:23 | ||
src/index.js:243:82 | ||
native | ||
src/index.js:53:25 | ||
node_modules/tapable/lib/Tapable.js:142:13 | ||
node_modules/webpack/lib/Compilation.js:641:10 | ||
node_modules/tapable/lib/Tapable.js:131:46 | ||
node_modules/webpack/lib/Compilation.js:637:9 | ||
node_modules/tapable/lib/Tapable.js:131:46 | ||
node_modules/webpack/lib/Compilation.js:580:8", | ||
] | ||
`; | ||
exports[`main.js 1`] = ` | ||
"webpackJsonp([0],[ | ||
/* 0 */ | ||
/***/ (function(module, exports) { | ||
// foo | ||
/*@preserve*/ | ||
// bar | ||
var a = 2 + 2; | ||
module.exports = function Foo() { | ||
var b = 2 + 2; | ||
console.log(b + 1 + 2); | ||
}; | ||
/***/ }) | ||
],[0]);" | ||
`; | ||
exports[`manifest.js 1`] = ` | ||
"/******/ (function(modules) { // webpackBootstrap | ||
/******/ // install a JSONP callback for chunk loading | ||
/******/ var parentJsonpFunction = window[\\"webpackJsonp\\"]; | ||
/******/ window[\\"webpackJsonp\\"] = function webpackJsonpCallback(chunkIds, moreModules, executeModules) { | ||
/******/ // add \\"moreModules\\" to the modules object, | ||
/******/ // then flag all \\"chunkIds\\" as loaded and fire callback | ||
/******/ var moduleId, chunkId, i = 0, resolves = [], result; | ||
/******/ for(;i < chunkIds.length; i++) { | ||
/******/ chunkId = chunkIds[i]; | ||
/******/ if(installedChunks[chunkId]) { | ||
/******/ resolves.push(installedChunks[chunkId][0]); | ||
/******/ } | ||
/******/ installedChunks[chunkId] = 0; | ||
/******/ } | ||
/******/ for(moduleId in moreModules) { | ||
/******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { | ||
/******/ modules[moduleId] = moreModules[moduleId]; | ||
/******/ } | ||
/******/ } | ||
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules, executeModules); | ||
/******/ while(resolves.length) { | ||
/******/ resolves.shift()(); | ||
/******/ } | ||
/******/ if(executeModules) { | ||
/******/ for(i=0; i < executeModules.length; i++) { | ||
/******/ result = __webpack_require__(__webpack_require__.s = executeModules[i]); | ||
/******/ } | ||
/******/ } | ||
/******/ return result; | ||
/******/ }; | ||
/******/ | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ | ||
/******/ // objects to store loaded and loading chunks | ||
/******/ var installedChunks = { | ||
/******/ 1: 0 | ||
/******/ }; | ||
/******/ | ||
/******/ // 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; | ||
/******/ } | ||
/******/ | ||
/******/ // This file contains only the entry chunk. | ||
/******/ // The chunk loading function for additional chunks | ||
/******/ __webpack_require__.e = function requireEnsure(chunkId) { | ||
/******/ var installedChunkData = installedChunks[chunkId]; | ||
/******/ if(installedChunkData === 0) { | ||
/******/ return new Promise(function(resolve) { resolve(); }); | ||
/******/ } | ||
/******/ | ||
/******/ // a Promise means \\"currently loading\\". | ||
/******/ if(installedChunkData) { | ||
/******/ return installedChunkData[2]; | ||
/******/ } | ||
/******/ | ||
/******/ // setup Promise in chunk cache | ||
/******/ var promise = new Promise(function(resolve, reject) { | ||
/******/ installedChunkData = installedChunks[chunkId] = [resolve, reject]; | ||
/******/ }); | ||
/******/ installedChunkData[2] = promise; | ||
/******/ | ||
/******/ // start chunk loading | ||
/******/ var head = document.getElementsByTagName('head')[0]; | ||
/******/ var script = document.createElement('script'); | ||
/******/ script.type = 'text/javascript'; | ||
/******/ script.charset = 'utf-8'; | ||
/******/ script.async = true; | ||
/******/ script.timeout = 120000; | ||
/******/ | ||
/******/ if (__webpack_require__.nc) { | ||
/******/ script.setAttribute(\\"nonce\\", __webpack_require__.nc); | ||
/******/ } | ||
/******/ script.src = __webpack_require__.p + \\"\\" + chunkId + \\".js\\"; | ||
/******/ var timeout = setTimeout(onScriptComplete, 120000); | ||
/******/ script.onerror = script.onload = onScriptComplete; | ||
/******/ function onScriptComplete() { | ||
/******/ // avoid mem leaks in IE. | ||
/******/ script.onerror = script.onload = null; | ||
/******/ clearTimeout(timeout); | ||
/******/ var chunk = installedChunks[chunkId]; | ||
/******/ if(chunk !== 0) { | ||
/******/ if(chunk) { | ||
/******/ chunk[1](new Error('Loading chunk ' + chunkId + ' failed.')); | ||
/******/ } | ||
/******/ installedChunks[chunkId] = undefined; | ||
/******/ } | ||
/******/ }; | ||
/******/ head.appendChild(script); | ||
/******/ | ||
/******/ return promise; | ||
/******/ }; | ||
/******/ | ||
/******/ // 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 = \\"\\"; | ||
/******/ | ||
/******/ // on error function for async loading | ||
/******/ __webpack_require__.oe = function(err) { console.error(err); throw err; }; | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ([]);" | ||
`; | ||
exports[`warnings 1`] = `Array []`; |
Oops, something went wrong.