include option for ng test is not working

Viewed 7087

I am trying to run unit tests using Karma and Jasmine using the ng test. when I issue the following command:

ng test --watch=false --code-coverage --main ./src/main/resources/public/scripts/xyz/workspace/commons/interceptors/mgr.ng.spec.ts

It works without any issues.

When I try the following command to run all scripts in that directory:

ng test --watch=false --code-coverage --include=src/main/resources/public/scripts/xyz/workspace/commons/interceptors/*.ng.spec.ts

I get the following error:

Specified patterns: "src/main/resources/public/scripts/xyz/workspace/commons/interceptors/*.ng.spec.ts" did not match any spec files

Any idea what is happening here? I tried many variations and it does not look like the include option is working at all.

6 Answers

The following is the command to run the test files under a particular folder and all its subfolder/subdirectory

ng test --include='src/app/modulefolder/**/*.spec.ts'

Try ng test --watch=false --code-coverage --include="src/main/resources/public/scripts/xyz/workspace/commons/interceptors/*.ng.spec.ts"

It would also be beneficial if you would post your project structure.

Oh don't you need to add quotation marks around your path? Also if you want, you can use this other way of using --include

ng test --include relative_or_absolute_path_here

or

ng test --include="relative_or_absolute_path_here"

https://angular.io/cli/test

ng test --include=src/app/my-folder

works for me. No quotes. No *.

Per the angular docs,

Globs of files to include, relative to workspace or project root. There are 2 special cases:

  • when a path to directory is provided, all spec files ending ".spec.@(ts|tsx)" will be included

  • when a path to a file is provided, and a matching spec file exists it will be included instead

Note, I tested in Powershell. Might need escape sequence and different slahes on different OS's/terminals.

to test all spec files in current director, and subfolders:

ng test --include **/*.spec.ts
Related