Skip to content

scottming/vscode-elixir-test-in-iex

Repository files navigation

elixir-test-in-iex README

Tested in IEx Shell, it's really fast, most tests will run at least 10-20 times faster, this plugin makes TDD painless.

image

Installation

You can install it through the Visual Studio Code Marketplace.

Features

TestInIEx: Run test File

It will automatically start the IEx shell and run test in it, for umbrella apps, it will cd to the child app of the test file, restart the IEx shell if needed, and run test.

Nov-27-2022 15-20-02

TestInIEx: Run Test at Cursor

Similar behavior as Run test File, but at the cursor.

Nov-27-2022 15-21-45

Hidden features

TestInIEx: Start Test

This elixir-test-in-iex.startIExTest will start the IEx shell for testing manually. Sometimes, you cancel the IEx shell, and want to do the test again, but it can't be started, because the cache is corrupted, this time, you need this.

Run the last command

This is not a command, every time you run the test, the plugin will cache the command text, and when you back to product code(not test file), whether you runTestFile or runTestFileAtCursor, it will automatically execute the previous command.

Keybindings

By default, the plugin does not bind you any shortcuts, so you need to open the command panel to execute them, or bind your own shortcuts for these two commands: elixir-test-in-iex.runTestFile and elixir-test-in-iex.runTestAtCursor.

For example:

  {
    "key": "shift+cmd+i f",
    "command": "elixir-test-in-iex.runTestFile",
    "when": "editorTextFocus && editorLangId == 'elixir'"
  },
  {
    "key": "shift+cmd+i c",
    "command": "elixir-test-in-iex.runTestAtCursor",
    "when": "editorTextFocus && editorLangId == 'elixir'"
  }

I am a vim user and my recommendation is to use whichkey, here is a reference:

    {
      "key": "t",
      "name": "+Test",
      "icon": "test",
      "type": "bindings",
      "bindings": [
        {
          "key": "t",
          "name": "Test at cursor",
          "type": "conditional",
          "bindings": [
            {
              "key": "languageId:elixir",
              "name": "Run elixir test at cursor in IEx shell",
              "type": "command",
              "command": "elixir-test-in-iex.runTestAtCursor"
            },
          ]
        },
        {
          "key": "T",
          "name": "Test File",
          "type": "conditional",
          "bindings": [
            {
              "key": "languageId:elixir",
              "name": "Run elixir test",
              "type": "command",
              "command": "elixir-test-in-iex.runTestFile"
            },
          ]
        },
        {
          "key": "D",
          "name": "Detach the activate terminal",
          "type": "command",
          "command": "workbench.action.terminal.detachSession"
        }
      ]
    }

by this keybinding, I only need to press space t t or space t T to triger the test.

Q & A

1. Q: What if run test does not start IEx?

A: The most likely reason is that it has been started before and cached, so the easiest way to fix this is Detaching current terminal session, you can set a keybinding for this command: workbench.action.terminal.detachSession, after detaching, you can run test again.

Enjoy!

This extension is inspired by neotest and vscode-elixir-test, big thanks to them.

About

Elixir test in IEx Shell

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published