-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to inspectpack@4. Add regression tests to catch imports of format* utils. #263
Conversation
}; | ||
|
||
expect(dashboard.setProgress(data)).to.not.throw; | ||
expect(dashboard.progressbar.setProgress).to.have.been.calledOnce; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to make these asserts more firm, i.e. to.have.been.calledWith
, but I'm hitting the good ol' JS-floating-point-math-is-horrible thing. The crux of the issue is that a float like 0.57
gets evaluated in our calculations in this method as 0.56999999997
(or something of the like), and our rounding setup returns 0.56
/ 56%
. Not sure if we want to update our rounding logic in this method, but wanted to call out that this is happening. I don't like the idea of writing:
const data = {
value: 0.57
};
expect(dashboard.progressbar.setProgress).to.have.been.calledWith(0.56);
test/dashboard/index.spec.js
Outdated
expect(dashboard.screen.render).to.have.been.called; | ||
}); | ||
|
||
it("can setProblems", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'm having a hard time getting formatProblems
import
properly tested. The issue is that setProblems
, which is the only method that uses formatProblems
, doesn't actually invoke formatProblems
. Rather, formatProblems
is called in a function that gets assigned to a particular key in our problemsItems
collection. So the function is created but never actually run in our current tests, so that import
, as far as I can tell, never gets tested. If I change the import
syntax on that util, all tests still pass 😬 So, not much of a regression test 😞 Let me know if any of you have a thought on a way to solve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking at this and will try to get to a bit more by sometime on Tuesday...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think something like this may get you where you want to be:
diff --git a/test/dashboard/index.spec.js b/test/dashboard/index.spec.js
index 6c9dd5b..4cf3a98 100644
--- a/test/dashboard/index.spec.js
+++ b/test/dashboard/index.spec.js
@@ -1,8 +1,9 @@
"use strict";
const chalk = require("chalk");
-require("../base.spec");
+const base = require("../base.spec");
+const blessed = require("blessed");
const Dashboard = require("../../dashboard");
describe("dashboard", () => {
@@ -122,6 +123,21 @@ describe("dashboard", () => {
});
it("can setProblems", () => {
+ // Override ListBar fakes from what we do in `base.spec.js`.
+ // Note that these are **already** stubbed. We're not monkey-patching blessed.
+ blessed.listbar.returns({
+ selected: "selected",
+ setLabel: base.sandbox.spy(),
+ setProblems: base.sandbox.spy(),
+ selectTab: base.sandbox.spy(),
+ setItems: base.sandbox.stub().callsFake((obj) => {
+ // Naively simulate what setItems would do calling each object key.
+ Object.keys(obj).forEach((key) => obj[key]());
+ })
+ });
+
+ // Discard generic dashboard, create a new one with adjusted mocks.
+ dashboard = new Dashboard();
+
const data = {
value: {
duplicates: {
We're really pushing the boundaries of how much to mock, but here I think it may make sense because we really want to ensure those imports are (1) happening and (2) used.
Let me know if you need tips on getting even further in to things like asserting on what's called within formatProblems
or whatnot...
test/plugin/index.spec.js
Outdated
|
||
plugin.observeMetrics({ toJson }).subscribe({ | ||
next: () => {}, | ||
error: () => {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GLOBAL TIP: Use base.sandbox.spy()
in place of () => {}
. It can be asserted on and it's more clear your using a test double.
test/plugin/index.spec.js
Outdated
@@ -1,5 +1,8 @@ | |||
"use strict"; | |||
|
|||
const sinon = require("sinon"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GLOBAL: Don't use sinon
as a best practice. Instead get spys and stubs from base.sandbox
.
@ElreyB here are some additional things I'd like to see:
I think that's about the scope I'd want to see in this PR. I'm also running into issues getting this PR'ed code to run against our |
test/utils/format-versions.spec.js
Outdated
context("when package are present", () => { | ||
it("should return a handlebar compile template", () => { | ||
const data = { | ||
packages: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be too robust but I want to make sure it hit the pkgNamePath
function.
0b6b7e8
to
3cc3f28
Compare
@ryan-roemer This should be ready for re-review. I rebased it down to one commit already (force pushed), so you'll need a clean branch of this locally to test. Let me know if there's anything else you'd like to see in this PR. |
test/dashboard/index.spec.js
Outdated
and percent is falsy`, () => { | ||
data.value = null; | ||
|
||
expect(dashboard.setProgress(data)).to.not.throw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GLOBAL:
These have to be of the format of "something to call", so:
expect(() => { dashboard.setProgress(data); }).to.not.throw;
unless dashboard.setProgress(data)
returns a function to execute, which I don't believe it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I was adding comments to everything I saw as "Same comment here.", but there are a lot, so just assume I did that 😛
test/dashboard/index.spec.js
Outdated
]; | ||
|
||
it("can setSizes", () => { | ||
expect(dashboard.setSizes(data)).to.not.throw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here.
test/dashboard/index.spec.js
Outdated
mockSetItems(); | ||
// Discard generic dashboard, create a new one with adjusted mocks. | ||
dashboard = new Dashboard(); | ||
expect(dashboard.setSizes(data)).to.not.throw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here.
test/dashboard/index.spec.js
Outdated
const err = "error"; | ||
|
||
it("can setSizesError", () => { | ||
expect(dashboard.setSizesError(err)).to.not.throw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here.
test/dashboard/index.spec.js
Outdated
}; | ||
|
||
it("can setProblems", () => { | ||
expect(dashboard.setProblems(data)).to.not.throw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here.
test/dashboard/index.spec.js
Outdated
// Discard generic dashboard, create a new one with adjusted mocks. | ||
|
||
dashboard = new Dashboard(); | ||
expect(dashboard.setProblems(data)).to.not.throw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here.
test/plugin/index.spec.js
Outdated
tapAsync: base.sandbox.stub() // this is us in webpack-dashboard | ||
}; | ||
compiler = { | ||
// TODO: ONLY WEBPACK4, but that's what we have in devDeps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just convert this to a full explanatory comment and remove the TODO
. I don't thing we necessarily need to run these unit tests through the different versions...
test/plugin/index.spec.js
Outdated
}); | ||
|
||
it("should serialize errors when encountered", () => { | ||
base.sandbox.stub(inspectpack, "actions").rejects; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this need to be:
base.sandbox.stub(inspectpack, "actions").rejects();
?
If so, is this test working correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!!!
I've got lots of comments everywhere, but there mostly straightforward I think, so no re-review needed unless you want one.
Also, quick note that I'm on vacation with free time only here and there, so possibly won't get next opportunity to respond until next week. Feel free to clean up "good enough" and merge here if there are minor outstanding things for me, and we can take up together in follow-on work once I'm back next week.
b94b21f
to
420bd67
Compare
420bd67
to
09cc396
Compare
@ryan-roemer @ElreyB @ianwsperber Here's a WiP PR for the
inspectpack@4.0.0
migration! Don't merge yet, I'm still underway adding tests but wanted to get some 👀on things so far.I haven't undertaken any UI updates to leverage new
inspectpack
in this PR, mostly because I want to ensure we can getwebpack-dashboard
fully operational with latestinspectpack
. The focus of this PR is on testing and code coverage, and adding regression tests for ourformat*
utils.I'm going to drop comments in the diff below around some things I've uncovered while testing. Would appreciate any initial feedback you have!