Home

Awesome

<p align="center"> <img src=".github/logo.svg" width="112px"> </p> <h1 align="center"> instant-mocha <br> <a href="https://npm.im/instant-mocha"><img src="https://badgen.net/npm/v/instant-mocha"></a> <a href="https://npm.im/instant-mocha"><img src="https://badgen.net/npm/dm/instant-mocha"></a> <a href="https://packagephobia.now.sh/result?p=instant-mocha"><img src="https://packagephobia.now.sh/badge?p=instant-mocha"></a> </h1>

Build tests with Webpack and run them with Mocha in one command

Features

How does it compare to mocha-webpack / mochapack? Answered in the FAQ.

<p align="center"> <a href="https://github.com/sponsors/privatenumber/sponsorships?tier_id=398771"><img width="412" src="https://raw.githubusercontent.com/privatenumber/sponsors/master/banners/assets/donate.webp"></a> <a href="https://github.com/sponsors/privatenumber/sponsorships?tier_id=416984"><img width="412" src="https://raw.githubusercontent.com/privatenumber/sponsors/master/banners/assets/sponsor.webp"></a> </p>

🚀 Install

npm i -D mocha webpack instant-mocha

Note: webpack and mocha are peer-dependencies so you can provide any version

👨‍🏫 Usage

instant-mocha [test paths/globs...]

You can either use npx (eg. npx instant-mocha ...) or add it to package.json scripts (eg. npm test) to invoke it.

Options

-w, --watch

Watch mode. Re-compiles the Webpack build and re-run tests on file-changes.

--webpack-config

Default: webpack.config.js

Path to the Webpack config.

Supports all options from Mocha CLI

For more info, run:

instant-mocha --help

Example

instant-mocha ---webpack-config webpack.config.js --require setup.js 'tests/*.spec.js'

💁‍♀️ FAQ

How do I enable source-maps?

Set devtool: 'source-map' in your Webpack config.

How do I add a progress bar?

Add webpackbar to your Webpack config.

Are node_modules automatically externalized?

They can't be automatically externalized because it's possible some dependencies require bundling or pre-processing. For example, packages in ESM format or deep-dependencies that are stubbed for testing.

It's recommended to externalize what you can in your Webpack config to speed up the build though. Consider using webpack-node-externals to do this.

How is it different from mocha-webpack or its fork mochapack?

First of all, major thanks to mocha-webpack for the original implementation and serving the community.

This project was created from scratch because mocha-webpack is no longer maintained and doesn't have Webpack 5 support.

Some notable improvements include:

Sponsors

<p align="center"> <a href="https://github.com/sponsors/privatenumber"> <img src="https://cdn.jsdelivr.net/gh/privatenumber/sponsors/sponsorkit/sponsors.svg"> </a> </p>