From a3a7cf6d79de7545a4c3a7ffa616ccbfaeaecde1 Mon Sep 17 00:00:00 2001 From: Max Belsky Date: Wed, 21 Jun 2023 11:47:28 +0200 Subject: [PATCH 1/3] Fix error code of AVV_ERR_ROOT_PLG_BOOTED --- lib/errors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/errors.js b/lib/errors.js index 338b8e8..1844ce3 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -54,7 +54,7 @@ module.exports = { "Plugin must be a function or a promise. Received: '%s'" ), AVV_ERR_ROOT_PLG_BOOTED: createError( - 'AVV_ERR_PLUGIN_NOT_VALID', + 'AVV_ERR_ROOT_PLG_BOOTED', 'Root plugin has already booted' ), AVV_ERR_PARENT_PLG_LOADED: createError( From 9c33b0a5c33fc0d64712e2b22eba5e1e6075aa47 Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Fri, 23 Jun 2023 16:55:28 +0200 Subject: [PATCH 2/3] add unit tests --- test/errors.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/errors.test.js b/test/errors.test.js index 40cc9cc..8a22c79 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -96,3 +96,23 @@ test('Create the error without the new keyword', t => { t.equal(err.message, 'Not available') t.equal(err.code, 'CODE') }) + +test('Correct codes of AvvioErrors', t => { + const testcases = [ + 'AVV_ERR_EXPOSE_ALREADY_DEFINED', + 'AVV_ERR_CALLBACK_NOT_FN', + 'AVV_ERR_PLUGIN_NOT_VALID', + 'AVV_ERR_ROOT_PLG_BOOTED', + 'AVV_ERR_PARENT_PLG_LOADED', + 'AVV_ERR_READY_TIMEOUT' + ] + + t.plan(testcases.length + 1) + // errors.js exposes errors and the createError fn + t.equal(testcases.length + 1, Object.keys(errors).length) + + for (const testcase of testcases) { + const error = new errors[testcase]() + t.equal(error.code, testcase) + } +}) From 3665463eeaaf25303a8f5373dc3882c6245c9db0 Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Fri, 23 Jun 2023 17:08:33 +0200 Subject: [PATCH 3/3] fix --- test/errors.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/errors.test.js b/test/errors.test.js index 8a22c79..59b5de4 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -1,7 +1,8 @@ 'use strict' const { test } = require('tap') -const { createError } = require('../lib/errors') +const errors = require('../lib/errors') +const createError = errors.createError const expectedErrorName = 'AvvioError'