Run | Debug inside docker container
Hey there, First of all I would like to thank you for great plugin! 🥇
In our development team we are working in docker environment, and all our tests runs inside container as well.
Ability to override file path
I just wanna make sure that my approach is correct:
Since we are running tests inside container we use jestrunner.jestCommand to provide custom command:
"jestrunner.jestCommand": "docker-compose run --service-ports webapi ts-node-dev --transpile-only npm run --"
As result we are getting following command been executed:
docker-compose run --service-ports webapi ts-node-dev --transpile-only npm run -- '/home/ec2-user/company/webapi/tests/api/controllers/controller.test.ts' -t 'test_that_you_wanna_to_test'
The problem that file path is incorrect, since in docker-compose we bind volume project root to /app inside container, so instead of /home/ec2-user/company/webapi/tests/api/controllers/controller.test.ts we should run tests/api/controllers/controller.test.ts.
Our approach is to write custom script as it was suggested here and override file path, is there any configuration that we can use to achieve this functionality out of the box, or use of script as it was suggested is only valid solution
Debug inside docker container
Is there any configuration that can help us to achieve debugging inside docker container? As we saw jestrunner.jestCommand have no affect on debugging process, so we are wonder if there is any type of customization that we can achieve as we did with Run.
Hi, same problem here. Any news on resolving that?
Also looking for a solution here
just merged https://github.com/firsttris/vscode-jest-runner/pull/306
check version 0.4.66
which enables you to define a relative project path using jestrunner.projectPath
using this method you would be able to produce a relative path like tests/api/controllers/controller.test.ts
please let us know if this solves your issue.
Background
I might not be understanding the usage of the jestrunner.projectPath config yet, but I have jestrunner.projectPath set to the two following configurations
- jestrunner.projectPath set to
/home/{userName}/pathToProjectContainingTestsAndConfig - jestrunner.projectPath set to
/usr/app/server(where my volume mounted project lives in the Docker container)
With jestrunner.jestCommand: "docker exec -it backend yarn test"
In either case, when I open a test in VS Code on my host machine and click 'run' on a test, it generates the following command.
docker exec -it backend yarn test '/home/{userName}/Documents/{projectName}/backend/src/commands/models/command.model.test.ts' -c '/home/{userName}/Documents/{projectName}/backend/jest.config.js' -t 'Command model' --runInBand
This command fails as the test file is found within /usr/app/server/....., volume mounted into the container. (not /home/{my user}/Documents/{projectName}/backend/...)
Solutions
Is there any way to configure jestrunner to 'alter' the path of the test I run (and associated jestconfig) from being a host-defined path to a 'container path'?
Also an issue for me, since our team setup runs all the tests inside docker.
@firsttris not sure how jestrunner.projectPath helps solve this 🤔
Would just like to bump this, it would be great for us if we could do this. Appreciate the extension either way though! :)
So for this use case https://github.com/firsttris/vscode-jest-runner/issues/199#issuecomment-1652680492, we are trying to fix the path of the test file, right?
This command fails as the test file is found within /usr/app/server/....., volume mounted into the container. (not /home/{my user}/Documents/{projectName}/backend/...)
This is the test file path:
/home/{userName}/Documents/{projectName}/backend/src/commands/models/command.model.test.ts
But the real test file path we want is something like this?
/usr/app/server/backend/src/commands/models/command.model.test.ts
Would something like #335 meet this requirement? It seems like it would be nice to have a built-in way to support a path mapping or a transformation of the test file path for these use cases 👍
Also, projectPath here won't help with the test file path, it is just for resolving where changeDirectoryToWorkspaceRoot will change the directory to (I don't think it helps with the test file path)
@domsleee Just had a look at the #335, and I believe your PR would resolve this!