2013-09-22 29 views
6

是否有可能只用一些測試運行nodeunit測試文件中的一個測試。我tests.js文件:通過名稱從一個節點單元文件運行一個測試

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

我可以運行所有測試:

$ nodeunit tests.js 

但我想只運行test2的,如:

$ nodeunit tests.js test2 

是否有可能不劈裂文件tests.js成2個獨立的文件?

回答

6

nodeunit -h可用的選項(這是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 

所以從以下應該做你想要什麼:

$ nodeunit tests.js -t test2 

如:

$ nodeunit ./tests.js -t test2 

tests.js 
test2 
✔ test2 
相關問題