npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

instant-mocha

v1.5.2

Published

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

Downloads

10,657

Readme

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

Features

  • Source-map support
  • Builds and runs in-memory
  • Inherits Mocha CLI
  • Supports Webpack 5 + Mocha 8, 9, & 10

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

Support this project by ⭐️ starring and sharing it. Follow me to see what other cool projects I'm working on! ❤️

🚀 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'
  • Load Webpack config from webpack.config.js
  • Load setup script from setup.js. Note, this is not apart of the build and is loaded directly from Node.js
  • Find and run tests that matches glob 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:

  • Written in TypeScript whereas mocha-webpack uses Flow.
  • Doesn't re-implement another file-watching mechanism Relies on Webpack's watcher instead.
  • Loosely coupled with Mocha and Webpack The API surface used is very narrow so it works with most versions, (eg. Webpack 4 & 5).
  • Correct exit codes Mocha and mocha-webpack returns the number of failed tests as the exit code. instant-mocha only uses exit code 1 for any test failures as per Bash convention.
  • Smaller size Reuses a lot from Webpack & Mocha so it's much lighter: instant-mocha install size vs mocha-webpack install size

💼 License

MIT © Hiroki Osame

Logo made by monkik