Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run | Debug inside docker container #199

Open
sashaaKr opened this issue Jul 20, 2021 · 8 comments
Open

Run | Debug inside docker container #199

sashaaKr opened this issue Jul 20, 2021 · 8 comments
Labels

Comments

@sashaaKr
Copy link

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.

@sochacki111
Copy link

Hi, same problem here. Any news on resolving that?

@pharapeti
Copy link

Also looking for a solution here

@firsttris
Copy link
Owner

just merged #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.

@pharapeti
Copy link

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

  1. jestrunner.projectPath set to /home/{userName}/pathToProjectContainingTestsAndConfig
  2. 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'?

@mkosir
Copy link

mkosir commented Aug 21, 2023

Also an issue for me, since our team setup runs all the tests inside docker.
@firsttris not sure how jestrunner.projectPath helps solve this 🤔

@sgriff96
Copy link

sgriff96 commented Oct 9, 2023

Would just like to bump this, it would be great for us if we could do this. Appreciate the extension either way though! :)

@domsleee
Copy link
Collaborator

domsleee commented Oct 14, 2023

So for this use case #199 (comment), 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)

@pharapeti
Copy link

@domsleee Just had a look at the #335, and I believe your PR would resolve this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants