Harrygr

Harrygr

Running/debugging tests in VSCode with ElixirLS

I’m trying to set up a nice debugging experience in my pretty bog-standard Phoenix app using VSCode and ElixirLS. Currently it kind of works but there are a number of issues with it:

  • The tests run very slowly compared to mix test (221s vs 7s)
  • The debugger output is very noisy and interspersed with errors that don’t arise during a normal test run.
  • The debugger hangs at the end of the test run and has to be manually stopped

I’m using the default config as generated by ElixirLS:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "mix_task",
      "name": "mix test",
      "request": "launch",
      "task": "test",
      "taskArgs": [
        "--trace"
      ],
      "startApps": true,
      "projectDir": "${workspaceRoot}",
      "requireFiles": [
        "test/**/test_helper.exs",
        "test/**/*_test.exs"
      ]
    }
  ]
}

Here’s the output from starting the debugger:

Started ElixirLS debugger v0.5.0
Elixir version: "1.10.3 (compiled with Erlang/OTP 22)"
Erlang version: "23"
ElixirLS compiled with Elixir 1.7.4 and erlang 20
# lots of Bcrypt errors 🤷‍♂️

I’d also like to be able to only run tests for the current file, or even just the current test. I believe vscode exposes various interpolations for launch configs.

Has anyone managed to get a nice test debugging experience in vscode with Elixir? Are there any changes I can make to fix the above problems.?

Most Liked

peoj

peoj

Could you say a bit more as to why please? Is there a way to modify this behaviour?

Here’s an example that works, although the by line test is a bit less convenient since your cursor must be on the precise line of the test you want to run:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "mix_task",
      "name": "mix test",
      "request": "launch",
      "task": "test",
      "taskArgs": [],
      "startApps": true,
      "projectDir": "${workspaceRoot}",
      "requireFiles": ["test/**/test_helper.exs", "test/**/*_test.exs"]
    },
    {
      "type": "mix_task",
      "name": "mix test current file",
      "request": "launch",
      "task": "test",
      "taskArgs": [
        "${relativeFile}"
      ],
      "startApps": true,
      "projectDir": "${workspaceRoot}",
      "requireFiles": [
        "test/**/test_helper.exs",
        "${relativeFile}"
      ]
    },
    {
      "type": "mix_task",
      "name": "mix test current line number",
      "request": "launch",
      "task": "test",
      "taskArgs": [
        "${relativeFile}:${lineNumber}"
      ],
      "startApps": true,
      "projectDir": "${workspaceRoot}",
      "requireFiles": [
        "test/**/test_helper.exs",
        "${relativeFile}"
      ]
    }
  ]
}

Any thoughts on how we might be able to speed this up? Some performance degradation is fine (and I imagine unavoidable) but it’s incredibly slow to use at the moment, and often quicker to add a few IO.inspect statements. Perhaps there is a way of specifying only certain modules that we’re interested in instrumenting?

lukaszsamson

lukaszsamson

ElixirLS Core Team

With VSCode ElixirLS extension it’s now possible to debug test directly from Testing tab or via right clicking the icon next to test definition and selecting Debug test. It will run the debugger with a launch configuration for mix test task and fall back to a default one if not found

Harrygr

Harrygr

I’m not sure you understood my question. It has nothing to do with Jest or JavaScript. These are Elixir tests that use ExUnit. The steps you mention don’t explain anything either.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New

We're in Beta

About us Mission Statement