This directory contains sets of fixture files that are used to test the parsing and serialization logic.
Each test is made up of four fixture files:
fixture-name.html
: The initial post content.fixture-name.parsed.json
: The expected output of the PEG parser for this content (checked against the actual output of both the JS and PHP versions of the parser).fixture-name.json
: The expected representation of the block(s) inside the post content, along with their attributes and any nested content. The contents of this file are compared against the actual block object(s).fixture-name.serialized.html
: The expected result of callingserialize
on the parsed block object(s). The contents of this file are compared against the actual re-serialized post content. This final step simulates opening and re-saving a post.
Every block is required to have at least one such set of fixture files to test
the parsing and serialization of that block. These fixtures must be named like
core__blockname{__*,}.{html,json,serialized.html}
. For example, for the
core/image
block, the following four fixture files must exist:
core__image.html
(orcore__image__specific-test-name.html
). Must contain a<!-- wp:core/image -->
block.core__image.parsed.json
(orcore__image__specific-test-name.parsed.json
).core__image.json
(orcore__image__specific-test-name.json
).core__image.serialized.html
(orcore__image__specific-test-name.serialized.html
).
Ideally all important attributes and features of the block should be tested this way. New contributions in the form of additional test cases are always welcome - this is a great way for us to identify bugs and prevent them from recurring in the future.
When adding a new test, it's only necessary to create file (1) above, then there is a command you can run to generate (2) through (4):
GENERATE_MISSING_FIXTURES=y npm run test-unit test/integration/full-content/full-content.spec.js
However, when using this command, please be sure to manually verify that the
contents of the .json
and .serialized.html
files are as expected.
See the
full-content.spec.js
test file for the code that runs these tests.