【问题标题】:Not getting code coverage information未获取代码覆盖率信息
【发布时间】:2015-01-12 11:18:39
【问题描述】:

我正在对我们现有的 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 文件。

【问题讨论】:

    标签: javascript code-coverage intern


    【解决方案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) {
    

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 2017-02-20
      • 2020-02-13
      • 2019-02-25
      • 2015-08-10
      • 2015-01-07
      • 2011-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多