Jest: No tests found when running Jest under Windows Server 2012 environment

Created on 5 Feb 2017  Â·  17Comments  Â·  Source: facebook/jest

No tests found: when running Jest under Windows Server 2012 environment.
The issue is only reproducible when the project path contains space.

My jest configuration is:
node: v6.9.1
npm: 3.10.8
Jest: 18.1.0

Windows

Most helpful comment

A workaround for anyone having this problem with jenkins is to set a custom workspace directory for your project under the project's advanced settings. Just set it to a path without spaces (e.g. c:\workspace\my-project).

All 17 comments

Someone here had this exact issue today!

@mikaelbr fixed something similar recently. Could you help here?

Sure. I can take a stab at it, but I don't think it's related to the previous issue at all.

Having the same issue in Windows Server 2012. Will get back if we can reproduce.

After wasting a bunch of time escaping paths. I was able to get tests to run by temporarily copying the project directory to the C:\Users\[USER]\Desktop, running the tests, then removing the directory. The world is happy.

PS - I want to do a PR, but I'm stacked with work. Also, I'm not a Windows dev, and our office is using an EC2 Windows Server for an unrelated build, so we're not tied to it.

Here's some Jenkins output (commands included) if you need some slight inspiration.

C:\Program Files (x86)\Jenkins\jobs\universal-drug-codes-server-test\workspace>echo "copying src to temporary directory..." 
"copying src to temporary directory..."

C:\Program Files (x86)\Jenkins\jobs\universal-drug-codes-server-test\workspace>mkdir "C:\Users\Administrator\Desktop\universal-codes-jest-tmp" 

C:\Program Files (x86)\Jenkins\jobs\universal-drug-codes-server-test\workspace>xcopy /S /Y "C:\Program Files (x86)\Jenkins\jobs\universal-drug-codes-server-test\workspace" "C:\Users\Administrator\Desktop\universal-codes-jest-tmp"

...

C:\Program Files (x86)\Jenkins\jobs\universal-drug-codes-server-test\workspace>echo "running tests..." 
"running tests..."

C:\Program Files (x86)\Jenkins\jobs\universal-drug-codes-server-test\workspace>chdir "C:\Users\Administrator\Desktop\universal-codes-jest-tmp"   && npm test -- --verbose 

> [email protected] test C:\Users\Administrator\Desktop\universal-codes-jest-tmp
> jest "--verbose"

 PASS  __tests__\handler.spec.js
  √ "handler.items" is defined
  "FilterValidFields" call
    √ called once
    √ called with correct argument
    √ called with correct argument 2 (15ms)
  "handler.items": empty query parameters
    √ should call error response once
    √ "MockLambdaJSONResponse" should be called with error object correct
    √ "MockLambdaJSONResponse" should be called with stringified JSON
    √ should return false
    √ mysql connection not called
  "handler.items": bad query parameters
    √ if bad query parameters, should call error response once
    √ if bad query parameters, error object correct
    √ should return false
    √ mysql connection not called
  "handler.items": bad field filter values
    √ if bad query parameters, should call error response once
    √ if bad query parameters, error object correct
    √ should return false
    √ mysql connection not called
  "handler.items": mysql connection
    √ should call "MySqlCreateConnection" once
    √ "MySqlCreateConnection" should be called with correct argument
    √ "MySqlCreateConnection" should be called with correct argument 2
    √ should call "PrepareSelectStatement" once
    √ "PrepareSelectStatement" should be called with correct argument
    √ "PrepareSelectStatement" should be called with correct argument 2
  "handler.items": mysql format
    √ should be called once
    √ should be called with a string as argument
    √ should be called with an object as argument 2

 PASS  __tests__\helper.spec.js
  √ "FilterValidFields" is defined

Test Suites: 2 passed, 2 total
Tests:       27 passed, 27 total
Snapshots:   0 total
Time:        1.124s, estimated 2s
Ran all test suites.
[workspace] $ cmd /c call C:\Users\ADMINI~1\AppData\Local\Temp\hudson8667930859440503455.bat

C:\Program Files (x86)\Jenkins\jobs\universal-drug-codes-server-test\workspace>echo "removing temporary directory..." 
"removing temporary directory..."

C:\Program Files (x86)\Jenkins\jobs\universal-drug-codes-server-test\workspace>rmdir "C:\Users\Administrator\Desktop\universal-codes-jest-tmp" /s /q 
C:\Program Files (x86)\Jenkins\jobs\universal-drug-codes-server-test\workspace>exit 0 
Finished: SUCCESS

I can confirm that the issue is still present with Jest v20.0.1.

17:02:41     > [email protected] test C:\Program Files (x86)\Jenkins\workspace\Project (BUILD)\ui
17:02:41     > jest
17:02:41     
17:02:42     No tests found
17:02:42     In C:\Program Files (x86)\Jenkins\workspace\Project (BUILD)\ui
17:02:42       113 files checked.
17:02:42       testMatch: /__tests__/**/.js?(x),**/?(.)(spec|test).js?(x) - 6 matches
17:02:42       testPathIgnorePatterns: \\node_modules\\ - 113 matches
17:02:42     Pattern: "" - 0 matches
17:02:42     ----------|----------|----------|----------|----------|----------------|
17:02:42     File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
17:02:42     ----------|----------|----------|----------|----------|----------------|
17:02:42     All files |  Unknown |  Unknown |  Unknown |  Unknown |                |
17:02:42     ----------|----------|----------|----------|----------|----------------|

@josalmi does it work with testRegex? It may be an issue with testMatch on Windows

Same problem here. I can run test with "Jest" or "Jest test", but no test match if run with "Jest test/components" Is there any workaround for this? We need to have different setupFiles/testEnvionment for different subfolder. Not sure how to achieve this with this bug.

As @lippea mentioned, we encountered this problem. It doesn't seem to be limited to Windows Server 2012; more Windows machines in general. Mac machines are okay. We worked around this for the time-being by using a separate json file, which uses an array of globs (instead of regex, at least as I understand it).

I was having the same problem on Windows 7 enterprise. I can confirm that the problem was related to having either a space or bracket in the path. Once I removed those the tests would run.

@mikehdt can you provide your example? I'd prefer your solution over my current one.

@mikehdt How do you use that json file? Please share your work-around :)

I'm still dealing with the same issue as @josalmi .

If you are all running into this issue, please send a PR to fix it for everyone. We don't have Windows 7 machines, so unless you guys send a PR, this won't get fixed :) Thank you.

Confirming problem, not clever enough to solve it. @mikehdt More on that json workaround would be appreciated.

A workaround for anyone having this problem with jenkins is to set a custom workspace directory for your project under the project's advanced settings. Just set it to a path without spaces (e.g. c:\workspace\my-project).

I think this is the same problem as https://github.com/facebook/jest/issues/2381. Closing in favor of the other issue. Still looking for help on this one!

Was this page helpful?
0 / 5 - 0 ratings