hmpo-nunjucks-test is a specialized JavaScript library designed for testing Nunjucks templates, including robust support for localization and dynamic rendering. It is currently stable at version 3.0.0, which mandates Node.js v24.x for execution. While there isn't a strict release cadence, updates appear to be made on an as-needed basis, often involving dependency updates and Node runtime bumps. Its core functionality revolves around a `renderer` factory function that sets up a Nunjucks environment, allowing developers to create a render function capable of processing templates, raw strings, or components/macros. A key differentiator is its integrated support for `hmpo-components` globals and filters, and its focus on robust localization testing, making it particularly useful within the HMPO ecosystem for ensuring UI consistency and translation accuracy. It provides granular control over the rendering context, translation flags, and component parameters, addressing common testing challenges in Nunjucks-based applications.
npm install hmpo-nunjucks-testVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes the Nunjucks renderer with sample view and locale paths, then demonstrates rendering both a full template with context and localization, and a specific Nunjucks component.
Upgrade your Node.js environment to version 24.x or newer, or stick to hmpo-nunjucks-test v2.x for older Node.js versions.
Install `hmpo-components` in your project: `npm install hmpo-components` or `yarn add hmpo-components`.
Ensure `renderer(views, ...)` receives a valid path string or an array of path strings, e.g., `renderer(['./views'], ...)`.
Verify the template path and ensure it's accessible from one of the directories provided in the `views` array during `renderer` initialization. Check for typos or incorrect relative paths.
Pass an object containing your custom filters to the `filters` parameter of the `renderer` function, e.g., `renderer(views, locales, globals, { myCustomFilter: () => {} })`.Ensure you call `renderer(...)` and assign its result: `const myRenderFunc = renderer(views, locales);`.