2014-11-14 105 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) {