File tree Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Original file line number Diff line number Diff line change 22 "name" : " stac-extensions" ,
33 "version" : " 1.1.0" ,
44 "scripts" : {
5- "test" : " npm run check-markdown && npm run check-examples" ,
5+ "test" : " jest && npm run check-markdown && npm run check-examples" ,
66 "check-markdown" : " remark . -f -r .github/remark.yaml" ,
77 "check-examples" : " stac-node-validator . --lint --verbose --schemaMap https://stac-extensions.github.io/processing/v1.1.0/schema.json=./json-schema/schema.json" ,
88 "format-examples" : " stac-node-validator . --format --schemaMap https://stac-extensions.github.io/processing/v1.1.0/schema.json=./json-schema/schema.json"
99 },
1010 "dependencies" : {
11+ "jest" : " ^27.4.4" ,
1112 "remark-cli" : " ^8.0.0" ,
1213 "remark-lint" : " ^7.0.0" ,
1314 "remark-lint-no-html" : " ^2.0.0" ,
Original file line number Diff line number Diff line change 1+ const { join } = require ( 'path' ) ;
2+ const { promises } = require ( 'fs' ) ;
3+ const { AjvOptions, rootDirectory, schemaPath } = require ( './validation.js' ) ;
4+ const ajv = new ( require ( 'ajv' ) ) ( AjvOptions ) ;
5+
6+ const examplePath = join ( rootDirectory , 'examples/collection.json' ) ;
7+
8+ let validate ;
9+ beforeAll ( async ( ) => {
10+ const data = JSON . parse ( await promises . readFile ( schemaPath ) ) ;
11+ validate = await ajv . compileAsync ( data ) ;
12+ } ) ;
13+
14+ describe ( 'Collection example' , ( ) => {
15+ it ( 'should pass validation' , async ( ) => {
16+ // given
17+ const example = JSON . parse ( await promises . readFile ( examplePath ) ) ;
18+
19+ // when
20+ let valid = validate ( example ) ;
21+
22+ // then
23+ expect ( valid ) . toBeTruthy ( )
24+ } ) ;
25+ } ) ;
Original file line number Diff line number Diff line change 1+ const axios = require ( 'axios' ) ;
2+ const { dirname, join } = require ( 'path' ) ;
3+ const iriFormats = require ( 'stac-node-validator/iri.js' ) ;
4+
5+ // const directory = dirname(fileURLToPath(import.meta.url));
6+
7+ const Schemas = new Map ( ) ;
8+ const loadSchema = function ( uri ) {
9+ let existing = Schemas . get ( uri ) ;
10+ if ( existing == null ) {
11+ existing = loadSchemaFromUri ( uri ) ;
12+ Schemas . set ( uri , existing ) ;
13+ }
14+ return existing ;
15+ }
16+
17+ /**
18+ * function passed in to Ajv instance which allows us to load schemas from a url at run time.
19+ */
20+ module . exports . loadSchemaFromUri = async function ( uri ) {
21+ try {
22+ let response = await axios . get ( uri ) ;
23+ return response . data ;
24+ } catch ( error ) {
25+ throw new Error ( `-- Schema at '${ uri } ' not found. Please ensure all entries in 'stac_extensions' are valid.` ) ;
26+ }
27+ }
28+
29+ module . exports . AjvOptions = { loadSchema, formats : Object . assign ( iriFormats ) } ;
30+ module . exports . rootDirectory = dirname ( __dirname ) ;
31+ module . exports . schemaPath = join ( module . exports . rootDirectory , 'json-schema/schema.json' ) ;
You can’t perform that action at this time.
0 commit comments