-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement custom validation + doc improvements
- Loading branch information
Showing
9 changed files
with
279 additions
and
6 deletions.
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,25 @@ | ||
const BaseValidator = require('./src/baseValidator.js'); | ||
|
||
class CustomValidator extends BaseValidator { | ||
|
||
/** | ||
* Any custom validation routines you want to run. | ||
* | ||
* You can either create a list of errors using the test interface | ||
* or just throw on the first error. | ||
* | ||
* @param {STAC} data | ||
* @param {Test} test | ||
* @param {import('.').Report} report | ||
* @param {import('.').Config} config | ||
* @throws {Error} | ||
*/ | ||
async afterValidation(data, test, report, config) { | ||
if (data.id === 'solid-earth') { | ||
test.deepEqual(data.example, [1,2,3]); | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = CustomValidator; |
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,41 @@ | ||
const { STAC } = import('stac-js'); | ||
|
||
class BaseValidator { | ||
|
||
/** | ||
* | ||
*/ | ||
constructor() { | ||
} | ||
|
||
/** | ||
* Any preprocessing work you want to do on the data. | ||
* | ||
* @param {Object} data | ||
* @param {import('.').Report} report | ||
* @param {import('.').Config} config | ||
* @returns {Object} | ||
*/ | ||
async afterLoading(data, report, config) { | ||
return data; | ||
} | ||
|
||
/** | ||
* Any custom validation routines you want to run. | ||
* | ||
* You can either create a list of errors using the test interface | ||
* or just throw on the first error. | ||
* | ||
* @param {STAC} data | ||
* @param {Test} test | ||
* @param {import('.').Report} report | ||
* @param {import('.').Config} config | ||
* @throws {Error} | ||
*/ | ||
async afterValidation(data, test, report, config) { | ||
|
||
} | ||
|
||
} | ||
|
||
module.exports = BaseValidator; |
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,155 @@ | ||
const assert = require('assert'); | ||
|
||
class Test { | ||
|
||
constructor() { | ||
this.errors = []; | ||
} | ||
|
||
truthy(...args) { | ||
try { | ||
assert(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
deepEqual(...args) { | ||
try { | ||
assert.deepEqual(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
deepStrictEqual(...args) { | ||
try { | ||
assert.deepStrictEqual(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
doesNotMatch(...args) { | ||
try { | ||
assert.doesNotMatch(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
async doesNotReject(...args) { | ||
try { | ||
await assert.doesNotReject(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
doesNotThrow(...args) { | ||
try { | ||
assert.doesNotThrow(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
equal(...args) { | ||
try { | ||
assert.equal(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
fail(...args) { | ||
try { | ||
assert.fail(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
ifError(...args) { | ||
try { | ||
assert.ifError(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
match(...args) { | ||
try { | ||
assert.match(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
notDeepEqual(...args) { | ||
try { | ||
assert.notDeepEqual(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
notDeepStrictEqual(...args) { | ||
try { | ||
assert.notDeepStrictEqual(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
notEqual(...args) { | ||
try { | ||
assert.notEqual(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
notStrictEqual(...args) { | ||
try { | ||
assert.notStrictEqual(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
ok(...args) { | ||
try { | ||
assert.ok(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
async rejects(...args) { | ||
try { | ||
await assert.rejects(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
strictEqual(...args) { | ||
try { | ||
assert.strictEqual(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
throws(...args) { | ||
try { | ||
assert.throws(...args); | ||
} catch (error) { | ||
this.errors.push(error); | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = Test; |