Last active
July 21, 2021 21:20
-
-
Save milsosa/ec2807887d62c023e944d18a68e91da4 to your computer and use it in GitHub Desktop.
Run Mocha Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.