Skip to content

Commit

Permalink
Merge pull request #308 from webpack-contrib/fix-warning-overlay
Browse files Browse the repository at this point in the history
Correctly hide the overlay when an errored build becomes merely warning
  • Loading branch information
glenjamin authored May 13, 2018
2 parents 78c9e7e + f4353b9 commit e0da910
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 3 deletions.
9 changes: 6 additions & 3 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,12 @@ function createReporter() {
if (options.warn) {
log(type, obj);
}
if (overlay && (options.overlayWarnings || type !== 'warnings')) {
overlay.showProblems(type, obj[type]);
return false;
if (overlay) {
if (options.overlayWarnings || type === 'errors') {
overlay.showProblems(type, obj[type]);
return false;
}
overlay.clear();
}
return true;
},
Expand Down
187 changes: 187 additions & 0 deletions test/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,54 @@ describe("client", function() {
"errors", ["Something broke", "Actually, 2 things broke"]
);
});
it("should hide overlay after errored build fixed", function() {
var eventSource = window.EventSource.lastCall.returnValue;
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [
"Something broke",
"Actually, 2 things broke"
],
warnings: [],
modules: []
}));
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [],
warnings: [],
modules: []
}));
sinon.assert.calledOnce(clientOverlay.showProblems)
sinon.assert.calledOnce(clientOverlay.clear)
});
it("should hide overlay after errored build becomes warning", function() {
var eventSource = window.EventSource.lastCall.returnValue;
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [
"Something broke",
"Actually, 2 things broke"
],
warnings: [],
modules: []
}));
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [],
warnings: ["This isn't great, but it's not terrible"],
modules: []
}));
sinon.assert.calledOnce(clientOverlay.showProblems)
sinon.assert.calledOnce(clientOverlay.clear)
});
it("should trigger webpack on warning builds", function() {
var eventSource = window.EventSource.lastCall.returnValue;
eventSource.onmessage(makeMessage({
Expand All @@ -152,9 +200,148 @@ describe("client", function() {
}));
sinon.assert.notCalled(clientOverlay.showProblems)
});
it("should show overlay after warning build becomes error", function() {
var eventSource = window.EventSource.lastCall.returnValue;
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [],
warnings: ["This isn't great, but it's not terrible"],
modules: []
}));
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [
"Something broke",
"Actually, 2 things broke"
],
warnings: [],
modules: []
}));
sinon.assert.calledOnce(clientOverlay.showProblems)
});
it("should test more of the client's functionality");
});

context("with overlayWarnings: true", function() {
beforeEach(function setup() {
global.__resourceQuery = '?overlayWarnings=true'; // eslint-disable-line no-underscore-dangle
global.document = {};
global.window = {
EventSource: sinon.stub().returns({
close: sinon.spy()
})
};
});
beforeEach(loadClient);
it("should show overlay on errored builds", function() {
var eventSource = window.EventSource.lastCall.returnValue;
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [
"Something broke",
"Actually, 2 things broke"
],
warnings: [],
modules: []
}));
sinon.assert.calledOnce(clientOverlay.showProblems)
sinon.assert.calledWith(clientOverlay.showProblems,
"errors", ["Something broke", "Actually, 2 things broke"]
);
});
it("should hide overlay after errored build fixed", function() {
var eventSource = window.EventSource.lastCall.returnValue;
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [
"Something broke",
"Actually, 2 things broke"
],
warnings: [],
modules: []
}));
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [],
warnings: [],
modules: []
}));
sinon.assert.calledOnce(clientOverlay.showProblems)
sinon.assert.calledOnce(clientOverlay.clear)
});
it("should show overlay on warning builds", function() {
var eventSource = window.EventSource.lastCall.returnValue;
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [],
warnings: ["This isn't great, but it's not terrible"],
modules: []
}));
sinon.assert.calledOnce(clientOverlay.showProblems)
sinon.assert.calledWith(clientOverlay.showProblems,
"warnings", ["This isn't great, but it's not terrible"]
)
});
it("should hide overlay after warning build fixed", function() {
var eventSource = window.EventSource.lastCall.returnValue;
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [],
warnings: ["This isn't great, but it's not terrible"],
modules: []
}));
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [],
warnings: [],
modules: []
}));
sinon.assert.calledOnce(clientOverlay.showProblems)
sinon.assert.calledOnce(clientOverlay.clear)
});
it("should update overlay after errored build becomes warning", function() {
var eventSource = window.EventSource.lastCall.returnValue;
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [
"Something broke",
"Actually, 2 things broke"
],
warnings: [],
modules: []
}));
eventSource.onmessage(makeMessage({
action: 'built',
time: 100,
hash: 'deadbeeffeddad',
errors: [],
warnings: ["This isn't great, but it's not terrible"],
modules: []
}));
sinon.assert.calledTwice(clientOverlay.showProblems)
sinon.assert.calledWith(clientOverlay.showProblems, "errors")
sinon.assert.calledWith(clientOverlay.showProblems, "warnings")
});
});

context("with name options", function() {
beforeEach(function setup() {
global.__resourceQuery = '?name=test'; // eslint-disable-line no-underscore-dangle
Expand Down

0 comments on commit e0da910

Please sign in to comment.