-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
js schema validation test and small fix
- Loading branch information
Showing
2 changed files
with
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** Ensure that the liquid class schema itself functions as intended, | ||
* and that all v1 liquid class fixtures will validate */ | ||
import Ajv from 'ajv' | ||
import path from 'path' | ||
import glob from 'glob' | ||
import { describe, expect, it } from 'vitest' | ||
import liquidClassSchemaV1 from '../../liquid-class/schemas/1.json' | ||
Check failure on line 7 in shared-data/js/__tests__/liquidClassSchema.test.ts
|
||
|
||
const fixtureV1Glob = path.join(__dirname, '../../liquid-class/fixtures/1/*.json') | ||
const defV1Glob = path.join(__dirname, '../../liquid-class/definitions/3/*.json') | ||
|
||
const ajv = new Ajv({ allErrors: true, jsonPointers: true }) | ||
|
||
const validateSchemaV1 = ajv.compile(liquidClassSchemaV1) | ||
|
||
describe('validate v1 liquid class definitions and fixtures', () => { | ||
const fixtures = glob.sync(fixtureV1Glob) | ||
|
||
fixtures.forEach(fixturePath => { | ||
const fixtureDef = require(fixturePath) | ||
|
||
it('fixture validates against schema', () => { | ||
const valid = validateSchemaV1(fixtureDef) | ||
const validationErrors = validateSchemaV1.errors | ||
|
||
if (validationErrors) { | ||
console.log( | ||
path.parse(fixturePath).base + | ||
' ' + | ||
JSON.stringify(validationErrors, null, 4) | ||
) | ||
} | ||
|
||
expect(validationErrors).toBe(null) | ||
expect(valid).toBe(true) | ||
}) | ||
}) | ||
|
||
const defs = glob.sync(defV1Glob) | ||
|
||
defs.forEach(defPath => { | ||
const liquidClassDef = require(defPath) | ||
|
||
it('liquid class definition validates against v1 schema', () => { | ||
const valid = validateSchemaV1(liquidClassDef) | ||
const validationErrors = validateSchemaV1.errors | ||
|
||
if (validationErrors) { | ||
console.log( | ||
path.parse(defPath).base + | ||
' ' + | ||
JSON.stringify(validationErrors, null, 4) | ||
) | ||
} | ||
|
||
expect(validationErrors).toBe(null) | ||
expect(valid).toBe(true) | ||
}) | ||
}) | ||
}) |
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