没有获得代码覆盖率信息

时间:2014-11-14 23:36:14

标签: javascript code-coverage intern

我在现有的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 个答案:

答案 0 :(得分: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) {