DEV Community

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

Posted on

1

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

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →