Run one test by name from one nodeunit file

Is it possible to run only one test from a nodeunit test file with multiple tests. My tests.js file:

 module.exports = { test2: function (test) { console.log ("test2") test.done(); }, test1: function (test) { console.log ("test1") test.done(); } }; 

I can run all tests:

 $ nodeunit tests.js 

But I want to run only test2, for example:

 $ nodeunit tests.js test2 

Is it possible without splitting the tests.js file into 2 separate files?

+6
source share
1 answer

See nodeunit -h for available options (this is for version 0.8.1):

 Usage: nodeunit [options] testmodule1.js testfolder [...] Options: --config FILE the path to a JSON file with options --reporter FILE optional path to a reporter file to customize the output --list-reporters list available build-in reporters -t name, specify a test to run -f fullname, specify a specific test to run. fullname is built so: "outerGroup - .. - innerGroup - testName" -h, --help display this help and exit -v, --version output version information and exit 

So from this you should do what you want:

 $ nodeunit tests.js -t test2 

eg:

 $ nodeunit ./tests.js -t test2 tests.js test2 ✔ test2 
+6
source

Source: https://habr.com/ru/post/954359/


All Articles