From 45afcde43ba699cec57625c6e8571230f75d0aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Dewitte?= Date: Wed, 29 May 2024 16:34:30 +0200 Subject: [PATCH] Get original function name in AVV_ERR_READY_TIMEOUT --- boot.js | 6 ++++-- test/on-ready-timeout-await.test.js | 33 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 test/on-ready-timeout-await.test.js diff --git a/boot.js b/boot.js index 2addb6d..e7d0a52 100644 --- a/boot.js +++ b/boot.js @@ -479,7 +479,7 @@ function callWithCbOrNextTick (func, cb) { } function timeoutCall (func, rootErr, context, cb) { - const name = func.name + const name = func.unwrappedName ?? func.name debug('setting up ready timeout', name, this._opts.timeout) let timer = setTimeout(() => { debug('timed out', name) @@ -571,7 +571,9 @@ function encapsulateTwoParam (func, that) { } function encapsulateThreeParam (func, that) { - return _encapsulateThreeParam.bind(that) + const wrapped = _encapsulateThreeParam.bind(that) + wrapped.unwrappedName = func.name + return wrapped function _encapsulateThreeParam (err, cb) { let res if (!func) { diff --git a/test/on-ready-timeout-await.test.js b/test/on-ready-timeout-await.test.js new file mode 100644 index 0000000..9593935 --- /dev/null +++ b/test/on-ready-timeout-await.test.js @@ -0,0 +1,33 @@ +'use strict' + +/* eslint no-prototype-builtins: off */ + +const { test } = require('tap') +const boot = require('../boot') + +test('onReadyTimeout', async (t) => { + const app = boot({}, { + timeout: 10, // 10 ms + autostart: false + }) + + app.use(function one (innerApp, opts, next) { + t.pass('loaded') + innerApp.ready(function readyNoResolve (err, done) { + t.notOk(err) + t.pass('first ready called') + // Do not call done() to timeout + }) + next() + }) + + await app.start() + + try { + await app.ready() + t.fail('should throw') + } catch (err) { + t.equal(err.message, 'Plugin did not start in time: \'readyNoResolve\'. You may have forgotten to call \'done\' function or to resolve a Promise') + // And not Plugin did not start in time: 'bound _encapsulateThreeParam'. You may have forgotten to call 'done' function or to resolve a Promise + } +})