Vscode-jest: jest.disabledWorkspaceFolders not working

Created on 13 May 2020  Â·  5Comments  Â·  Source: jest-community/vscode-jest

Environment

  1. node -v: v10.16.2
  2. npm -v: 6.10.3
  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): [email protected]
  4. your vscode-jest settings if customized:

  5. Operating system: Win 10

Prerequisite

  • are you able to run jest test from the command line? yes
  • how do you run your tests from the command line? (for example: npm run test or node_modules/.bin/jest) npm run test

Steps to Reproduce

  1. add
    "jest.disabledWorkspaceFolders": [ ".history" ],
    to your settings.
  2. install the VS-Code Extension Local History
  3. Edit some test, so that the history extension will create a copy of the test file(with the path) in the /.history/ folder (of your root).
  4. check if a test file is in that folder
  5. run tests
  6. See that the Test from the history folder will also be run.

Expected Behavior

I expected the test from the .history folder not to be executed, as I put the folder name in the jest.disabledWorkspaceFolders setting.

Actual Behavior

The tests in the folders will be executed every time with the others.

This problem has nothing to do with the other extension, as I could have created the folder and files my self for whatever purpose. I just did name it here to show that this is not an unusual scenario.

All 5 comments

I believe vscode-jest auto-inserts the "jest.disabledWorkspaceFolders" settings into the wrong place when you click on the UI to insert it. I had to put it in my workspace settings and specifically put it inside the "settings" key/object, so in your case it'd look something like:

{
    "settings": {
        "jest.disabledWorkspaceFolders": [
            ".history"
        ],
    }
}

I can confirm this
also what EmpireJones suggested worked for me as well.

Strangly it did not work for me.

It's Happening here.

Jest should runs only in store dir, but it runs in design and docs also.

I am using a monorepo workspace, this is the json of the workspace settings:

.vscode/workspace.code-workspace

{
    "folders": [
        {
            "name": "✨ foo",
            "path": ".."
        },
        {
            "name": "📦 @foo/design",
            "path": "../packages/design"
        },
        {
            "name": "📦 @foo/docs",
            "path": "../packages/docs"
        },
        {
            "name": "📦 @foo/store",
            "path": "../packages/store"
        }
    ],
    "settings": {
        "jest.disabledWorkspaceFolders": [
            "../packages/docs",
            "../packages/design"
        ]
    }
}

I tried variations of disabledWorkspaceFolders like packages/docs, /packages/docs and @foo/docs. None of them worked.

I found a workaround:

add a folder setting that disables jest automatic run on each folder of the multi-root workspace:

packages/{docs,design}/settings.json

{
    "jest.autoEnable": false
}
Was this page helpful?
0 / 5 - 0 ratings