Since you asked for simplest…
In a.js:
module.exports = (arg) => {
return arg * 3;
};
In a.test.js:
// require module to test
const testedFunction = require('./a.js');
// testing
console.log("Default export", "should multiply argument by two:", true &&
testedFunction(3) === 3 * 2
);
In package.json:
"scripts": {
"test": "for file in *test*; do node ${file}; done"
}
In your shell:
$ npm run test
A few things to note:
* Node.js has console.assert() but it is really noisy.
* console.group() could be used to… group assertions and indent output.
* This works for ES6 modules, too, with --experimental-modules and .mjs extensions.
If you want something serious but still lightweight, there's always https://github.com/MithrilJS/mithril.js/tree/next/ospec.