forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.wp-env.json schema: Fix schema and add unit tests (WordPress#63281)
Co-authored-by: t-hamano <[email protected]> Co-authored-by: ajlende <[email protected]>
- Loading branch information
1 parent
0c2704c
commit e434ec4
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
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,38 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import Ajv from 'ajv'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import wpEnvSchema from '../../schemas/json/wp-env.json'; | ||
import wpEnvJsonFile from '../../.wp-env.json'; | ||
|
||
describe( '.wp-env.json schema', () => { | ||
const ajv = new Ajv( { | ||
allowMatchingProperties: true, | ||
} ); | ||
|
||
test( 'strictly adheres to the draft-07 meta schema', () => { | ||
// Use ajv.compile instead of ajv.validateSchema to validate the schema | ||
// because validateSchema only checks syntax, whereas, compile checks | ||
// if the schema is semantically correct with strict mode. | ||
// See https://github.com/ajv-validator/ajv/issues/1434#issuecomment-822982571 | ||
const result = ajv.compile( wpEnvSchema ); | ||
|
||
expect( result.errors ).toBe( null ); | ||
} ); | ||
|
||
test( 'validates schema for .wp-env.json', () => { | ||
// We want to validate the .wp-env.json file using the local schema. | ||
const { $schema, ...metadata } = wpEnvJsonFile; | ||
|
||
// we expect the $schema property to be present in the .wp-env.json file | ||
expect( $schema ).toBeTruthy(); | ||
|
||
const result = ajv.validate( wpEnvSchema, metadata ) || ajv.errors; | ||
|
||
expect( result ).toBe( true ); | ||
} ); | ||
} ); |