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

Add local version of wp-env schema to .wp-env.json #63253

Merged
merged 1 commit into from
Jul 8, 2024
Merged

Conversation

t-hamano
Copy link
Contributor

@t-hamano t-hamano commented Jul 8, 2024

Similar to #61312

What?

This PR adds a reference to the local schema in the wp-env config file used by the Gutenberg project.

Why?

  • This will prevent incorrect fields from being defined in future updates to .wp-env.json.
  • As mentioned in this comment, there are some fields missing in the current schema. When fixing these, it will be easier to test using the .wp-env.json in the Gutenberg project.

Testing Instructions

  • Check out this PR.
  • Open the .wp-env.json file in a code editor.
  • The code editor should help you auto-complete fields and warn you about invalid fields and values.
@t-hamano t-hamano added Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Project Management Meta-issues related to project management of Gutenberg labels Jul 8, 2024
@t-hamano t-hamano self-assigned this Jul 8, 2024
@t-hamano t-hamano marked this pull request as ready for review July 8, 2024 14:56
Copy link

github-actions bot commented Jul 8, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: ajlende <ajlende@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@fabiankaegy fabiankaegy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this 👍

Copy link
Contributor

@ajlende ajlende left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

For our blocks and themes, we test the files with Ajv as part of the automated testing.

test.each( jsonFiles )( 'validates schema for `%s`', ( filepath ) => {
// We want to validate the block.json file using the local schema.
const { $schema, ...blockMetadata } = require( filepath );
expect( $schema ).toBe( 'https://schemas.wp.org/trunk/block.json' );
const result = ajv.validate( blockSchema, blockMetadata ) || ajv.errors;
expect( result ).toBe( true );
} );

test.each( jsonFiles )( 'validates schema for `%s`', ( filepath ) => {
// We want to validate the theme.json file using the local schema.
const { $schema, ...metadata } = require( filepath );
// we expect the $schema property to be present in the theme.json file
expect( $schema ).toBeTruthy();
const result = ajv.validate( themeSchema, metadata ) || ajv.errors;
expect( result ).toBe( true );
} );

Adding tests for our .wp-env.json would be a good next step.

@ajlende ajlende enabled auto-merge (squash) July 8, 2024 15:24
@ajlende ajlende merged commit 99352db into trunk Jul 8, 2024
73 of 74 checks passed
@ajlende ajlende deleted the env/add-schema branch July 8, 2024 15:31
@github-actions github-actions bot added this to the Gutenberg 18.8 milestone Jul 8, 2024
huubl pushed a commit to huubl/gutenberg that referenced this pull request Jul 10, 2024
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: ajlende <ajlende@git.wordpress.org>
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Jul 18, 2024
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: ajlende <ajlende@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Project Management Meta-issues related to project management of Gutenberg
3 participants