diff --git a/index.js b/index.js index c65d997..99cd1a3 100644 --- a/index.js +++ b/index.js @@ -66,7 +66,7 @@ function loadAndValidateEnvironment (_opts) { const isOptionValid = optsSchemaValidator(opts) if (!isOptionValid) { - const error = new Error(optsSchemaValidator.errors.map(e => e.message)) + const error = new Error(sharedAjvInstance.errorsText(optsSchemaValidator.errors, { dataVar: 'opts' })) error.errors = optsSchemaValidator.errors throw error } @@ -97,7 +97,7 @@ function loadAndValidateEnvironment (_opts) { const valid = ajv.validate(schema, merge) if (!valid) { - const error = new Error(ajv.errors.map(e => e.message).join('\n')) + const error = new Error(ajv.errorsText(ajv.errors, { dataVar: 'env' })) error.errors = ajv.errors throw error } diff --git a/test/basic.test.js b/test/basic.test.js index bca61d9..1ee43ca 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -213,7 +213,7 @@ const tests = [ }, data: { }, isOk: false, - errorMessage: 'must have required property \'PORT\'' + errorMessage: 'env must have required property \'PORT\'' }, { name: 'simple object - invalid data', @@ -228,7 +228,7 @@ const tests = [ }, data: [], isOk: false, - errorMessage: 'must NOT have fewer than 1 items,must be object,must match exactly one schema in oneOf' + errorMessage: 'opts/data must NOT have fewer than 1 items, opts/data must be object, opts/data must match exactly one schema in oneOf' }, { name: 'simple object - ok - with separator', @@ -304,7 +304,7 @@ const tests = [ }, data: {}, isOk: false, - errorMessage: 'must have required property \'ALLOWED_HOSTS\'' + errorMessage: 'env must have required property \'ALLOWED_HOSTS\'' }, { name: 'simple object - KO - multiple required properties', @@ -320,9 +320,7 @@ const tests = [ }, data: {}, isOk: false, - errorMessage: `must have required property 'A' -must have required property 'B' -must have required property 'C'` + errorMessage: 'env must have required property \'A\', env must have required property \'B\', env must have required property \'C\'' } ] diff --git a/test/custom-ajv.test.js b/test/custom-ajv.test.js index cd4a39a..6e8f418 100644 --- a/test/custom-ajv.test.js +++ b/test/custom-ajv.test.js @@ -214,7 +214,7 @@ const tests = [ }, data: { }, isOk: false, - errorMessage: 'must have required property \'PORT\'' + errorMessage: 'env must have required property \'PORT\'' }, { name: 'simple object - invalid data', @@ -229,7 +229,7 @@ const tests = [ }, data: [], isOk: false, - errorMessage: 'must NOT have fewer than 1 items,must be object,must match exactly one schema in oneOf' + errorMessage: 'opts/data must NOT have fewer than 1 items, opts/data must be object, opts/data must match exactly one schema in oneOf' } ] @@ -269,7 +269,7 @@ const noCoercionTest = { PORT: '44' }, isOk: false, - errorMessage: 'must be integer', + errorMessage: 'env/PORT must be integer', confExpected: { PORT: 44 }