Skip to content

Commit 2e52a78

Browse files
committed
Merge pull request webpack#1146 from realtymaps/master
Stats.js formatError supports string errors
2 parents 0a0ee1c + 20980b8 commit 2e52a78

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

lib/Stats.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Stats.prototype.toJson = function toJson(options, forToString) {
7474
}
7575
function formatError(e) {
7676
var text = "";
77+
if(typeof e === "string")
78+
e = {message: e};
7779
if(e.module && e.module.readableIdentifier && typeof e.module.readableIdentifier === "function") {
7880
text += e.module.readableIdentifier(requestShortener) + "\n";
7981
} else if(e.file) {

test/Stats.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var webpack = require("../lib/webpack");
77

88
var base = path.join(__dirname, "statsCases");
99
var tests = fs.readdirSync(base);
10+
var Stats = require("../lib/Stats");
1011

1112
describe("Stats", function() {
1213
tests.forEach(function(testName) {
@@ -59,4 +60,43 @@ describe("Stats", function() {
5960
});
6061
});
6162
});
63+
describe("Error Handling", function(){
64+
describe("does have", function(){
65+
it("hasErrors", function() {
66+
mockStats = new Stats({errors:['firstError'],hash:'1234'});
67+
mockStats.hasErrors().should.be.ok;
68+
});
69+
it("hasWarnings", function() {
70+
mockStats = new Stats({warnings:['firstError'],hash:'1234'});
71+
mockStats.hasWarnings().should.be.ok;
72+
});
73+
});
74+
describe("does not have", function(){
75+
it("hasErrors", function() {
76+
mockStats = new Stats({errors:[],hash:'1234'});
77+
mockStats.hasErrors().should.not.be.ok;
78+
});
79+
it("hasWarnings", function() {
80+
mockStats = new Stats({warnings:[],hash:'1234'});
81+
mockStats.hasWarnings().should.not.be.ok;
82+
});
83+
});
84+
it("formatError handles string errors", function(){
85+
mockStats = new Stats({
86+
errors:['firstError'],
87+
warnings:[],
88+
assets:[],
89+
chunks:[],
90+
modules:[],
91+
children:[],
92+
hash:'1234',
93+
mainTemplate:{
94+
getPublicPath:function(){return 'path';}
95+
}
96+
});
97+
obj = mockStats.toJson();
98+
obj.errors[0].should.be.equal('firstError');
99+
});
100+
});
101+
62102
});

0 commit comments

Comments
 (0)