How to get mocha to execute unit tests in multiple subfolders in node.js?

Member

by darion , in category: Javascript , 18 days ago

How to get mocha to execute unit tests in multiple subfolders in node.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elisha_langworth , 17 days ago

@darion 

To get Mocha to execute unit tests in multiple subfolders in Node.js, you can use the --recursive flag when running the Mocha command. This flag tells Mocha to search for test files in subdirectories as well.


Here's an example of how you can run Mocha with the --recursive flag to execute unit tests in multiple subfolders:

1
mocha --recursive test/


In this example, the test/ directory contains subfolders with unit tests in them. By using the --recursive flag, Mocha will search for test files in all subdirectories of the test/ directory and execute them.


You can also specify multiple directories to search for test files by separating them with commas:

1
mocha --recursive test/subfolder1,test/subfolder2


This command will tell Mocha to search for test files in both the test/subfolder1 and test/subfolder2 directories.


By using the --recursive flag and providing the appropriate directory paths, you can easily execute unit tests in multiple subfolders with Mocha in Node.js.