jest-community / vscode-jest

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

[BUG] Not able to run test more than once #1124

Closed hkan0157 closed 3 months ago

hkan0157 commented 4 months ago

Describe the bug I'm able to run only once in VS Code using Jest extension. In order to test it again, If I run the same test it just loads for long time, nothing happens. I need to close and open each time to run tests. But when I run tests as debug, it is fine. But when we need to run as normal test it doesn't allow.

Environment (please complete the following information):

Prerequisite


The fastest (and the most fun) way to resolve the issue is to submit a pull request yourself. If you are interested, please check out the contribution guide, we look forward to seeing your PR...

maxpatiiuk commented 3 months ago

I'm having the exact same issue - the test/tests show up as running, but nothing happens (and the 1min timeout is not triggered either)

https://github.com/jest-community/vscode-jest/assets/40512816/1b1e718f-72fb-4624-a501-77a551d86dba

If I create a new test file, then tests auto-run fine - it's when I want to run a specific test or file that things fail

I am in a monorepo with virtual folders setup and a custom Jest command. Settings:

{
  "jest.jestCommandLine": "yarn test",
  "jest.virtualFolders": [
    { "name": "components-controllers", "rootPath": "packages/support-packages/components-controllers" }
  ],
  "jest.runMode": "on-demand",
  "jest.debugMode": true,
}

Where yarn jest is defined as stencil test --spec -- (Stencil is proxying all extra flags to Jest CLI)


vscode-jest: v6.2.2 node -v: v20.11.0 npm -v or yarn --version: yarn 4.0.2 Operating system: macOS

are you able to run jest from the command line? Yes where do you run jest CLI from? rootPath is set to packages/support-packages/components-controllers how do you run your tests from the command line? Using Stencil, which wraps over Jest and forwards the arguments


If I change the jest.debugMode from true to false or the other direction, a window with this error pops up: Screenshot 2024-03-10 at 09 06 56

Sometimes I also see [error] failed to schedule test for /Users/mak13180/site/esri/arcgis-web-components-migration/packages/support-packages/components-controllers/src

connectdotz commented 3 months ago

Hmm... do you guys have a sample repo I can try to repro? Does this happen all the time or just occasionally? Does reload/restart make any difference?

maxpatiiuk commented 3 months ago

reload/restart does not fix the issue (happens again after the first run) when tests auto-run as part of creating new file or saving changes, all works fine when debugging individual test, all works fine it's only when running individual test in non-debug mode that it never completes - and such uncompleted tests are not stoppable/cancellable either

Does this happen all the time or just occasionally?

happens consistently in the condition described above. and consistently does not happen in the other conditions

do you guys have a sample repo I can try to repro?

I will try to create one tomorrow and will post the link here (might take a bit of time as the bug happens in a large proprietary monorepo)

maxpatiiuk commented 3 months ago

Hmm, Jest output when run using vscode-jest contains this:

Ran all test suites matching /\/|U|s|e|r|s|\/|m|a|k|1|3|1|8|0|\/|s|i|t|e|\/|e|s|r|i|\/|a|r|c|g|i|s|-|w|e|b|-|c|o|m|p|o|n|e|n|t|s|-|j|e|s|t|\/|p|a|c|k|a|g|e|s|\/|s|u|p|p|o|r|t|-|p|a|c|k|a|g|e|s|\/|c|o|m|p|o|n|e|n|t|s|-|c|o|n|t|r|o|l|l|e|r|s|-|s|l|i|m|\/|s|r|c|\/|t|e|s|t|s|\/|t|e|s|t|\|.|s|p|e|c|\|.|t|s/i with tests matching "a$".

That regex looks broken with all those pipes. But the Jest's CLI is called with correct regex, so it's something inside of Jest?

More details Here are the arguments Stencil passes to Jest's CLI: ```js { _: [], spec: true, testLocationInResults: true, json: true, useStderr: true, outputFile: '/var/folders/bm/w84q11_j2kvg36zkh5sjwkgc0000gp/T/jest_runner_components_controllers_502_2.json', testNamePattern: 'a$', coverage: false, reporters: [ 'default', '/Users/mak13180/.vscode/extensions/orta.vscode-jest-6.2.2/out/reporter.js' ], colors: true, watchAll: true, testPathPattern: '/Users/mak13180/site/esri/arcgis-web-components-jest/packages/support-packages/components-controllers-slim/src/tests/test\\.spec\\.ts', 'max-workers': 8, maxWorkers: 8, '$0': '../../../node_modules/@stencil/core/bin/stencil', config: '{"setupFilesAfterEnv":["/Users/mak13180/site/esri/arcgis-web-components-jest/node_modules/@stencil/core/testing/jest-setuptestframework.js","./src/tests/jestSetup.js"],"testPathIgnorePatterns":["/Users/mak13180/site/esri/arcgis-web-components-jest/packages/support-packages/components-controllers/.vscode","/Users/mak13180/site/esri/arcgis-web-components-jest/packages/support-packages/components-controllers/.stencil","/Users/mak13180/site/esri/arcgis-web-components-jest/packages/support-packages/components-controllers/node_modules","/Users/mak13180/site/esri/arcgis-web-components-jest/packages/support-packages/components-controllers/www"],"testRegex":"(/__tests__/.*|(\\\\.|/)(test|spec|e2e))\\\\.[jt]sx?$","runner":"/Users/mak13180/site/esri/arcgis-web-components-jest/node_modules/@stencil/core/testing/jest-runner.js","rootDir":"/Users/mak13180/site/esri/arcgis-web-components-jest/packages/support-packages/components-controllers","preset":"/Users/mak13180/site/esri/arcgis-web-components-jest/node_modules/@stencil/core/testing","transform":{"^.+\\\\.(ts|tsx)$":"./dist/build/jestPreprocessor.cjs"},"testRunner":"jest-circus"}' } ``` Note that testPathPattern looks like `/Users/mak13180/site/esri/arcgis-web-components-jest/packages/support-packages/components-controllers-slim/src/tests/test\\.spec\\.ts` But then Jest outputs the following: ```yaml Test Suites: 2 failed, 7 skipped, 1 passed, 3 of 10 total Tests: 46 skipped, 1 passed, 47 total Snapshots: 0 total Time: 1.703 s Ran all test suites matching /\/|U|s|e|r|s|\/|m|a|k|1|3|1|8|0|\/|s|i|t|e|\/|e|s|r|i|\/|a|r|c|g|i|s|-|w|e|b|-|c|o|m|p|o|n|e|n|t|s|-|j|e|s|t|\/|p|a|c|k|a|g|e|s|\/|s|u|p|p|o|r|t|-|p|a|c|k|a|g|e|s|\/|c|o|m|p|o|n|e|n|t|s|-|c|o|n|t|r|o|l|l|e|r|s|-|s|l|i|m|\/|s|r|c|\/|t|e|s|t|s|\/|t|e|s|t|\|.|s|p|e|c|\|.|t|s/i with tests matching "a$". ``` and then inside of jest, globalConfig is set to ```json { bail: 0, changedFilesWithAncestor: false, changedSince: undefined, ci: false, collectCoverage: false, collectCoverageFrom: [], coverageDirectory: '/Users/mak13180/site/esri/arcgis-web-components-jest/packages/support-packages/components-controllers/coverage', coverageProvider: 'babel', coverageReporters: [ 'json', 'lcov', 'clover' ], coverageThreshold: undefined, detectLeaks: false, detectOpenHandles: false, errorOnDeprecated: false, expand: false, filter: undefined, findRelatedTests: false, forceExit: false, globalSetup: undefined, globalTeardown: undefined, json: true, lastCommit: false, listTests: false, logHeapUsage: false, maxConcurrency: 5, maxWorkers: 8, noSCM: undefined, noStackTrace: false, nonFlagArgs: [], notify: false, notifyMode: 'failure-change', onlyChanged: false, onlyFailures: false, openHandlesTimeout: 1000, outputFile: '/var/folders/bm/w84q11_j2kvg36zkh5sjwkgc0000gp/T/jest_runner_components_controllers_502_2.json', passWithNoTests: true, projects: [], randomize: undefined, replname: undefined, reporters: [ [Array], [Array] ], rootDir: '/Users/mak13180/site/esri/arcgis-web-components-jest/packages/support-packages/components-controllers', runInBand: undefined, runTestsByPath: false, seed: -803780311, shard: undefined, showSeed: undefined, silent: undefined, skipFilter: false, snapshotFormat: { escapeString: false, printBasicPrototype: false }, testFailureExitCode: 1, testNamePattern: 'a$', testPathPattern: '/|U|s|e|r|s|/|m|a|k|1|3|1|8|0|/|s|i|t|e|/|e|s|r|i|/|a|r|c|g|i|s|-|w|e|b|-|c|o|m|p|o|n|e|n|t|s|-|j|e|s|t|/|p|a|c|k|a|g|e|s|/|s|u|p|p|o|r|t|-|p|a|c|k|a|g|e|s|/|c|o|m|p|o|n|e|n|t|s|-|c|o|n|t|r|o|l|l|e|r|s|-|s|l|i|m|/|s|r|c|/|t|e|s|t|s|/|t|e|s|t|\\|.|s|p|e|c|\\|.|t|s', testResultsProcessor: undefined, testSequencer: '/Users/mak13180/site/esri/arcgis-web-components-jest/node_modules/@jest/test-sequencer/build/index.js', testTimeout: undefined, updateSnapshot: 'new', useStderr: true, verbose: undefined, watch: false, watchAll: true, watchPlugins: undefined, watchman: true, workerIdleMemoryLimit: undefined, workerThreads: false } ```
maxpatiiuk commented 3 months ago

I pushed a minimum reproducible case in this repo - https://github.com/maxpatiiuk/vscode-jest-bug-reproduction

README.md contains reproduction steps

This might have something to do with Yarn, as changing run command from yarn test to npm run test resolves the issue

connectdotz commented 3 months ago

@maxpatiiuk, thanks for the sample repo. I can now reproduce this issue. It seems that the process we spawned was never closed as expected, thus blocking the subsequent test request.

The issue seems to be related to stencil, not yarn. If I run jest directly (by not setting jest.jestCommandLine), everything worked as expected. Looking at the command line we generated, the culprit seems to be the `"--watchAll=false", stencil interpreted this incorrectly and started the process in watch mode, opposite of what we intended.

You can easily reproduce this by issuing this command in the terminal:

yarn test --listTests --json --watchAll=false

You will see it went into a watch mode. Now compare with running jest directly:

yarn jest --listTests --json --watchAll=false

Directly running jest shows the right behavior. You might want to file a bug report in stencil.

connectdotz commented 3 months ago

@hkan0157, not sure if you have the same stencil dependency. I noticed your node/npm version is really old. The latest jest doesn't even support those versions anymore... which jest version are you running?