angular-builders icon indicating copy to clipboard operation
angular-builders copied to clipboard

No tests found on 'ng test' with dot in the path to the root directory

Open MaKCbIMKo opened this issue 5 years ago • 19 comments

Describe the bug When I do ng test - it doesn't find any single test.

Firstly, I tried that on existing project (which is using jest but via jest cli and I know tests exist) -> 0 tests discovered. Then, I tried new project (via ng new) -> 0 tests discovered. At last, I downloaded simple-app example -> 0 tests discovered.

And I have no idea what I am doing wrong or haven't configured properly.

Any ideas what's the reason?

Ask for more information -> will provide information that might help.

To Reproduce (for instance, new project)

  1. ng new jest-app
  2. npm i -D jest @types/jest @angular-builders/jest
  3. adjust angular.json to use new builder
  4. npm run test -> ng test

Expected behavior All tests are discovered

Builder:

  • @angular-builders/jest
  • 8.2.0

Libraries

  • angular-devkit/build-angular: from 0.802.2 to 0.803.19

Additional context

  • node.js: 12.13.0

MaKCbIMKo avatar Nov 14 '19 16:11 MaKCbIMKo

I've never had this problem. Could you provide a reproduction?

arturovt avatar Nov 15 '19 17:11 arturovt

What do you want me to provide?

Is 'steps to reproduce' not enough?

MaKCbIMKo avatar Nov 18 '19 09:11 MaKCbIMKo

No, not enough. I ran through them and don't see such errors.

arturovt avatar Nov 18 '19 09:11 arturovt

Issues without reproductions should be closed as well as on the StackOverflow:

When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimal, reproducible example (reprex), a minimal, complete and verifiable example (mcve), or a minimal, workable example (mwe).

What's the problem to make a working example thus everyone who has a look at this issue is able to reproduce it, debug and prolly provide a fix?

arturovt avatar Nov 18 '19 09:11 arturovt

I just re-checked with simple-app example:

  • download example
  • install packages
  • run tests

image

I did change nothing, and if I will create another repro-repo - it will be the same as example.

No, not enough. I ran through them and don't see such errors.

That's why I guess it might be related to environment (different nodejs versions etc)...

MaKCbIMKo avatar Nov 18 '19 10:11 MaKCbIMKo

I've investigated the issue I have.

And I found the problem: root path to project contains dot character, e.g. D:\my\path\.with\dot\.

Further investigation showed some interesting things: In all cases I have rootDir path WITH dot (in jest config)

  1. if I use full path (with dot) in testMatch config section -> no tests found
  2. if I use <rootDir> variable in testMatch config section -> no tests found
  3. if I use default testMatch without specifying full path (e.g. just "**/+(*.)+(spec|test).+(ts|js)?(x)") -> all tests found

As I workaround for that I have specified testMatch without full path:

{
    ........
    testMatch: ["**/+(*.)+(spec|test).+(ts|js)?(x)"],
    ........
}

It overrides generated testMatch path provided by jest builder and as a results it finds all tests.

It's weird because the rootDir still contains folder starts with dot, but it works.

Seems like it's not a problem with jest builder but the problem with jest itself. I will close this issue.

Hovewer, @just-jeb - Do you think I need to open another issue/suggestion to handle such case by jest builder (e.g. do not use full paths in testMatch generation)?

I've created issue in jest repo but I have no idea how fast they will proceed that...

At least for now I have a workaround without changing project path or renaming folders

MaKCbIMKo avatar Dec 03 '19 11:12 MaKCbIMKo

Hi @MaKCbIMKo thanks for the effort. I'll reopen it until we confirm it's not an issue with the builder (it might be the builder, because it effectively generates the matches per project so probably it doesn't work well with dots).
Might be also issue with Angular core, since we use their utilities to resolve the paths.

just-jeb avatar Dec 03 '19 12:12 just-jeb

Hi @just-jeb - Ok, so I will wait for updates from you - I'm curios what you will find.

MaKCbIMKo avatar Dec 03 '19 14:12 MaKCbIMKo

Tests ran fine locally but I encountered this exact issue in Azure Devops CI. I can also confirm the workaround.

mcaden avatar Jan 16 '20 23:01 mcaden

@mcaden Can you confirm that the path also has dots in it?

just-jeb avatar Jan 18 '20 08:01 just-jeb

Yes, my repo name and one of the parent project folders both have one/more dots in them. Repo name is {Dept}.{Project} and the sub-project inside the repo is {Dept}.{Project}.Web. Strange it doesn't affect local runs and is only happening on CI as I'm pretty sure all the versions match judging from yarn.lock, using same node version, using same yarn version, etc. The build box path is (because Azure Devops) d:\build\9\s\Code\{Dept}.{Project}.Web\ClientApp

mcaden avatar Jan 20 '20 15:01 mcaden

Maybe OS? What's your local system and what system are you using in CI?

just-jeb avatar Jan 20 '20 15:01 just-jeb

Local is Windows 10. Build box is Windows Server 2016.

mcaden avatar Jan 20 '20 15:01 mcaden

I'm having this issue with the latest Jest version installed (25.1.0), it was fine when I was using Jest 24.9.0. These are 1 release away from each other Releases

angular-builders/jest version is 8.3.2.

Running:

ng test base-lib

Results in:

  testMatch: /Users/user/Documents/angular-app/projects/base-lib/**/+(*.)+(spec|test).+(ts|js)?(x) - 0 matches
  testPathIgnorePatterns: /node_modules/ - 2796 matches
  testRegex:  - 0 matches

jonathanlie avatar Jan 30 '20 03:01 jonathanlie

@jonathanlie No dots in path? Does specifying absolute path help?

just-jeb avatar Jan 30 '20 07:01 just-jeb

I had the same issue as above, after updating 24.9.0 to 25.1.0

Seems that testMatch should be adjusted as follow: **/*(*.)@(spec|test).[tj]s?(x)

p.s. The related jest discussion can be found here: testMatch on Windows

it-ias avatar Jan 30 '20 11:01 it-ias

@it-ias thanks for the update. I'm gonna take this out into a separate issue as it seems to be unrelated to the one that started this thread.

just-jeb avatar Jan 30 '20 21:01 just-jeb

All, please track #673 for Jest 25 related issue.

just-jeb avatar Jan 30 '20 21:01 just-jeb

I had the same issue, but it turns out that when a test fails, the test runner claims there were no tests found. In other words, the wrong error is given.

paddotk avatar Jun 03 '22 12:06 paddotk