Angular library secondary entrypoint test code coverage problem
Asked Answered
O

1

6

I am using angular library with secondary entrypoint My library folder structure is

  • my-library
    • secondary-entrpoint 1
      • service 1
    • secondary-entrypoint 2
      • service 2
    • src

And I used this command ng test my-library --code-coverage

The secondary entry points' service test doesn't execute.

Then I tried, changing "test.ts" context path('./') with '../' which is under the src folder. Tests were executed but code coverage doesn't create.

How can I execute tests for a secondary entry point?

Ottava answered 15/9, 2020 at 14:29 Comment(0)
X
10

That is because the source root of your project is pointing to projects/your-library/src and when running tests it does not take into account the other entry points.

To fix this just change the sourceRoot property in your "angular.json" file to projects/your-library, everything else should still work fine.

X answered 21/9, 2020 at 14:58 Comment(6)
I have multiple secondary entrpoints. So I can't set sourceroot property on angular.jsonNavarre
All your secondary entry points have the same root, so following your example in your angular.json you should set "sourceRoot": "projects/my-library" instead of "sourceRoot": "projects/my-library/src" that is what Angular sets as defaultX
I got Mert's answer to work by also moving the test.ts file to the "project/my-library" level AND changing my tsconfig.spec.ts files from "src/test.ts" to "test.ts"Julesjuley
It worked great for me. tnx man :)Supplejack
After moving test.ts 1 level up, no need to change sourceRoot in angular.json, changing test/options/main path is enough.Armistead
Actually, despite tests run, they don't reflect in the code coverage report. With or without changes to sourceRoot, only primary endpoint shows up in coverage. Any way to fix it?Armistead

© 2022 - 2024 — McMap. All rights reserved.