hbenl / vscode-mocha-test-adapter

Mocha Test Adapter for the VS Code Test Explorer
MIT License
91 stars 31 forks source link

Help with getting docker compose debug working correctly #224

Open duncanf95 opened 2 years ago

duncanf95 commented 2 years ago

Hey, for a few month on and off I've been trying to get this project to run tests in a docker image created by a docker compose file, and ran with docker-compose up. This is the way my job runs most of it's services locally.

I've found success in getting the tests to run, I have 2 repos to show an example api and a fork of the launcher scripts

settings.json:

{
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
      },
      "eslint.validate": ["typescript"],
      "mochaExplorer.files": "test/**/*.ts",
      "mochaExplorer.launcherScript": "node_modules/mocha-explorer-launcher-scripts/docker-compose",
      "mochaExplorer.require": [ "ts-node/register" ],
      "mochaExplorer.debuggerConfig": "Debug in Docker",
      "mochaExplorer.logpanel": true,
      "mochaExplorer.exit": true,
      "mochaExplorer.debuggerPort": 9230,
      "mochaExplorer.timeout": 15000,
      "mochaExplorer.env": {
        "DOCKER_CONTAINER_NAME": "example_app"
      }
}

If you clone both, run npm link on the launcher script fork and then run npm link mocha-explorer-launcher-scripts in the example-api folder. Add the settings above to the settings.json and then run a docker compose up. After this you'll notice that the tests run in the test explorer and provide correct feedback on whether they pass or fail when run.

The place where I've gotten stuck in the debugging part of it, I can't seem to get it to hit breakpoints and I feel like I must be misunderstanding the process a little. I've left my launch.json below to help. If anyones able to shed light on what I'm doing wrong I would bevery grateful. i hope to contribute this example back when I'm done so this becomes an easier process.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "Debug in Docker",
            "timeout": 30000,
            "continueOnAttach": true,
            "remoteRoot": "/app",
            "sourceMaps": true,
            "port": 9230,
            "resolveSourceMapLocations": [
                "${workspaceFolder}/**",
                "!**/node_modules/**"
            ]
        }
    ]
}