2014-11-14 130 views
1

我正在我們現有的Webapp文件夾結構上運行單元測試實驗。當我在AMD和非AMD js文件上運行測試時,單元測試運行,但我沒有得到每個測試的代碼覆蓋率。我假設這是因爲目錄結構(見下文);將'node_modules'和'intern_tests'向下移動一層('internjs')。如果我將'node_modules'和'intern_tests'文件夾移動到Webapp文件夾下,它就可以運行(運行+覆蓋)。我正在運行版本2.1.1。代碼覆蓋率是否適用於這種類型的目錄結構?未獲取代碼覆蓋率信息

文件夾結構:

WebApp (top) 
    |- example_apps (example AMD and non-AMD apps) 

    |- internjs (run tests from here) 
     |- node_modules 

     |- intern_tests 
       |- unit (test js apps under example_apps) 

非AMD單元測試:

define([ 
    'intern!object', 
    'intern/chai!assert', 
    // made a package under intern.js 
    'intern/order!exampleApps/calc.js' 
], function (registerSuite, assert) { 
    registerSuite({ .... 

AMD單元測試:

define([ 
    'intern!object', 
    'intern/chai!assert', 
    'intern/chai!config', 
    'exampleApps/hello' 
], function (registerSuite, assert, config, hello) { 
    registerSuite({ ... 

intern_unit.js:

loader: { 
    // Packages that should be registered with the loader in each testing environment 
    packages: [ { name: 'exampleApps', location: '../example_apps' } ] 
}, 

// Non-functional test suite(s) to run in each browser 
suites: [ 
    'intern_tests/unit/unit_hello', 
    'intern_tests/unit/unit_calc2' 

], 

輸出:

./node_modules/.bin/intern-client config=intern_tests/intern_unit 
PASS: main - hello - greet (1ms) 
0/1 tests failed 
PASS: main - test_calc - sum (0ms) 
0/1 tests failed 
0/2 tests failed 

注意,它運行但在「example_apps」目錄下一個級別上的兩個js文件沒有代碼覆蓋。

回答

1

我想通了。我必須從WebApp運行腳本(頂部)。以下是新的配置。

命令行:

user:~/WebApp$ ./intenjs/node_modules/.bin/intern-client config=internjs/intern_tests/intern_unit 

intern_unit.js

loader: { 
    // Packages that should be registered with the loader in each testing environment 
    packages: [ { name: 'exampleApps', location: 'example_apps' }, 
       { name: 'internTests', location: 'internjs/intern_tests' } ] 
}, 

// Non-functional test suite(s) to run in each browser 
suites: [ 
    // AMD 
    'internTests/unit/unit_hello', 
    // non-AMD 
    'internjs/intern_tests/unit/unit_calc2' 

], 

// A regular expression matching URLs to files that should not be included in code coverage analysis 
excludeInstrumentation: /^(?:internjs)\// 

非AMD的測試腳本:

define([ 
    'intern!object', 
    'intern/chai!assert', 
    // non-AMD, saw this in tutorial 
    'intern/order!../../../example_apps/calc.js' 
    // this also works 
// '../../../example_apps/calc.js' 
], function (registerSuite, assert) { 

AMD測試腳本:

define([ 
    'intern!object', 
    'intern/chai!assert', 
    'intern/chai!config', 
    'exampleApps/hello' 
], function (registerSuite, assert, config, hello) {