-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add full-content tests for parsing + blocks list + serialization #849
Conversation
I have a bad experience with tests like this (giant chunks of fixtures, with auto-generation). In my experience, this kind of tests breaks too often with false positives, because we continuously change the shape of the blocks or the output. And thus, we end up, regenerating the fixtures without taking much attention. I'd prefer several targeted tests instead of testing whole posts like this. |
I think this kind of test is crucially important, though I agree we need to find a good balance between "easy to add a new test" and "lots of unnecessary noise". Here are some things I'd like to achieve here:
I agree, these need to be smaller. However, I am also hoping that later on when our internal block structure is more stable, we can use this test structure to fix + verify examples of problematic post content that we find during testing. Invalid markup inside blocks, invalid block types, etc.
We shouldn't be changing the shape of the output so much anymore, so I'm pretty happy with the way steps (1) and (3) are working. For (2) I agree we need something much simpler; as long as we cover the list of blocks and their parsed attributes, this should be ok. Maybe the [
{
blockType: 'core/text',
content: [
'<p>some text</p>',
'<p>second paragraph</p>'
]
},
...
] |
That's one of the reasons I put this PR in the first place #448 to allow each block test its own attributes (parsing included). I'm not saying no to this PR, I wanted to share my concerns. And maybe, we should add more targeted tests to the parser unit tests to limit the scope of these fixtures tests. |
3f48cb9
to
3fc694a
Compare
I've updated the PR with smaller fixtures extracted from individual blocks in the demo content file. I've also simplified the way React trees are represented in the fixtures -
It still seems better to me to keep the blocks code simple and have the test code work around it. For now that means any code that tests our actual blocks needs to run first (before the tests that unregister all blocks), though we could definitely look at other approaches here.
What do you have in mind here? This is basically what this PR is doing now, with the advantage that it is very easy to add tests for new blocks because they are all done the same way. |
Actually, I'm way more satisfied with the current approach. It's way easier to reason block by block like this. I wonder if we can't search for blocks and error (or warning) if a block is not tested like this. This would make this test more discoverable and we'll enforce block implementers to add this test each time a block is created. |
Only applies to nested elements, not to blocks themselves.
64fd1a5
to
db47f0f
Compare
db47f0f
to
df253a2
Compare
I agree. I would still like to add tests here for how we deal with content in between blocks, but this can wait until a future PR.
Good idea. Done in df253a2 (and added missing fixtures for 2 blocks in 9f412a2). |
575b173
to
54a11f0
Compare
Any objections to me merging this in the next day or so? |
This PR adds a mechanism for testing all of the parsing and serialization logic at once:
f1c0511 adds the code that makes this work, including some helper code that generates (2) and (3) from the list above given (1) as follows:
GENERATE_MISSING_FIXTURES=y npm run test-unit -- --grep 'full post content fixture'
Then, 7f30894 (very large commit - I would recommend reviewing only the first commit for now) adds a couple of test fixtures based on the demo
post-content.js
to demonstrate how this works. There are a couple of issues:key
values of React elements differently. (Probably the way to solve this will be to do something more sophisticated than callingJSON.stringify
on a React tree, see this thread for example.)I had to make a couple of changes to the webpack config for this to work:
node.__dirname
so that the compiledtest/build.js
can read fixture files as expected.full-content.js
tests first because many of the other tests unregister all registered blocks (example).See #745, though I am reluctant to close that one before we have a large number of these test cases in place.