Skip to content

Commit 000dae1

Browse files
TheLarkInnsokra
authored andcommitted
fix(tests): Updated tests across the board to work with perf budgets
1 parent e360c8b commit 000dae1

61 files changed

Lines changed: 2757 additions & 111 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/Compilation.js

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,96 +1030,4 @@ Compilation.prototype.checkConstraints = function() {
10301030
throw new Error("checkConstraints: duplicate chunk in compilation " + chunk.debugId);
10311031
chunk.checkConstraints();
10321032
}.bind(this));
1033-
};
1034-
1035-
Compilation.prototype.getAssetsByChunks = function() {
1036-
var webpackStatsJson = this.getStats().toJson();
1037-
var chunks = getFilteredChunks(webpackStatsJson);
1038-
1039-
function getFilteredChunks(webpackStatsJson) {
1040-
return webpackStatsJson.chunks.filter(function(chunk) {
1041-
var chunkName = chunk.names[0];
1042-
// This chunk doesn't have a name. This script can't handled it.
1043-
if (chunkName === undefined) {
1044-
return false;
1045-
}
1046-
// Skip if the chunk should be lazy loaded
1047-
if (!chunk.initial) {
1048-
return false;
1049-
}
1050-
1051-
// Add otherwise
1052-
return true;
1053-
});
1054-
};
1055-
1056-
var assets = {
1057-
// Will contain all js & css files by chunk
1058-
chunks: {},
1059-
// Will contain all js files
1060-
js: [],
1061-
// Will contain all css files
1062-
css: [],
1063-
// Will contain the html5 appcache manifest files if it exists
1064-
manifest: Object.keys(this.assets).filter(function(assetFile) {
1065-
return path.extname(assetFile) === '.appcache';
1066-
})[0]
1067-
};
1068-
1069-
// Append a hash for cache busting
1070-
for(var i = 0; i < chunks.length; i++) {
1071-
var chunk = chunks[i];
1072-
1073-
debugger;
1074-
1075-
var chunkName = chunk.names && chunk.names[0] || "";
1076-
1077-
assets.chunks[chunkName] = {};
1078-
1079-
// Prepend the public path to all chunk files
1080-
var chunkFiles = [].concat(chunk.files).map(function(chunkFile) {
1081-
return chunkFile;
1082-
});
1083-
1084-
// Webpack outputs an array for each chunk when using sourcemaps
1085-
// But we need only the entry file
1086-
1087-
var entry = chunkFiles[0];
1088-
assets.chunks[chunkName].size = chunk.size;
1089-
assets.chunks[chunkName].entry = entry;
1090-
assets.chunks[chunkName].hash = chunk.hash;
1091-
assets.js.push(entry);
1092-
1093-
// Gather all css files
1094-
var css = chunkFiles.filter(function(chunkFile) {
1095-
// Some chunks may contain content hash in their names, for ex. 'main.css?1e7cac4e4d8b52fd5ccd2541146ef03f'.
1096-
// We must proper handle such cases, so we use regexp testing here
1097-
return /.css($|\?)/.test(chunkFile);
1098-
});
1099-
assets.chunks[chunkName].css = css;
1100-
assets.css = assets.css.concat(css);
1101-
}
1102-
1103-
// Duplicate css assets can occur on occasion if more than one chunk
1104-
// requires the same css.
1105-
1106-
assets.css = uniques(assets.css);
1107-
1108-
return assets;
1109-
};
1110-
1111-
// TODO# Find better module or make more reusable
1112-
function uniques(array) {
1113-
var result = [],
1114-
val, ridx;
1115-
outer:
1116-
for(var i = 0, length = array.length; i < length; i++) {
1117-
val = array[i];
1118-
ridx = result.length;
1119-
while(ridx--) {
1120-
if(val === result[ridx]) continue outer;
1121-
}
1122-
result.push(val);
1123-
}
1124-
return result;
1125-
}
1033+
};

lib/Stats.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,13 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
456456

457457
function getAssetColor(asset, defaultColor) {
458458
var jsRegex = /\.js($|\?)/i;
459-
460-
if(isHugeBundle(asset.size) && jsRegex.test(asset.name)) {
461-
return colors.yellow;
459+
460+
if("performance" in obj) {
461+
if(isHugeBundle(asset.size) && jsRegex.test(asset.name)) {
462+
return colors.yellow;
463+
}
462464
}
465+
463466
return defaultColor;
464467
}
465468

lib/performance/EmittedAssetSizeLimitPlugin.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
121121
entrypoint.isOverSizeLimit = false;
122122
if(entrypoint.assets[file].isOverSizeLimit) {
123123
entrypoint.isOverSizeLimit = true;
124-
};
125-
124+
}
126125
});
127126

128127
if(!entrypoint.isOverSizeLimit) {
@@ -165,7 +164,7 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
165164
}
166165
}
167166

168-
if(!!warnings.length) {
167+
if(warnings.length) {
169168
Array.prototype.push.apply(compilation.warnings, warnings);
170169
}
171170

schemas/webpackOptionsSchema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@
760760
"type": "number"
761761
},
762762
"maxAssetSize": {
763-
"description": "Filesize limit (in kB) when exceeded, that webpack will provide performance hints",
763+
"description": "Filesize limit (in bytes) when exceeded, that webpack will provide performance hints",
764764
"type": "number"
765765
}
766766
},

test/Validation.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe("Validation", function() {
104104
message: [
105105
" - configuration has an unknown property 'postcss'. These properties are valid:",
106106
" object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, " +
107-
"loader?, module?, name?, node?, output?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, " +
107+
"loader?, module?, name?, node?, output?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, " +
108108
"recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }",
109109
" For typos: please correct them.",
110110
" For loader options: webpack 2 no longer allows custom properties in configuration.",
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module.exports = {
2-
target: "web"
2+
target: "web",
3+
performance: {
4+
hints: false
5+
}
36
};

test/fixtures/temp-cache-fixture/a.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixtures/temp-cache-fixture/c.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/statsCases/preset-normal-performance/expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Hash: <CLR=BOLD>f8acbb13651bd3d16001</CLR>
1+
Hash: <CLR=BOLD>c45568f88684e80dbde5</CLR>
22
Time: <CLR=BOLD>X</CLR>ms
33
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=BOLD>Chunk Names</CLR>
4-
<CLR=32,BOLD>0.js</CLR> 251 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
4+
<CLR=32,BOLD>0.js</CLR> 227 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
55
<CLR=32,BOLD>1.js</CLR> 100 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
66
<CLR=32,BOLD>2.js</CLR> 178 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
77
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>419 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> main
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
webpackJsonp([2],[
2+
/* 0 */,
3+
/* 1 */,
4+
/* 2 */,
5+
/* 3 */,
6+
/* 4 */
7+
/***/ function(module, exports, __webpack_require__) {
8+
9+
__webpack_require__(5);
10+
__webpack_require__(0);
11+
__webpack_require__(1);
12+
__webpack_require__(2);
13+
__webpack_require__(3);
14+
__webpack_require__(6);
15+
__webpack_require__(7);
16+
17+
18+
/***/ },
19+
/* 5 */,
20+
/* 6 */
21+
/***/ function(module, exports) {
22+
23+
/*************************************************************************************************/
24+
/*************************************************************************************************/
25+
/*************************************************************************************************/
26+
/*************************************************************************************************/
27+
/*************************************************************************************************/
28+
/*************************************************************************************************/
29+
/*************************************************************************************************/
30+
/*************************************************************************************************/
31+
/*************************************************************************************************/
32+
33+
/***/ },
34+
/* 7 */
35+
/***/ function(module, exports) {
36+
37+
/*************************************************************************************************/
38+
/*************************************************************************************************/
39+
/*************************************************************************************************/
40+
/*************************************************************************************************/
41+
/*************************************************************************************************/
42+
/*************************************************************************************************/
43+
/*************************************************************************************************/
44+
/*************************************************************************************************/
45+
/*************************************************************************************************/
46+
47+
/***/ }
48+
],[4]);

0 commit comments

Comments
 (0)