DEV Community

Cover image for Instant test feedback with vscode
Andrei Eres
Andrei Eres

Posted on

Instant test feedback with vscode

Long story short — I'm trying to switch from vim to vscode.

I like TDD and run single or all specs lots of times. That way one of the things I love in vim — instant test feedback with vim-test.

Switching to vscode I discovered how to implement that using user tasks.

So, open Tasks: Open User Tasks with the command palette and paste your test tasks. I use these ones:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Test current file",
      "type": "shell",
      "command": "bundle exec rspec ${relativeFile}",
      "group": "test",
      "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": true
      }
    },
    {
      "label": "Test current line",
      "type": "shell",
      "command": "bundle exec rspec ${relativeFile}:${lineNumber}",
      "group": "test",
      "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": true
      }
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Also for quick running, I set up hotkeys with vim extension:

  "vim.normalModeKeyBindingsNonRecursive": [
    {
      "before": ["<leader>", "t"],
      "commands": [
        {
          "command": "workbench.action.tasks.runTask",
          "args": "Test current file"
        }
      ]
    },
    {
      "before": ["<leader>", "s"],
      "commands": [
        {
          "command": "workbench.action.tasks.runTask",
          "args": "Test current line"
        }
      ]
    }
  ],
Enter fullscreen mode Exit fullscreen mode

And that's it!
Alt Text

Top comments (0)