Skip to content

Instantly share code, notes, and snippets.

@milsosa
Last active July 21, 2021 21:20
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milsosa/ec2807887d62c023e944d18a68e91da4 to your computer and use it in GitHub Desktop.
Save milsosa/ec2807887d62c023e944d18a68e91da4 to your computer and use it in GitHub Desktop.
Run Mocha Tests
'use strict';
// 1. Create the file: {projectRoot}/test.js
// 2. Install dependencies: npm i glob why-is-node-running
// 3. Run the tests: node --expose-internals test.js
const whyIsNodeRunning = require('why-is-node-running');
const glob = require('glob');
const Mocha = require('mocha');
const mocha = new Mocha();
const testFiles = glob.sync('test/**/*.js');
console.log('testing files: ', testFiles);
testFiles.forEach(file => mocha.addFile(file));
mocha.run(() => {
whyIsNodeRunning();
});
@milsosa
Copy link
Author

milsosa commented Oct 12, 2017

Mocha since version 4 does not exits the precess by default anymore - reference -, so this snippet helps out running the tests programmatically and figuring out why the process is still alive (may not be the case) when the tests execution have been finished,
which will be useful to apply the corresponding fixes or in last instance use its --exit flag/option if there is no way to avoid the process remain running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment