Skip to content

Fix test suite compatibility with Node v24 (CJS/ESM, locutus v3, twing v6)#64

Open
alex-ahumada wants to merge 3 commits into
JohnAlbin:mainfrom
alex-ahumada:fix/locutus-update-tests
Open

Fix test suite compatibility with Node v24 (CJS/ESM, locutus v3, twing v6)#64
alex-ahumada wants to merge 3 commits into
JohnAlbin:mainfrom
alex-ahumada:fix/locutus-update-tests

Conversation

@alex-ahumada
Copy link
Copy Markdown

@alex-ahumada alex-ahumada commented May 21, 2026

Node v24 exposed three pre-existing incompatibilities introduced by recent dependency and runtime upgrades. This PR fixes all three.

locutus 2.x → 3.x

  • Import path fix: locutus v3 added a package exports field (./*./esm/*.js). Importing locutus/php/datetime/date.js with the .js suffix resolved to …/date.js.js, causing uncaught exceptions across the entire test suite. Fixed by using the bare path locutus/php/datetime/date.
  • Named export: locutus v3 switched from a default export to a named export (export function date). Updated to import { date }.

Node v24 CJS/ESM interop

  • Node ≥22.12 adds a module.exports key to the namespace object when importing a CJS module as ESM. The exports/ tests were using a hardcoded Object.keys(exports).length - N subtraction that broke when this extra key appeared. Replaced with an explicit wrapper-key filter in all three exports tests.

twing 5.x → 6.x

twing v5 calls util.isNullOrUndefined, which Node v23 removed entirely, causing all 94 Twing tests to fail.
twing v6 is a significant rewrite. Key breaking changes addressed.

Area What changed in v6 What we did
Filter/function factories new TwingFilter/Function removed createFilter/createFunction (same arg order)
Callable signature All callables now receive executionContext as first arg Added _ctx first param to all 16 callables
Template from string env.createTemplate(str) removed createArrayLoader({}) + loader.setTemplate + env.loadTemplate
safe_join Internal join(ctx, val, glue, and)and=undefined leaks into output Pass null explicitly as 4th arg
placeholder Markup objects are always truthy even when empty String(escaped) before falsy check in wrapPlaceholder
without Twig [] is a plain JS array, not a Map Removed Map-flattening loop; simplified to (_ctx, element, ...args)
Argument strictness Extra args throw at runtime if not declared Added is_variadic: true to active_theme and active_theme_path
render_var v6 enforces acceptedArguments at compile time Fixed missing acceptedArguments in function registration
create_attribute Inline hashes are plain JS objects, not Maps Promoted from test.failing — now works correctly
|keys rendering Arrays render as 'Array' in string context (closer to PHP Twig) Added |join(",") in Twing-specific without tests

@alex-ahumada alex-ahumada changed the title Use updated locutus imports Fix test suite compatibility with Node v24 (locutus v3, twing v6) May 21, 2026
@alex-ahumada alex-ahumada changed the title Fix test suite compatibility with Node v24 (locutus v3, twing v6) Fix test suite compatibility with Node v24 (CJS/ESM, locutus v3, twing v6) May 21, 2026
@alex-ahumada
Copy link
Copy Markdown
Author

My bad, the locutus imports issues were already addressed in #63, I missed that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant