3

I have an Angular workspace with the following basic structure:

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

These were generated by running ng generate application admin and ng generate library core... fairly straight forward.

When running ng test core the core library has coverage of around 90%.

When running ng test admin the admin application SHOULD have coverage around 90%, but the coverage report includes the core files (without their corresponding tests). Example:

------------------------------------------|----------|----------|----------|----------|-------------------|
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 )
================================================================================

The admin/src/app line shows the coverage for the admin project is 94.55% (...) but these numbers aren't reflected in the summary.

I understand why it's attempting to include the files (they ARE being imported)... but how do I exclude them? I have tried modifying the tsconfig.spec.json file inside of admin/ to exclude the files, but that did not work. When I modified the root tsconfig.json file to remove the "path" to the library (it's aliased to @martzcodes/core and imported that way) I got the appropriate import warnings. I shouldn't have to mock all of my libs...

Typescript version 2.9.2, @angular/cli 6.1.3

martzcodes
  • 404
  • 5
  • 16

1 Answers1

3

Use codeCoverageExclude in angular.json test.options like so:

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

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

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

RocketKittens
  • 409
  • 5
  • 7