未获取代码覆盖率信息

Not getting code coverage information

本文关键字:信息 代码覆盖率 获取      更新时间:2023-09-26

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

我想通了。 我必须从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) {