Closed Bug 1249106 Opened 8 years ago Closed 8 years ago

Fail tests when React propType errors are logged

Categories

(DevTools :: General, defect, P2)

defect

Tracking

(firefox47 affected, firefox48 fixed)

RESOLVED FIXED
Firefox 48
Tracking Status
firefox47 --- affected
firefox48 --- fixed

People

(Reporter: linclark, Assigned: linclark)

References

Details

(Whiteboard: [btpp-fix-later])

Attachments

(1 file, 4 obsolete files)

To ensure that APIs don't unintentionally drift, we should fail tests when React logs errors about propTypes.

:bgrins says that it's pretty easy to intercept the console.error messages.
Flags: needinfo?(bgrinstead)
You can use something like the following:

https://dxr.mozilla.org/mozilla-central/source/devtools/shared/acorn/tests/unit/head_acorn.js#41-75

This will watch the messages.  You can trim down the listener to just do what you need.  This example does not actually fail a test, just dumps some things (some evildoer changed our console listeners to not fail anymore...).  Anyway, add a call to ok(false, ...) when you see a bad message.
Flags: needinfo?(bgrinstead)
Attached patch Bug1249106.patch (obsolete) — Splinter Review
Thanks for the pointer, that's exactly what I was looking for.

Unfortunately I can't seem to get it to fail on my local, even when I introduce a failed propType. My guess is that when I'm running the test, it's running with the production version of React, but I'm not sure.
Assignee: nobody → lclark
Status: NEW → ASSIGNED
Attached patch failed-proptype.patch (obsolete) — Splinter Review
Adding a patch that should in theory make it fail.
(In reply to Lin Clark [:linclark] from comment #2)
> Unfortunately I can't seem to get it to fail on my local, even when I
> introduce a failed propType. My guess is that when I'm running the test,
> it's running with the production version of React, but I'm not sure.

Do you have `ac_add_options --enable-debug-js-modules` set in your .mozconfig?

The example in https://dxr.mozilla.org/mozilla-central/source/devtools/shared/acorn/tests/unit/head_acorn.js#41-75 is a 'console service' listener which means it will listen for page errors - and I'm guessing that these warnings are going through the console API instead (console.warn, etc).  Here's a small test that sets up a console API listener: https://dxr.mozilla.org/mozilla-central/source/dom/tests/browser/browser_bug1004814.js
Attached patch Bug1249106.patch (obsolete) — Splinter Review
This now fails tests on debug builds if any of the props passed in don't pass propType validation. You can see an example here:

https://treeherder.mozilla.org/#/jobs?repo=try&revision=13765cf005e6&selectedJob=17214597
Attachment #8720806 - Attachment is obsolete: true
Attachment #8720807 - Attachment is obsolete: true
Attachment #8723435 - Flags: review?(jryans)
Comment on attachment 8723435 [details] [diff] [review]
Bug1249106.patch

Review of attachment 8723435 [details] [diff] [review]:
-----------------------------------------------------------------

::: devtools/client/framework/test/shared-head.js
@@ +50,5 @@
> +    var message = subject.wrappedJSObject.arguments[0];
> +
> +    // React has a few different type-related errors (which are output with
> +    // console.error). This regex should catch them all.
> +    if (/Failed.*Type/.test(message)) {

What other messages are possible?  I am little worried this regex is too general and could match on things we don't care about here.

The example try run only contained "Failed propType" in the messages, but maybe you're saying others are possible too?

@@ +61,5 @@
> +registerCleanupFunction(() => {
> +  Services.obs.removeObserver(ConsoleObserver, "console-api-log-event");
> +});
> +
> +

Nit: remove extra blank line
Attachment #8723435 - Flags: review?(jryans) → feedback+
Attached patch Bug1249106-fail-proptype.patch (obsolete) — Splinter Review
Based on the feedback, I limited the check to failed proptypes. Eventually we might want to fail on more errors (and even more than I had originally included), but for now we can just fail on prop types.
Attachment #8725491 - Flags: review?(jryans)
Comment on attachment 8725491 [details] [diff] [review]
Bug1249106-fail-proptype.patch

Review of attachment 8725491 [details] [diff] [review]:
-----------------------------------------------------------------

Commit message needs bug number.

::: devtools/client/framework/test/shared-head.js
@@ +49,5 @@
> +  observe: function(subject, topic, data) {
> +    var message = subject.wrappedJSObject.arguments[0];
> +
> +    // React has a few different type-related errors (which are output with
> +    // console.error). This regex should catch them all.

Update comment, since we're only catching Failed propType now?
Attachment #8725491 - Flags: review?(jryans) → review+
Attached patch Bug1249106.patchSplinter Review
Thanks for catching that. Fixed.
Attachment #8723435 - Attachment is obsolete: true
Attachment #8725491 - Attachment is obsolete: true
Attachment #8725989 - Flags: review+
Keywords: checkin-needed
yay... ?

I think this was probably introduced with a big commit to the memory tool on March 1. I'm working with them to fix it in Bug 1249106. Sorry about the confusion, and thanks for the helpful links.
Depends on: 1253650
Filter on TEAPOT-SPLINES.
Priority: -- → P2
Whiteboard: [btpp-fix-later]
https://hg.mozilla.org/mozilla-central/rev/12637684d990
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 48
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: