Registry / testing / hmpo-nunjucks-test

hmpo-nunjucks-test

JSON →
library3.0.0jsnpmunverified

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-test
INSTALL
IMPORT
SIG · HMPO-NUNJUCKS-TEST
H
hmpo-nunjucks-test
testingjavascriptv3.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

renderer
✓ import { renderer } from 'hmpo-nunjucks-test';
✗ const renderer = require('hmpo-nunjucks-test').renderer;
The primary factory function for creating Nunjucks renderers. While CommonJS is still supported, ESM is preferred in modern Node.js environments.
hmpoNunjucksTest
✓ import * as hmpoNunjucksTest from 'hmpo-nunjucks-test';
✗ const hmpoNunjucksTest = require('hmpo-nunjucks-test');
CommonJS `require` returns an object containing named exports. For ESM, use `import * as` for similar behavior.

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.

const path = require('path'); const { renderer } = require('hmpo-nunjucks-test'); const fs = require('fs'); // Create dummy view and locale files for the example const viewsDir = path.resolve(__dirname, 'views'); const localeDir = path.resolve(__dirname, 'locale'); fs.mkdirSync(viewsDir, { recursive: true }); fs.mkdirSync(localeDir, { recursive: true }); fs.writeFileSync(path.join(viewsDir, 'exampleTemplate.html'), ` <h1>Hello, {{ data.name }}!</h1> <p>{{ translate('greeting') }}</p> {% from 'components/my-component.html' import myComponent %} {{ myComponent(param='component-data') }} `); fs.writeFileSync(path.join(viewsDir, 'components', 'my-component.html'), ` {% macro myComponent(param) %} <p>This is a component with param: {{ param }}</p> {% endmacro %} `); fs.writeFileSync(path.join(localeDir, 'en.json'), ` { "greeting": "Welcome to the Nunjucks test!" } `); // Initialize the Nunjucks renderer const myRenderFunc = renderer( [viewsDir], [path.join(localeDir, 'en.json')] ); // Render a template const templateOutput = myRenderFunc({ template: 'exampleTemplate.html', translate: true }, { data: { name: 'World' } }); console.log('--- Template Output ---\n', templateOutput); // Render a component directly const componentOutput = myRenderFunc({ component: 'myComponent', params: { param: 'another-component-data' }, ctx: true }); console.log('\n--- Component Output ---\n', componentOutput); // Clean up dummy files (optional for actual usage) // fs.rmSync(viewsDir, { recursive: true, force: true }); // fs.rmSync(localeDir, { recursive: true, force: true });
Debug
Known issues
breakingVersion 3.0.0 of hmpo-nunjucks-test requires Node.js runtime version 24.x. Projects running on older Node.js versions must upgrade their environment to use v3.x.
fix
Upgrade your Node.js environment to version 24.x or newer, or stick to hmpo-nunjucks-test v2.x for older Node.js versions.
affects: >=3.0.0
gotchaThis library has a peer dependency on `hmpo-components`. While npm typically warns, ensure `hmpo-components` is installed in your project, as its globals and filters are often implicitly expected.
fix
Install `hmpo-components` in your project: `npm install hmpo-components` or `yarn add hmpo-components`.
affects: >=1.0.0
Errors
Common errors & fixes
Error: The 'views' parameter must be a string or array of strings.
The `views` argument passed to `renderer` is not a string or an array of strings.
fix
Ensure `renderer(views, ...)` receives a valid path string or an array of path strings, e.g., `renderer(['./views'], ...)`.
Nunjucks Error: template not found: my-template.html
The specified template file does not exist in any of the configured `views` directories.
fix
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.
Nunjucks Error: Unknown filter "myCustomFilter"
A custom filter used in a Nunjucks template was not registered with the Nunjucks environment.
fix
Pass an object containing your custom filters to the `filters` parameter of the `renderer` function, e.g., `renderer(views, locales, globals, { myCustomFilter: () => {} })`.
TypeError: myRenderFunc is not a function
The `renderer` factory function was not called, or its return value (the actual render function) was not correctly assigned to a variable.
fix
Ensure you call `renderer(...)` and assign its result: `const myRenderFunc = renderer(views, locales);`.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
hmpo-componentsrequiredProvides default Nunjucks globals and filters, essential for typical usage.
Agent activity
6 hits · last 30 days
node
6
Resources
hmpo-nunjucks-test — npm install hmpo-nunjucks-test · libregistry