jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.84k stars 295 forks source link

No tests are detected #1086

Closed flixman closed 9 months ago

flixman commented 1 year ago

In the root of my app there are two folders, backend and frontend. All the react code is in frontend/src, and I cannot get any tests detected, however I can run them from the CLI without any issue.

update: Actually is worse. With this configuration in my .vscode/settings.json, I get the error "unknown Configuration setting".

{
    "jest.virtualFolders": [
        {
            "name": "unit-tests",
            "rootPath": "frontend",
            "jestCommandLine": "npm run test -- --silent=false",
            "runMode": "on-demand"
        }
    ]
}

Environment

  1. vscode-jest version: 5.2.3
  2. node -v: 20.9.0
  3. npm -v: 10.2.1
  4. npm ls jest: 29.7.0
  5. your vscode-jest settings if customized:
    • jest.autoRun: "off"
    • jest.rootPath: frontend
  6. Operating system: arch linux

Prerequisite

Steps to Reproduce

Just start VSCode and get to Test, no tests get detected.

connectdotz commented 1 year ago

HI, sorry for the late reply. jest.virtualFolders is only available in v6 pre-release. It seems that you are using the 5.2.3, please try the pre-release instead.

stefanrybacki commented 1 year ago

Sorry for hijacking this, however I am facing a similar problem. I want to start all test within a folder subfolder from vscode, however for some reason the pattern below is not correct, it misses the tsroot part, which is set in settings.json via jest.rootPath

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /home/XXX/project/tsroot
  3509 files checked.
  testMatch: /home/XXX/project/tsroot/**/*(*.)@(spec|test).[tj]s?(x) - 507 matches
  testPathIgnorePatterns: /home/XXX/project/tsroot/build/, /home/XXX/project/tsroot/node_modules/ - 1690 matches
  testRegex:  - 0 matches
Pattern: /home/XXX/project/subfolder - 0 matches

Interestingly tsroot is also not shown in the Test Explorer view where the tree is project/subfolder, tsroot is missing there as well.

Any ideas?

connectdotz commented 1 year ago

@stefanrybacki, I need clarification on what your project structure is. Is it /home/XXX/project/subfolder/tsroot or /home/XXX/project/tsroot? What is the actual vscode workspace folder? Are you able to run jest even on the terminal (to verify it is not a jest config issue)? Where do you usually run your tests? subfolder? tsroot? Are you also using virtualFolders?

Okay, the best way is to create a sample repo so we can skip these questions. And you might want to create your own issue so we won't mix these 2 together.

stefanrybacki commented 1 year ago

@connectdotz thanks for your answer, The project is very large and I am not sure how much of the configs we use I can disclose as well as reduce in order to provide a testing repo. However, I can create a new ticket for sure. Just for the record regarding your questions: the structure is /home/XXX/project/tsroot, with tsroot being the ts root folder within the project folder one lever higher. The workspace folder would be /home/XXX/project. Jest runs on the terminal, tests I start from within a spec.ts file via the green play button also work (for the most part, paramterized tests not working correctly if selected individually). And last but not least I run test from tsroot if I want all, or individually from within a spec.ts file. However, just in this case I wanted to run all tests within subfolder from the vscode test explorer but that did not work (because of I assume the wrong folder to match).

mirceaburac-sugarcrm commented 1 year ago

I am having the same or a similar problem: I can't run tests by the folder from the "Testing" tab on left navbar, it says the regex has no matches.

This is happening after I changed to the pre-release version, because I had a bug where the Test Results Output was not being shown.

My folder structure hasn't changed, but the behavior of the extension seems to be different somehow.

![Uploading image.png…]()

connectdotz commented 1 year ago

@mirceaburac-sugarcrm, this is interesting... can you upload a screen recording that shows me the issue (the png link you posted above didn't take me to the actual image)? If this is a bug in the pre-release we should definitely fix it.

connectdotz commented 12 months ago

@mirceaburac-sugarcrm, do you still experience this issue? Can you show us the error screenshot with the spawned command line?

mirceaburac-sugarcrm commented 12 months ago

@connectdotz Sorry, the first time the picture upload bugged. You can see here:

image

This only occurs on the pre release version. The release version is fine. The problem I have with the release version is that the output in Test Results just disappears after the tests are done.

connectdotz commented 12 months ago

@mirceaburac-sugarcrm, from the output, it looks like your jest config found tests under

"/home/xxx/Projects/xxx/projects/xxx/frontend/app/src/"

but you are trying to run tests in

"/home/xxx/Projects/xxx/src/components/ManageUsersList"

Which doesn't seem to be under your jest config's testMatch pattern? Are you using virtualFolders? is it using the wrong jest config? do you have a sample repo we can dig further?

mirceaburac-sugarcrm commented 11 months ago

@connectdotz I don't have a sample repo unfortunately.

The only thing I can point to is that this wrong folder configuration is only happening when I switch to the pre release version, but works fine for the normal release.... As soon as I change from prerelease to normal release I don't have the problem anymore. No configs changed in between.

DetachHead commented 10 months ago

i was able to reproduce with a fairly simple example

steps

  1. clone my repo and checkout this commit: https://github.com/DetachHead/ts-helpers/commit/f482e83aad9cfa694cdc631e9c015963e03f48da
  2. run npm ci
  3. navigate to tests/asdf.spec.ts and press the run icon next to the test output:

    > @detachhead/ts-helpers@16.1.0 test
    > jest "--testLocationInResults" "--json" "--useStderr" "--outputFile" "C:\\Users\\user\\AppData\\Local\\Temp\\jest_runner_ts_helpers_user_2.json" "--no-coverage" "--reporters" "default" "--reporters" "c:\\Users\\user\\.vscode\\extensions\\orta.vscode-jest-5.2.3\\out\\reporter.js" "--colors" "--watchAll=false" "--testPathPattern" "c:\\\\Users\\\\user\\\\IdeaProjects\\\\ts-helpers\\\\test\\\\asdf\\.spec\\.ts"
    
    No tests found, exiting with code 1
    Run with `--passWithNoTests` to exit with code 0
    In C:\Users\user\IdeaProjects\ts-helpers
      7 files checked.
      testMatch:  - 0 matches
      testPathIgnorePatterns: \\node_modules\\ - 7 matches
      testRegex: \\test\\.*.ts - 1 match
    Pattern: c:\\\\Users\\\\user\\\\IdeaProjects\\\\ts-helpers\\\\test\\\\asdf\\.spec\\.ts - 0 matches
  4. open a terminal and run jest output:

    > jest
    ts-jest[ts-jest-transformer] (WARN) Define `ts-jest` config under `globals` is deprecated. Please do
    transform: {
        <transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],
    },
     PASS  test/asdf.spec.ts
      √ asdf (1 ms)
    
    Test Suites: 1 passed, 1 total
    Tests:       1 passed, 1 total
    Snapshots:   0 total
    Time:        1.312 s
    Ran all test suites.

environment info

(for everything else see package-lock.json)

connectdotz commented 10 months ago

@DetachHead, I tried your repo following your steps, and the test ran fine. Comparing the output, I did notice your "testPathPattern" is not right: it seems to be double-escaped \\\\ while the right pattern should be \\... Do you happen to be running with npm < 8.15? see comment for a known bug that could cause this issue.

connectdotz commented 10 months ago

@mirceaburac-sugarcrm, we are getting ready to promote the pre-release to production. However, your issue still concerns me. I would like to try one last time to see if we can figure it out...

From the error info, I am not sure how it could have worked with the production version. It seems your jest config should not recognize "/home/xxx/Projects/xxx/src/components/ManageUsersList" since it is not in your testMatch pattern. Did I miss something?

Can you take a snapshot of a working command line output (you should be able to see it in the TERMINAL tab with names like "Jest (xxx)").

Since you don't have a sample repo, please provide more details below:

appreciated.

DetachHead commented 10 months ago

@DetachHead, I tried your repo following your steps, and the test ran fine. Comparing the output, I did notice your "testPathPattern" is not right: it seems to be double-escaped \\\\ while the right pattern should be \\... Do you happen to be running with npm < 8.15? see comment for a known bug that could cause this issue.

not currently at that PC so i can't check right now, but that explanation sounds right. haven't updated node/npm in a while on that device, but the issue doesn't occur on my other machine with npm 10.2.4.

i'll check in a few hours and let you know if that was the issue

DetachHead commented 10 months ago

yeah updating npm fixed the issue for me

connectdotz commented 9 months ago

@mirceaburac-sugarcrm I think i might have found the suspect... please give v6.1.2 a try and let me know if it resolves the issue you were seeing.

mirceaburac-sugarcrm commented 9 months ago

@connectdotz Trying 6.1.2, it works to run individual test suites, but as soon as I try running a folder containing multiple suites, it errors.

Previous questions:

module.exports = { webpack: { alias: { '@myproject': path.resolve(dirname, 'src/'), '@maple-syrup': path.resolve(dirname, 'src/maple-syrup/'), }, }, jest: { configure: { moduleNameMapper: { '^@myproject(.)$': '/src$1', '^@maple-syrup(.)$': '/src/maple-syrup$1', }, }, }, };



- How did you run jest from the command line? What is the command and from which directory?
I don't, I run `yarn test` and run all suites. I started using the extension in order to be able to run tests individually while working on something specific. I guess now that the pre release lets me do that, I can work on specific tests using the extension, and run all suites with `yarn test`. Although it would be nice to be able to run multiple suites through the test window with the extension.
connectdotz commented 9 months ago

@mirceaburac-sugarcrm, good to hear you can run individual tests in the pre-release now.

As for running multiple suites for your monorepo project: Yes, you should be able to do so by setting up your project as a multi-root workspace or using the new jest.virtualFolders to host each project in its own (real/virtual) folder. You can find more info here: https://github.com/jest-community/vscode-jest?tab=readme-ov-file#how-to-use-the-extension-with-monorepo-projects