Registry / testing / mocha-stylus-compiler

mocha-stylus-compiler

JSON →
library1.0.1jsnpmunverified

A Stylus compiler plugin for Mocha that allows requiring .styl files in tests, compiling them to CSS but ignoring the output (compiles to null). Version 1.0.1 is the latest and only stable release. It is a minimal tool for integrating Stylus preprocessing into Mocha test runs. Unlike alternative approaches (like using stylus directly or other Mocha compilers), this package specifically registers .styl files with Mocha's --compilers option, preventing parse errors when requiring Stylus files in tests. No updates since initial release; considered stable but unmaintained.

npm install mocha-stylus-compiler
INSTALL
IMPORT
SIG · MOCHA-STYLUS-COMPI
M
mocha-stylus-compiler
testingjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
require('mocha-stylus-compiler')
import mochaStylus from 'mocha-stylus-compiler'
This package is only used as a Mocha compiler via CLI flag, not imported directly in source code. However, if used programmatically with Mocha API, you would pass the function returned by require().

Shows how to set up and run Mocha tests that require .styl files using the Stylus compiler.

// Install mocha and mocha-stylus-compiler // npm install --save-dev mocha mocha-stylus-compiler // Create a test file test/example.test.js const assert = require('assert'); const styles = require('./styles.styl'); // This will compile to an empty object describe('Stylus', function() { it('should compile without error', function() { assert.equal(typeof styles, 'object'); }); }); // Run: npx mocha --compilers styl:mocha-stylus-compiler
Debug
Known issues
gotchaThe package compiles Stylus to CSS but discards the output, so requiring a .styl file returns an empty object `{}`. This may be unexpected if you intend to actually use the compiled CSS.
fix
If you need to use the compiled CSS in tests, consider using a different approach (e.g., compile Stylus files separately and read the output).
affects: >=1.0.0
deprecatedMocha v8+ deprecated the --compilers option in favor of --require with a custom compiler. The package may not work with newer Mocha versions.
fix
For Mocha v8+, use `--require mocha-stylus-compiler/register` if available, or switch to a compiler that supports the new API. Alternatively, downgrade Mocha to v7 or earlier.
affects: >=1.0.0
gotchaThe package only compiles .styl files with the extension `.styl`. If you use a different extension (e.g., .stylus), the compiler will not be applied.
fix
Rename your files to .styl or modify the compiler registration to match your extension.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mocha-stylus-compiler'
Package not installed, or not in node_modules when Mocha runs (often due to global Mocha installation).
fix
Install locally: `npm install --save-dev mocha-stylus-compiler` and use local Mocha: `npx mocha --compilers styl:mocha-stylus-compiler`
Error: require.extensions is not supported by webpack
Webpack does not allow modifying require.extensions, which this package relies on. This package is intended for Node.js Mocha, not webpack.
fix
Use a webpack loader for Stylus files (e.g., stylus-loader) instead of this package.
Error: Cannot find module 'stylus'
The package depends on `stylus` as a peer dependency, but it may not be installed.
fix
Install stylus: `npm install --save-dev stylus`
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
mocha-stylus-compiler — npm install mocha-stylus-compiler · libregistry