Angular 6代码覆盖率...如何在应用程序的代码覆盖率中排除本地库?

时间:2018-08-16 18:48:14

标签: angular typescript code-coverage karma-coverage

我有一个具有以下基本结构的Angular工作区:

/projects
    -- /admin <-- angular application
    -- /core <-- library

这些是通过直接运行ng generate application adminng generate library core生成的。

运行ng test core时,核心库的覆盖率约为90%。

运行ng test admin时,管理应用程序应具有约90%的覆盖率,但是覆盖率报告应包括核心文件(没有其相应的测试)。示例:

------------------------------------------|----------|----------|----------|----------|-------------------|
File                                      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
------------------------------------------|----------|----------|----------|----------|-------------------|
All files                                 |    68.08 |    58.27 |    40.72 |    68.74 |                   |
 admin/src                         |      100 |      100 |      100 |      100 |                   |
  polyfills.ts                            |      100 |      100 |      100 |      100 |                   |
  test.ts                                 |      100 |      100 |      100 |      100 |                   |
 admin/src/app                     |    94.55 |    70.69 |    83.33 |    97.78 |                   |
  app.component.ts                        |       95 |    62.07 |      100 |      100 |         3,4,5,6,9 |
  app.testing.module.ts                   |    94.29 |    79.31 |       75 |    96.67 |                17 |
 admin/src/app/configuration       |    59.57 |    54.55 |    30.77 |    62.62 |                   |
  configuration.actions.ts                |    69.66 |      100 |    51.61 |    69.66 |... 24,125,132,133 |
  configuration.effects.ts                |    47.54 |     69.7 |    11.54 |    55.56 |... 45,47,52,53,55 |
  configuration.reducer.ts                |    36.36 |    20.83 |     8.33 |    39.02 |... 71,74,76,87,90 |
  configuration.service.ts                |    83.33 |    62.07 |    44.44 |    83.87 |    26,29,32,35,38 |
 admin/src/app/edit/components     |    70.89 |    59.09 |    43.75 |    71.23 |                   |
  editor.component.ts                     |    70.89 |    59.09 |    43.75 |    71.23 |... 79,80,82,83,86 |
 admin/src/app/edit/containers     |    71.05 |    62.07 |       40 |     69.7 |                   |
  edit-container.component.ts             |    71.05 |    62.07 |       40 |     69.7 |... 32,37,38,41,44 |
 admin/src/app/landing             |    91.67 |    62.07 |    66.67 |    94.74 |                   |
  landing.component.ts                    |    91.67 |    62.07 |    66.67 |    94.74 |                21 |
 admin/src/app/models              |       90 |      100 |    66.67 |       90 |                   |
  application.ts                          |      100 |      100 |      100 |      100 |                   |
  config-item.ts                          |    84.62 |      100 |       50 |    84.62 |             12,15 |
 admin/src/app/view/components     |    77.27 |    71.88 |    57.14 |    76.79 |                   |
  view-app.component.ts                   |    95.24 |    79.31 |       80 |      100 |         3,4,5,6,9 |
  view-list.component.ts                  |    68.89 |    65.71 |    44.44 |     67.5 |... 36,40,41,42,45 |
 admin/src/app/view/containers     |    80.65 |    62.07 |    66.67 |    80.77 |                   |
  view-container.component.ts             |    80.65 |    62.07 |    66.67 |    80.77 |    23,24,25,26,29 |
 core/src                                 |      100 |       50 |      100 |      100 |                   |
  index.ts                                |      100 |       50 |      100 |      100 |                 3 |
  public_api.ts                           |      100 |       50 |      100 |      100 |                 6 |
 core/src/lib                             |    93.85 |    66.67 |    69.23 |    96.43 |                   |
  core.module.ts                          |    94.12 |       50 |       50 |    96.67 |                31 |
  core.testing.module.ts                  |    93.55 |    79.31 |    77.78 |    96.15 |                56 |
 core/src/lib/app-config                  |    66.67 |    54.55 |       40 |    66.67 |                   |
  app-config.service.ts                   |    66.67 |    54.55 |       40 |    66.67 |... 29,30,31,32,33 |
 core/src/lib/auth                        |       48 |    42.34 |       27 |    47.91 |                   |
  auth.actions.ts                         |    71.88 |      100 |    52.17 |    71.88 |... 74,81,88,95,96 |
  auth.effects.ts                         |    46.38 |    65.71 |    18.75 |    45.16 |... 71,72,75,76,80 |
  auth.guard.ts                           |    66.67 |    54.55 |     37.5 |    66.67 |... 28,29,30,32,35 |
  auth.reducer.ts                         |    33.33 |       20 |        0 |    40.91 |... 24,27,30,33,42 |
  auth.service.ts                         |       42 |    39.13 |       25 |    40.48 |... 51,53,55,58,60 |
  queryParamUtils.ts                      |       12 |        0 |        0 |    12.24 |... 89,90,91,92,93 |
  role.guard.ts                           |    57.14 |    46.15 |       30 |    57.14 |... 44,45,46,47,49 |
  secure.directive.ts                     |    48.39 |       46 |       20 |    47.27 |... 70,73,77,80,83 |
 core/src/lib/components/account-dropdown |    83.33 |    79.31 |     37.5 |       84 |                   |
  account-dropdown.component.ts           |    83.33 |    79.31 |     37.5 |       84 |       18,22,25,28 |
 core/src/lib/components/navbar           |    95.65 |    79.31 |       60 |      100 |                   |
  navbar.component.ts                     |    95.65 |    79.31 |       60 |      100 |         3,4,5,6,9 |
 core/src/lib/containers/page-not-found   |    94.74 |    62.07 |       60 |      100 |                   |
  page-not-found.component.ts             |    94.74 |    62.07 |       60 |      100 |         3,4,5,6,9 |
 core/src/lib/containers/parent           |       80 |    79.31 |       60 |       80 |                   |
  parent.component.ts                     |       80 |    79.31 |       60 |       80 |    19,20,21,22,23 |
 core/src/lib/containers/unauthorized     |    94.74 |    62.07 |       60 |      100 |                   |
  unauthorized.component.ts               |    94.74 |    62.07 |       60 |      100 |         3,4,5,6,9 |
 core/src/lib/models                      |      100 |      100 |       50 |      100 |                   |
  user.ts                            |      100 |      100 |       50 |      100 |                   |
  navbar-link.ts                          |      100 |      100 |       50 |      100 |                   |
  secure.ts                               |      100 |      100 |       50 |      100 |                   |
------------------------------------------|----------|----------|----------|----------|-------------------|

=============================== Coverage summary ===============================
Statements   : 68.08% ( 836/1228 )
Branches     : 58.27% ( 479/822 )
Functions    : 40.72% ( 125/307 )
Lines        : 68.74% ( 741/1078 )
================================================================================

admin / src / app行显示admin项目的覆盖率为94.55%(...),但这些数字未反映在摘要中。

我知道为什么它要尝试包含文件(它们正在导入)...但是如何排除它们?我尝试修改admin /内的tsconfig.spec.json文件以排除文件,但这没有用。当我修改tsconfig.json根文件以删除库的“路径”(别名为@martzcodes/core并以这种方式导入)时,我得到了适当的导入警告。我不必嘲笑我所有的库...

打字稿版本2.9.2,@ angular / cli 6.1.3

1 个答案:

答案 0 :(得分:2)

angular.json codeCoverageExclude中使用test.options,如下所示:

"codeCoverageExclude": [
  "admin/**",
]

https://github.com/angular/angular-cli/issues/3356

angular cli exclude files/directory for `ng test --code-coverage`