Global Application Helpers (Mixins) Don't Work within Test-Harness

Description

While developing a new Coldbox 7 module, if you launch the app via the test-harness, none of the global helpers are available in interceptors, layouts, or views. However, they are available in handlers.

Loading the module normally when installed via Forgebox or in modules_app still works as expected.

This issue is problematic because it makes it impossible to develop and test modules using the Ortus Coldbox Module Template if your app depends on use global application helpers.

Here’s the easiest way to replicate the issue:

  1. Clone and download the route-visualizer Coldbox module

  2. Create a new file named mixins.cfm in /helpers/

  3. Register the mixin as a global application helper in ModuleConfig.cfc

  4. Update the /layouts/Main.cfm file and include `bar()` somewhere

  5. Alternatively, you can do the same thing in /views/home/index.cfm, or try to use bar() in an interceptor method like preProcess()

  6. Install Coldbox 7.3 in the test-harness folder install coldbox

  7. Fire up one of the preconfigured server.json files in the module root (e.g. server start name=server-lucee@5.json

  8. Navigate to the /route-visualizer/ module.

  9. You will trigger an exception error that bar() is undefined.



Attachments

3

Activity

Show:

David Levin September 13, 2024 at 9:19 PM

Thank you! That did the trick! Good idea to update the module-template for anyone else who runs into this issue.

Luis Majano September 13, 2024 at 8:58 AM

This is a hard one since we are bootstrapping things AFTER ColdBox has loaded to do integration testing. Again, that means that interceptors have been loaded already with their helpers. So, if you want them to get the helpers, we need to announce the interception call: cbLoadInterceptorHelpers

This means in our template, after the rendered restart we need to reload the event too:

I will add this to the template.

David Levin September 12, 2024 at 5:07 PM

thank you for the tip about starting up the renderer again. Adding the line you provided partially fixed the issue for layouts and views. However, interceptors still don’t see the global application helpers.

To replicate the issue, you can create a new interceptor in the route-visualizer module and register it in ModuleConfig.cfc

Reinit the app and you will see an exception “No matching function [BAR] found”

Luis Majano September 12, 2024 at 9:59 AM

The issue lies on the fact that the Renderer is a singleton and might have been loaded already so your custom loaded module has not had a chance to contribute it’s mixins.

If you want to test this specifically what I would suggest is that here in this method:

After the module is bootstrapped that you do this

This will startup the renderer again with your contributions.

David Levin September 11, 2024 at 9:22 PM

I did a little digging on my own to see if I could figure out why handlers still have the global application helpers, but views, layouts, and interceptors don’t.

When I dump out cbInjectedHelpers in a handler, I see a struct containing all registered helpers:

However, in the layout, view, or interceptor, I only see one:

I’m not sure why it’s missing everywhere else when going through the test-harness.

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Affects versions

Priority

Sentry

Created September 11, 2024 at 8:52 PM
Updated September 13, 2024 at 9:19 PM
Resolved September 13, 2024 at 8:58 AM