-
Notifications
You must be signed in to change notification settings - Fork 31
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
Running tests remotely (e.g. in docker) #13
Comments
First of all: Wow! It would be fascinating to make this work.
So... if IPC could be run over TCP and you had the ability to specify your own launch config for debugging, do you think you'd have everything you need? |
Thanks for the quick reply. I think I'd only need a couple other things:
As a first step, I can submit a PR to bundle the worker scripts. I've used |
Yes, that's the plan: make the port fixed and configurable. As for the path conversion and the bundling: I don't want to add any more complexity to this adapter |
I've created a branch called
The IPC connection is currently established by the worker, i.e. the adapter acts as a TCP server and the worker as a client. So you don't have to open a port for this in your docker config, but you have to somehow forward the This is the default configuration used for debugging - use this as a template for your own debug config:
(if you change the I like the idea of bundling the worker script with its dependencies, but there is a problem: the worker script contains a dynamic Finally, there is still the issue of converting the paths - this has to be done for the arguments to the worker script, but also for the events that the worker sends back to the adapter. I could write some utility methods that help with that. |
Thanks! I'm taking a look at the code.
Hmm, my shim script can probably establish a reverse-tunnel using
I prototyped a worker bundler using rollup; I'll share it to see what you think. As much as I love webpack, rollup's config in this case was simpler.
For
If you want to keep your code as simple as possible, you can expose a "path conversion plugin" API. Then I can implement a localRoot to remoteRoot converter plugin. VSCode's debugger already uses localRoot and remoteRoot to handle this; it's a shame it doesn't expose a path conversion API that we can use.
Right now the arguments are being passed as positional arguments. You want to keep your worker as simple as possible (understandable) so my shim script will need to parse, convert, and re-serialize these args. The problem is, the index of
This makes it simpler for shim scripts to parse, mutate, and re-serialize the args. Unknown options can be passed through verbatim. This doesn't eliminate the possibility of breakage but it reduces it. And I think it keeps your code just as simple as it is today. |
Well, it was the straightforward thing to do when I started this adapter, but I agree that I should move this to a single JSON string now. I'm planning to write (and maintain) a little collection of utility functions for this scenario. One of those functions would apply the path conversion to the JSON-encoded worker arguments, another one could set up a little TCP proxy for the worker events that applies the path conversion to the events. So the only thing that your shim script would have to do for path conversion is call these functions and pass them your path conversion plugin. |
I've started implementing the utility functions, but they're completely untested so far because I couldn't yet figure out how to bundle the worker scripts:
Any ideas? |
I implemented rollup bundling in #19. I'm using two common rollup plugins to handle node's module resolution and CommonJS imports & exports. I also added a hack to give us access to node's |
I pushed a lot more changes, experimental at the moment.
|
I have implemented a new approach in my The new approach is to let you replace the worker script with an adapter script in your project and pass the path to the directory containing the worker bundle to your script so that it can start the worker. With this approach, this extension remains simple and generic while giving you maximum flexibility. I have also created an example project that runs its tests in a Docker container. Check it out! Debugging isn't working yet, but everything else works (only tested on Linux so far). Some notes:
|
I got debugging to work as well - kind of. Breakpoints don't work initially so you have to use a |
I think the issue with breakpoints not working initially (they work after hitting a |
How do the new VS Code remote extensions effect this issue? |
When you use a remote workspace, the tests will automatically be run remotely, so that's a possible solution. |
This is now (finally!) supported by Mocha Test Explorer: you'll have to write a launcher script that runs the tests remotely - there are example projects for running tests in a docker container and via ssh that contain well-documented launcher scripts and a project containing further documentation and utility functions to use in the launcher script. |
My team needs to run mocha tests in a docker container. The containerized environment is configured with special CLI tools and networked services that our code must access. I've created a VSCode launch.json configuration that runs mocha via
docker exec
, attaches the debugger, maps sourcemaps correctly, and lets us set breakpoints. It works! But it's incompatible with your great sidebar, so we can't e.g. debug a single test case.Here's what I've tried so far:
Implementing a shim script for
"execPath"
that emulates "node" but actually invokes it within our docker container. (docker exec $containerId node
) Unfortunately:docker exec
doesn't forward the extra file descriptor used bychild_process.fork()
so IPC is broken. I'm trying to create a multiplexer / demultiplexer so that multiple file descriptors can be tunneled over stdin /stdout into the docker container. Usage looks something like this:multiplex -- docker exec $containerId demultiplex -- node ./node_modules/bin/_mocha
My shim script needs to map host paths into container paths. This is a hack and requires
JSON.parse()
-ing the argv array. I also need to download a copy of vscode-mocha-test-adapter into my project's source tree so that "node" within the container can run "./worker/{runTests,loadTests}.sh" It would be great if this happened automatically via my debug configuration's "localRoot" and "remoteRoot."Docker containers cannot forward additional ports after they've started. So I'm stuck using the same port or range of ports for node's debugger protocol. I need a way to set the port instead of getting one at random.
The debugger configuration needs the appropriate sourcemap options so that breakpoints and line numbers are correct. Our configuration looks something like this:
Ideas to support this use-case
Support a user-specified "template" launch configuration for debugging. For example, set
"mochaExplorer.launchTemplateId": "docker-debug"
and it'll inherit the right "localRoot", "remoteRoot", "port", etc options. This solves most of the issues.Add the ability to install ./worker/ scripts via npm so they can be run from within the docker container. Alternatively, maybe there's an easy way to pipe them into node via a mix of "node -e" and IPC? That way, the worker process doesn't even need filesystem access to the worker scripts.
Support IPC over stdin / stdout, so that it's compatible with
docker exec
. If this is too complex, I'll keep using my multiplexer / demultiplexer script.I realize this is a ton to ask. If we add a few, relatively simple features to vscode-mocha-test-adapter, I can finish my
"execPath"
shim scripts, and the combination of the two will do the trick. I am happy to help implement these features, too. What do you think?The text was updated successfully, but these errors were encountered: