Skip to content
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

Fix warnings during tests and prevent them from reoccurring #1769

Merged
merged 7 commits into from
Jul 10, 2017

Conversation

nylen
Copy link
Member

@nylen nylen commented Jul 6, 2017

We have a few warnings appearing during test suite runs:

  1) full post content fixture core__table:
     Error: Warning caught via console.error: Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of <table>. Make sure you don't have any extra whitespace between tags on each line of your source code. See table > #text.

  2) state editor() "before all" hook:
     Error: Warning caught via console.error: The "save" property must be specified and must be a valid function.

  3) state editor() "after all" hook:
     Error: Warning caught via console.error: Block "core/test-block" is not registered.

(Output is from the test suite after checking out only the first commit in this branch.)

Like in PHPUnit, these should fail the build. The way of accomplishing this in JavaScript is a bit hacky but I think it is probably worth doing.

@gziolo - it looks like this may cause problems with Jest and #1382 (IMO adopting Jest is more important than this change). Thoughts?

@EphoxJames - I cannot figure out why these warnings about whitespace text nodes appear in test mode but not when saving/editing posts. Thoughts?

@nylen
Copy link
Member Author

nylen commented Jul 6, 2017

Rebased after adding Jest in #1382. This seems to still be working fine (try it by applying this, for example):

diff --git a/blocks/api/test/registration.js b/blocks/api/test/registration.js
index d601ac5..6141bb8 100644
--- a/blocks/api/test/registration.js
+++ b/blocks/api/test/registration.js
@@ -36,6 +36,7 @@ describe( 'blocks', () => {
 		setUnknownTypeHandler( undefined );
 		setDefaultBlock( undefined );
 		console.error.restore();
+		console.error( 'hi :)' );
 	} );
 
 	describe( 'registerBlockType()', () => {

@nylen nylen force-pushed the fix/warnings-during-tests branch from 735d432 to c90bd80 Compare July 6, 2017 22:37
@gziolo
Copy link
Member

gziolo commented Jul 7, 2017

I like the idea of promoting console errors to test errors unless explicitly wrapped with proper expect call 👍

@nylen nylen force-pushed the fix/warnings-during-tests branch 6 times, most recently from 19c4cf8 to fcea6e8 Compare July 8, 2017 10:53
@nylen
Copy link
Member Author

nylen commented Jul 8, 2017

080b7a5 is interesting code, but not the kind I'd like to merge, especially since this is only needed during test runs. Now taking a different approach that allows only these mysterious validateDOMNesting warnings:

Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of <table>. Make sure you don't have any extra whitespace between tags on each line of your source code. See table > #text.

@BoardJames
Copy link

I'll remove the whitespace from the table serialization test input which I'd imagine will fix the warning.
It seems a pretty silly warning though as whitespace does nothing to break xhtml and actually makes the test input readable.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 60309fd55f0e877b88e60ca41850f363c110faf4 on fix/warnings-during-tests into ** on master**.

@nylen nylen force-pushed the fix/warnings-during-tests branch from 60309fd to d2954b8 Compare July 10, 2017 09:49
@nylen
Copy link
Member Author

nylen commented Jul 10, 2017

I'll remove the whitespace from the table serialization test input which I'd imagine will fix the warning.

👍 I guess this is OK, though it'd be nice to know more about what is happening here.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 17.816% when pulling d2954b8 on fix/warnings-during-tests into d157b5e on master.

@nylen nylen merged commit 4e0ea5c into master Jul 10, 2017
@nylen nylen deleted the fix/warnings-during-tests branch July 10, 2017 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants