Closed akwodkiewicz closed 1 year ago
When I'm clicking "play" on the oauth
folder (location: packages/backend/src/auth/oauth
), I get the following output:
> my-backend-project@.0.1 test
> env-cmd -f .env jest \
... \
--testPathPattern /Users/akwodkiewicz/Private/repo-A/src/auth/oauth
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/akwodkiewicz/Private/repo-A/packages/backend/src
7472 files checked.
testMatch: - 0 matches
testPathIgnorePatterns: /node_modules/ - 7472 matches
testRegex: \.spec\.ts$ - 1412 matches
Pattern: /Users/akwodkiewicz/Private/repo-A/src/auth/oauth - 0 matches
npm ERR! Lifecycle script `test` failed with error:
npm ERR! Error: command failed
npm ERR! in workspace: my-backend-project@0.0.1
npm ERR! at location: /Users/akwodkiewicz/Private/repo-A/packages/backend
The pattern passed to the script is always the concatenation of:
/Users/akwodkiewicz/Private/repo-A/
src/auth/oauth
It's missing the packages/backend
part, which is the rootPath
defined in the virtualFolders
option!
I believe the --testPathPattern
is set here:
And the value for testFileNamePattern
might be set here:
And uri
there is crafted with this static method:
When you look at the VirtualWorkspaceFolder
you can see a effectiveUri
property:
The comment above it sounds like it's something we need. But the effectiveUri
is only used to determine if something is in the virtual workspace folder, the uri
property does not use this effectiveUri
.
Is it possible that the fix would look like this?
get uri(): vscode.Uri {
return this.effectiveUri;
}
Ok, I think it's something like this:
The URI of the virtual workspace folder is defined to be the same as the "actual workspace folder". There's even a unit test for this
So whenever we run the command for my repo-A/packages/backend
virtual folder, we're going to use the repo-A
URI to calculate some paths.
To establish the test path patterns, we need to craft the URIs with the help of FolderData.makeUri
. It joins a folder name with the parent URI
. So it explains why oauth
is prefixed with auth
and auth
is prefixed with src
-- it matches what I see in the GUI.
But, then there's a question of "what is the root parent element"? And I think the answer is in line 194:
If there are no parents, then the root is the this
, which refers to the WorkspaceRoot
class.
It would then explain why
oauth
is prefixed by the parent:
auth
and its parent:src
and then, since this is the root of the virtual folder, we don't have any parents (I guess), so we're left with this
:
/Users/akwodkiewicz/Private/repo-A/
and the packages/backend
is missing from the equation.
We would need to somehow add the information about the effectiveUri to the WorkspaceRoot
or use VirtualWorkspaceFolder
-specific methods instead of FolderData
static ones to account for the rootPath
of the virtual folder.
I think the only way to make it work is for the VirtualWorkspaceFolder
to return effectiveUri
as the URI. This is even mentioned in the class comment https://github.com/jest-community/vscode-jest/blob/ad719cb5b9509715047f1cae8ea7204db5f8faa5/src/virtual-workspace-folder.ts#L91
This makes sense, cause the "virtualness" of the folder is transparent to the context class, so it should behave as a real folder and return its real URI.
I'll try to prepare a PR tonight
@akwodkiewicz, good catch and nice investigation. 👍
But let's not change the uri
for the virtualWorkspaceFolder, as many vscode and other components use, and assume that attribute yields the same as the original vscode.WorkspaceFolder
. I think we might be able to fix this with a much narrower change:
VirtualWorkspaceFolder
(readonly)WorkspaceRoot.createTestItem()
to use the effectiveUri
for virtualWorkspaceFolder: https://github.com/jest-community/vscode-jest/blob/10414abf47d9829d67ef8932fdd12bb472154ed9/src/test-provider/test-item-data.ts#L135I hope this is enough to fix the issue and look forward to the PR!
@connectdotz, thanks for the suggestions.
But let's not change the
uri
for the virtualWorkspaceFolder, as many vscode and other components use, and assume that attribute yields the same as the originalvscode.WorkspaceFolder
.
Do you mean the setup wizard? (maybe it's broken too 😅)
I followed your advice and prepared a PR according to your proposal: https://github.com/jest-community/vscode-jest/pull/1080
I launched the modified extension on my repo and it worked correctly!
Sorry but it doesn't work without any virtual folders(
In my case "jest.rootPath": "client/src"
and when I'm try to run test on folder by interface I get command
DEFAULT_LOCALE=ru jest --testLocationInResults --json --useStderr --outputFile /tmp/jest_runner_stoege_1000_2.json --no-coverage --reporters default --reporters /home/wsl/.vscode-server/extensions/orta.vscode-jest-6.1.0/out/reporter.js --colors --watchAll=false --testPathPattern /home/wsl/Development/app/core
where testPathPattern
is ignore rootPath
it must be --testPathPattern /home/wsl/Development/app/${rootPath}/core
Environment
vscode-jest version
: v6.0.1node -v
: v18.16.0npm -v
~ oryarn --version
: 3.4.1npm ls jest
ornpm ls react-scripts
(if you haven’t ejected)~:yarn why jest
your vscode-jest settings if customized:
my.code-workspace
:Operating system: macOS 14.0 (23A344) (Sonoma)
Prerequisite
npm run test
ornode_modules/.bin/jest
)yarn test
Steps to Reproduce
Open "Testing" tab
Try to "Run Test" on a "folder" item (for the purpose of troubleshooting, I'm selecting the
redis
folder in my project).Relevant Debug Info
I'm running VSCode from a .code-workspace file, this is a monorepo, but I don't have multiple roots defined (and I don't want to have them). I'm trying this new
virtualFolder
setup.~Might be unrelated to the issue, though.~ (EDIT: it probably is the issue, see the next comment)
Full path to the redis folder:
/Users/akwodkiewicz/Private/repo-A/packages/backend/src/redis
Relative path to the .code-workspace file
packages/backend/src/redis
Expected Behavior
All tests from the selected folder are run.
Actual Behavior
No tests are found.
"Test Results" tab output (added line breaks in command for readability):
~It looks like the
--testPathPattern
should be set toredis
-- then searching for this path pattern would be successfulIn /Users/akwodkiewicz/Private/repo-A/packages/backend/src
.~~However, the script is passed a faulty concatenation of the workspace absolute path (
/Users/akwodkiewicz/Private/repo-A
), the outersrc
folder (which is visible in the "Testing tab", but I did not put it on the screenshot), andredis
.~EDIT: The
--testPathPattern
is wrong, but a better analysis of what happens is in the next comment