JavaScript unit test framework weigh-in

Dossy Shiobara
This Old Code
Published in
2 min readOct 6, 2017

It really annoys me how the Node.js community seems to pretty much ignore, or at least accept, how kitchen-sinky everything is, as in, packages have dependency trees that include “everything and the kitchen sink.” It’s not uncommon for a package to have 50 MB worth of dependencies. Compare that to the source for the Linux 1.0 kernel at only 5.7 MB, and that’s the source code for a whole OS kernel’s worth of functionality.

I’ve been examining different unit testing framework options, and I decided to do a basic weigh-in: see how much each one “weighs” in bytes with all their dependencies. I chose five of the more popular options out there today: Jasmine, Jest, Karma, Mocha, TAP.

Here’s how I weighed them:

$ mkdir weigh-in
$ cd weigh-in/
$ npm_config_prefix=$(pwd) npm ls -g
/Users/dossy/Desktop/weigh-in/lib
└── (empty)
$ npm init -y
Wrote to /Users/dossy/Desktop/weigh-in/package.json:
{
"name": "weigh-in",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
$ for i in jasmine jest karma mocha tap; do npm_config_prefix=$(pwd) npm i $i --no-save --no-package-lock; mv node_modules node_modules.$i; done
npm WARN weigh-in@1.0.0 No description
npm WARN weigh-in@1.0.0 No repository field.
+ jasmine@2.8.0
added 14 packages in 1.057s
> fsevents@1.1.2 install /Users/dossy/Desktop/weigh-in/node_modules/fsevents
> node install
[fsevents] Success: "/Users/dossy/Desktop/weigh-in/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
npm WARN weigh-in@1.0.0 No description
npm WARN weigh-in@1.0.0 No repository field.
+ jest@21.2.1
added 486 packages in 40.777s
> fsevents@1.1.2 install /Users/dossy/Desktop/weigh-in/node_modules/fsevents
> node install
[fsevents] Success: "/Users/dossy/Desktop/weigh-in/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
npm WARN weigh-in@1.0.0 No description
npm WARN weigh-in@1.0.0 No repository field.
+ karma@1.7.1
added 296 packages in 16.364s
npm WARN weigh-in@1.0.0 No description
npm WARN weigh-in@1.0.0 No repository field.
+ mocha@4.0.1
added 24 packages in 1.99s
npm WARN weigh-in@1.0.0 No description
npm WARN weigh-in@1.0.0 No repository field.
+ tap@10.7.2
added 338 packages in 17.905s

Any guesses as to how much each of these packages weigh? See if your guesses line up with their actual weights:

$ paste -d '#' <(du -s node_modules.*) <(du -sh node_modules.*) | sort -nk 1,1 | cut -d'#' -f2
856K node_modules.jasmine
2.2M node_modules.mocha
34M node_modules.tap
35M node_modules.karma
54M node_modules.jest

Jasmine’s the lightest at 856 KB followed by Mocha at 2.2 MB, and Jest is the heaviest at 54 MB, with TAP and Karma a close second at 34 MB and 35 MB.

Obviously, weight is only one dimension to consider. But, I hope more people start making it part of their selection process. I know choosing between packages that provide similar functionality and capability, I will certainly favor the one that’s lighter.

--

--

Dossy Shiobara
This Old Code

Living la vida startup, doing professional services consulting, and trying to support my wife and two daughters. Free time? What's that ...