Skip to content

Commit

Permalink
Add test script to run just validation tests and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Glen Davies committed Feb 10, 2021
1 parent 0194064 commit 1def8d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
32 changes: 21 additions & 11 deletions projects/plugins/jetpack/extensions/shared/test/block-fixtures.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ the parsing and serialization of that block. Additionally, each deprecation for
a block should also have a fixture.

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:
`jetpack__blockname{__*,}.{html,json,serialized.html}`. For example, for the
`jetpack/whatsapp-button` block, the following four fixture files must exist:

1. `core__image.html` (or `core__image__specific-test-name.html`). Must
1. `jetpack__whatsapp-button.html` (or `jetpack__whatsapp-button__specific-test-name.html`). Must
contain a `<!-- wp:core/image -->` block.
2. `core__image.parsed.json` (or `core__image__specific-test-name.parsed.json`).
3. `core__image.json` (or `core__image__specific-test-name.json`).
4. `core__image.serialized.html` (or
`core__image__specific-test-name.serialized.html`).
2. `jetpack__whatsapp-button__image.parsed.json` (or `core__image__specific-test-name.parsed.json`).
3. `jetpack__whatsapp-button.json` (or `jetpack__whatsapp-button__specific-test-name.json`).
4. `jetpack__whatsapp-button.serialized.html` (or
`jetpack__whatsapp-button.serialized.html`).

For each deprecation a fixture should exist with the filename format
`core__image__deprecated-1.html`, with the number relating to the deprecation version.
`jetpack__whatsapp-button__deprecated-1.html`, with the number relating to the deprecation version.

Ideally all important attributes and features of the block should be tested
this way.
this way, for example with a gallery block where adding a `linkTo` attribute may significantly change the saved content of the block there might be a fixture that has the image tag wrapped in a `<a>` and named `jetpack__tiled-gallery__link-to-attachment.html`.

## Creating Fixtures
## Creating fixtures

When adding a new fixtures, only the first file above (1, e.g. `core__image.html`) needs
to be created manually, the other files are generated from this first file.
Expand Down Expand Up @@ -73,7 +73,13 @@ contents of the `.json` and `.serialized.html` files are as expected.
In particular, check that the `isValid` property is `true`, and that
the attributes are serialized correctly.

## Updating Fixtures
## Add a deprecation fixture

When adding a fixture for a block deprecation follow the same steps as above but name the new fixture file as `core__image__dreprecated-1.html`) where the number at the end represents the deprecation version. The content of this file should match the saved block content the deprecated version of the block

In the case of deprecations the content of the `.json` and `.serialized.html` files should match the content of the produced by the latest version of the block save method, ie. they should mimic what would happen to a blocks content when a deprecated version is loaded in the editor and migrated to be compatible with the new save method.

## Updating fixtures

The process for updating fixtures for existing tests is similar to that for creating them:

Expand All @@ -94,6 +100,10 @@ yarn fixtures:regenerate
After regenerating fixtures, check the diff (using git/github) to check that the changes were expected
and the block is still valid (`isValid` is `true`).

## Running the tests

The fixture tests will be run as part of running the `fixtures:generate` and `fixtures:regenerate` scripts and also as part of the `yarn test-extensions` test run. They can also be run independently with `yarn fixtures:test`

## Related

See the
Expand Down
1 change: 1 addition & 0 deletions projects/plugins/jetpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"distclean": "rm -rf node_modules && yarn clean",
"fixtures:regenerate": "REGENERATE_FIXTURES=y GENERATE_MISSING_FIXTURES=y yarn jest",
"fixtures:generate": "GENERATE_MISSING_FIXTURES=y yarn jest",
"fixtures:test": "jest validate.js",
"install-if-deps-outdated": "yarn install --check-files --production=false --frozen-lockfile",
"test-adminpage": "yarn test-client && yarn test-gui",
"test-client": "NODE_ENV=test NODE_PATH=tests:_inc/client tests/runner.js",
Expand Down

0 comments on commit 1def8d3

Please sign in to comment.