Skip to content

Commit

Permalink
Merge 47002da into 8984fa2
Browse files Browse the repository at this point in the history
  • Loading branch information
SevInf committed Mar 14, 2018
2 parents 8984fa2 + 47002da commit 674d7a2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions helpers.js
Expand Up @@ -7,3 +7,15 @@ exports.pathMatch = function(url, path) {
return false;
}
}

exports.createMemoizedToJson = function() {
var lastStats = null;
var lastJson = null;
return function(stats) {
if (lastStats !== stats) {
lastStats = stats;
lastJson = stats.toJson({ errorDetails: false });
}
return lastJson;
}
};
3 changes: 2 additions & 1 deletion middleware.js
Expand Up @@ -2,6 +2,7 @@ module.exports = webpackHotMiddleware;

var helpers = require('./helpers');
var pathMatch = helpers.pathMatch;
var statsToJson = helpers.createMemoizedToJson();

function webpackHotMiddleware(compiler, opts) {
opts = opts || {};
Expand Down Expand Up @@ -84,7 +85,7 @@ function createEventStream(heartbeat) {

function publishStats(action, statsResult, eventStream, log) {
// For multi-compiler, stats will be an object with a 'children' array of stats
var bundles = extractBundles(statsResult.toJson({ errorDetails: false }));
var bundles = extractBundles(statsToJson(statsResult));
bundles.forEach(function(stats) {
if (log) {
log("webpack built " + (stats.name ? stats.name + " " : "") +
Expand Down
21 changes: 21 additions & 0 deletions test/helpers-test.js
Expand Up @@ -19,4 +19,25 @@ describe("helpers", function() {
assert.equal(pathMatch("/path-and", "/path"), false);
});
});

describe("createMemoizedToJson", function() {
var stats = function() {
return {
toJson: function() {
return {};
}
}
};
var toJson = null;
beforeEach(function() {
toJson = helpers.createMemoizedToJson();
});
it("should return same value for same stats instance", function() {
var instance = stats();
assert.strictEqual(toJson(instance), toJson(instance));
});
it("should return same value for same stats instance", function() {
assert.notStrictEqual(toJson(stats()), toJson(stats()));
});
});
});

0 comments on commit 674d7a2

Please sign in to comment.