Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: Add integration tests for block schema validation (#36351)
- Loading branch information
Showing
11 changed files
with
398 additions
and
1,364 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import Ajv from 'ajv-draft-04'; | ||
import glob from 'fast-glob'; | ||
import path from 'path'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import blockSchema from '../../schemas/json/block.json'; | ||
|
||
describe( 'block.json schema', () => { | ||
const blockFolders = glob.sync( 'packages/block-library/src/*', { | ||
onlyDirectories: true, | ||
ignore: [ 'packages/block-library/src/utils' ], | ||
} ); | ||
const testData = blockFolders.map( ( blockFolder ) => [ | ||
'core/' + path.basename( blockFolder ), | ||
path.join( blockFolder, 'block.json' ), | ||
] ); | ||
const ajv = new Ajv(); | ||
|
||
test( 'found block folders', () => { | ||
expect( blockFolders.length ).toBeGreaterThan( 0 ); | ||
} ); | ||
|
||
test.each( testData )( | ||
'validates schema for `%s`', | ||
( blockName, 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 ); | ||
} | ||
); | ||
} ); |