diff --git a/Makefile b/Makefile index e903db7..45daa10 100755 --- a/Makefile +++ b/Makefile @@ -95,7 +95,9 @@ test-examples: ## run medium (feature) tests test-bundle: ## run small (unit) tests test-bundle: build-bundle - $(NODE_BIN)/nyc --reporter=lcov --reporter=text-summary --report-dir="$(TARGET_PATH)/coverage" --exclude-after-remap $(NODE_BIN)/mocha $(TARGET_PATH)/test.js + $(NODE_BIN)/nyc --report-dir="$(TARGET_PATH)/coverage" --exclude-after-remap \ + --reporter=html --reporter=lcov --reporter=text-summary \ + $(NODE_BIN)/mocha $(TARGET_PATH)/test.js test-rules: ## validate the rules directory test-rules: build-bundle diff --git a/config/rollup.js b/config/rollup.js index 7655fc9..35f9839 100644 --- a/config/rollup.js +++ b/config/rollup.js @@ -76,6 +76,7 @@ const bundle = { 'intersection', 'isNil', 'isString', + 'kebabCase', ], 'node_modules/noicejs/out/main-bundle.js': [ 'BaseError', diff --git a/src/rule.ts b/src/rule.ts index 924bf9b..d539a0b 100644 --- a/src/rule.ts +++ b/src/rule.ts @@ -74,7 +74,7 @@ export async function loadRules(paths: Array, ctx: VisitorContext): Prom ctx.addSchema(data.name, data.definitions); } - rules.push(...data.rules.map((data: any) => new Rule(data))); + rules.push(...data.rules.map((data: RuleData) => new Rule(data))); } } diff --git a/test/error/TestError.ts b/test/error/TestError.ts new file mode 100644 index 0000000..1fa6c39 --- /dev/null +++ b/test/error/TestError.ts @@ -0,0 +1,34 @@ +import { expect } from 'chai'; +import { kebabCase } from 'lodash'; + +import { InvalidArgumentError } from '../../src/error/InvalidArgumentError'; +import { NotFoundError } from '../../src/error/NotFoundError'; + +const errors = [ + InvalidArgumentError, + NotFoundError, +]; + +describe('errors', () => { + for (const errorType of errors) { + describe(kebabCase(errorType.name), () => { + it('should have a message', () => { + const err = new errorType(); + expect(err.message).to.not.equal(''); + }); + + it('should include nested errors in the stack trace', () => { + const inner = new Error('inner error'); + const err = new errorType('outer error', inner); + expect(err.stack).to.include('inner', 'inner error message').and.include('outer', 'outer error message'); + }); + + it('should have the nested error', () => { + const inner = new Error('inner error'); + const err = new errorType('outer error', inner); + expect(err.cause()).to.equal(inner); + expect(err.length).to.equal(1); + }); + }); + } +}); diff --git a/test/utils/ajv/TestFriendlyErrors.ts b/test/utils/ajv/TestFriendlyErrors.ts new file mode 100644 index 0000000..d74afa3 --- /dev/null +++ b/test/utils/ajv/TestFriendlyErrors.ts @@ -0,0 +1,15 @@ +import { expect } from 'chai'; + +import { friendlyError } from '../../../src/utils/ajv'; + +describe('friendly errors', () => { + it('should have a message', () => { + const err = friendlyError({ + keyword: 'test', + dataPath: 'test-path', + schemaPath: 'test-path', + params: { /* ? */ }, + }); + expect(err.msg).to.not.equal(''); + }); +});