Mocha compiler that enables webpack-like importing of images (PNG, JPG, GIF, SVG) in Node.js test environments. Current version 1.0.0 is stable and rarely updated. It works by replacing image require calls with a simple path string, making it ideal for testing components that import images. Unlike webpack loaders, this is a lightweight, no-config solution specifically designed for Mocha's --compilers flag. Requires Mocha as a peer dependency.
npm install mocha-image-compilerNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Installs mocha and mocha-image-compiler, creates a test file that imports a PNG image, and runs mocha with the compiler to replace image require with a path string.
Use only in Mocha test environment; for bundlers use appropriate loaders (e.g., file-loader).
Assume require('./image.png') returns a string path; do not expect a Buffer or URL object.Install mocha alongside mocha-image-compiler: npm install --save-dev mocha
Use only static string paths in require(); do not use variables or expressions.
Specify compilers in correct order: mocha --compilers js:babel/register,.:mocha-image-compiler
Run npm install --save-dev mocha-image-compiler in your project.
Use --compilers .:mocha-image-compiler (dot colon package-name). Ensure the dot matches the file extension (e.g., . for any extension, or .js:...).
Add --experimental-modules or use import statements. Alternatively, set 'type': 'commonjs' or use .cjs extension.