From 93eb8a8cda7f2d8e440da25af41ae70ef5b71c79 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 26 Aug 2021 08:49:29 -0600 Subject: [PATCH] Core: Improve warning for incorrect hook usage to include module name Add the names of the relevant modules so the message is more actionable for users who encounter it. Fixes https://github.com/qunitjs/qunit/issues/1647. --- src/module.js | 6 ++++-- test/cli/cli-main.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/module.js b/src/module.js index 6c7dadfd5..75a7594ff 100644 --- a/src/module.js +++ b/src/module.js @@ -112,8 +112,10 @@ function processModule( name, options, executeNow, modifiers = {} ) { function setHookFunction( module, hookName ) { return function setHook( callback ) { if ( config.currentModule !== module ) { - Logger.warn( "The `" + hookName + "` hook was called inside the wrong module. " + - "Instead, use hooks provided by the callback to the containing module. " + + Logger.warn( "The `" + hookName + "` hook was called inside the wrong module (`" + + config.currentModule.name + "`). " + + "Instead, use hooks provided by the callback to the containing module (`" + + module.name + "`). " + "This will become an error in QUnit 3.0." ); } module.hooks[ hookName ].push( callback ); diff --git a/test/cli/cli-main.js b/test/cli/cli-main.js index 267320f91..28ecca0af 100644 --- a/test/cli/cli-main.js +++ b/test/cli/cli-main.js @@ -671,7 +671,7 @@ CALLBACK: done`; const execution = await execute( command ); assert.equal( execution.code, 0 ); - assert.equal( execution.stderr, "The `beforeEach` hook was called inside the wrong module. Instead, use hooks provided by the callback to the containing module. This will become an error in QUnit 3.0.", "The warning shows" ); + assert.equal( execution.stderr, "The `beforeEach` hook was called inside the wrong module (`module providing hooks > module not providing hooks`). Instead, use hooks provided by the callback to the containing module (`module providing hooks`). This will become an error in QUnit 3.0.", "The warning shows" ); assert.equal( execution.stdout, expectedOutput[ command ] ); } );