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

fix(index): relax default asset name {RegExp} (options.test) #251

Merged
merged 1 commit into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UglifyJsPlugin {

const {
uglifyOptions = {},
test = /\.js$/i,
test = /\.(js?)(\?.+)?$/i,
warningsFilter = () => true,
extractComments = false,
sourceMap = false,
Expand Down
17 changes: 17 additions & 0 deletions test/__snapshots__/test.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`empty option: 0.0.js?ver=bd0395a3b5883cc6e11c 1`] = `"webpackJsonp([0],{5:function(e,t,c){\\"use strict\\";Object.defineProperty(t,\\"__esModule\\",{value:!0}),t.default=\\"async-dep\\"}});"`;

exports[`empty option: AsyncImportExport.js?var=bd0395a3b5883cc6e11c 1`] = `"webpackJsonp([4],{4:function(e,o,n){\\"use strict\\";Object.defineProperty(o,\\"__esModule\\",{value:!0}),n.e(0).then(n.bind(null,5)).then(()=>{console.log(\\"Good\\")}),o.default=\\"Awesome\\"}},[4]);"`;

exports[`empty option: errors 1`] = `Array []`;

exports[`empty option: importExport.js?var=bd0395a3b5883cc6e11c 1`] = `"webpackJsonp([1],[,,function(t,a,e){\\"use strict\\";Object.defineProperty(a,\\"__esModule\\",{value:!0});var n=e(3);a.default=function(){const t=n.b,a=\`baz\${Math.random()}\`;return()=>({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[2]);"`;

exports[`empty option: js.js?var=bd0395a3b5883cc6e11c 1`] = `"webpackJsonp([3],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`;

exports[`empty option: manifest.js?var=bd0395a3b5883cc6e11c 1`] = `"!function(e){var r=window.webpackJsonp;window.webpackJsonp=function(n,c,i){for(var u,a,p,s=0,f=[];s<n.length;s++)a=n[s],t[a]&&f.push(t[a][0]),t[a]=0;for(u in c)Object.prototype.hasOwnProperty.call(c,u)&&(e[u]=c[u]);for(r&&r(n,c,i);f.length;)f.shift()();if(i)for(s=0;s<i.length;s++)p=o(o.s=i[s]);return p};var n={},t={5:0};function o(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,o),t.l=!0,t.exports}o.e=function(e){var r=t[e];if(0===r)return new Promise(function(e){e()});if(r)return r[2];var n=new Promise(function(n,o){r=t[e]=[n,o]});r[2]=n;var c=document.getElementsByTagName(\\"head\\")[0],i=document.createElement(\\"script\\");i.type=\\"text/javascript\\",i.charset=\\"utf-8\\",i.async=!0,i.timeout=12e4,o.nc&&i.setAttribute(\\"nonce\\",o.nc),i.src=o.p+\\"\\"+e+\\".\\"+({1:\\"importExport\\",2:\\"mjs\\",3:\\"js\\",4:\\"AsyncImportExport\\"}[e]||e)+\\".js?ver=bd0395a3b5883cc6e11c\\";var u=setTimeout(a,12e4);function a(){i.onerror=i.onload=null,clearTimeout(u);var r=t[e];0!==r&&(r&&r[1](new Error(\\"Loading chunk \\"+e+\\" failed.\\")),t[e]=void 0)}return i.onerror=i.onload=a,c.appendChild(i),n},o.m=e,o.c=n,o.d=function(e,r,n){o.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},o.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(r,\\"a\\",r),r},o.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},o.p=\\"\\",o.oe=function(e){throw console.error(e),e}}([]);"`;

exports[`empty option: mjs.js?var=bd0395a3b5883cc6e11c 1`] = `"webpackJsonp([2],[,function(o,n){o.exports=function(){console.log(7)}}],[1]);"`;

exports[`empty option: warnings 1`] = `Array []`;
1 change: 1 addition & 0 deletions test/fixtures/async-import-export/async-dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "async-dep";
5 changes: 5 additions & 0 deletions test/fixtures/async-import-export/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import("./async-dep").then(() => {
console.log('Good')
});

export default "Awesome";
9 changes: 9 additions & 0 deletions test/fixtures/entry.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// foo
/* @preserve*/
// bar
const a = 2 + 2;

module.exports = function Foo() {
const b = 2 + 2;
console.log(b + 1 + 2);
};
1 change: 1 addition & 0 deletions test/fixtures/import-export/async-dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "async-dep";
40 changes: 40 additions & 0 deletions test/test.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import UglifyJsPlugin from '../src/index';
import {
cleanErrorStack,
createCompiler,
compile,
} from './helpers';

describe('when applied with test option', () => {
it('with empty value', () => {
const compiler = createCompiler({
entry: {
js: `${__dirname}/fixtures/entry.js`,
mjs: `${__dirname}/fixtures/entry.mjs`,
importExport: `${__dirname}/fixtures/import-export/entry.js`,
AsyncImportExport: `${__dirname}/fixtures/async-import-export/entry.js`,
},
output: {
path: `${__dirname}/dist`,
filename: '[name].js?var=[hash]',
chunkFilename: '[id].[name].js?ver=[hash]',
},
});

new UglifyJsPlugin().apply(compiler);

return compile(compiler).then((stats) => {
const errors = stats.compilation.errors.map(cleanErrorStack);
const warnings = stats.compilation.warnings.map(cleanErrorStack);

expect(errors).toMatchSnapshot('empty option: errors');
expect(warnings).toMatchSnapshot('empty option: warnings');

for (const file in stats.compilation.assets) {
if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) {
expect(stats.compilation.assets[file].source()).toMatchSnapshot(`empty option: ${file}`);
}
}
});
});
});