Skip to content

Instantly share code, notes, and snippets.

@whazzmaster
Last active November 21, 2022 09:06
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save whazzmaster/b9071c2706cc588293a73ec3b6613d20 to your computer and use it in GitHub Desktop.
Save whazzmaster/b9071c2706cc588293a73ec3b6613d20 to your computer and use it in GitHub Desktop.
Test tasks for Visual Studio Code and Elixir
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "cmd+t cmd+t",
"command": "workbench.action.tasks.runTask",
"args": "Run All Tests"
},
{
"key": "f5",
"command": "workbench.action.tasks.runTask",
"args": "Run Focused Test"
},
{
"key": "f4",
"command": "workbench.action.tasks.runTask",
"args": "Set Focused Test"
},
{
"key": "f6",
"command": "workbench.action.tasks.runTask",
"args": "Debug Focused Test"
},
{
"key": "cmd+t cmd+f",
"command": "workbench.action.tasks.runTask",
"args": "Test Current File"
}
]
{
"version": "2.0.0",
"tasks": [{
"label": "Build",
"command": "mix",
"group": "build",
"args": [
"compile"
],
"problemMatcher": [
"$mixCompileError",
"$mixCompileWarning"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
{
"label": "Run All Tests",
"command": "mix test",
"type": "shell",
"group": "test",
"problemMatcher": [
"$mixCompileError",
"$mixCompileWarning",
"$mixTestFailure"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
{
"label": "Set Focused Test",
"group": "test",
"type": "shell",
"command": "echo -n ${relativeFile}:${lineNumber} > ${workspaceRoot}/.vscode/TEST_FOCUS",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
{
"label": "Clear Focused Test",
"group": "test",
"type": "shell",
"command": "rm ${workspaceRoot}/.vscode/TEST_FOCUS",
"presentation": {
"echo": true,
"reveal": "never",
"focus": false,
"panel": "shared"
}
},
{
"label": "Run Focused Test",
"command": "mix test $(cat ${workspaceRoot}/.vscode/TEST_FOCUS)",
"type": "shell",
"group": "test",
"problemMatcher": [
"$mixCompileError",
"$mixCompileWarning",
"$mixTestFailure"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
{
"label": "Debug Focused Test",
"command": "iex -S mix test $(cat ${workspaceRoot}/.vscode/TEST_FOCUS)",
"type": "shell",
"group": "test",
"problemMatcher": [
"$mixCompileError",
"$mixCompileWarning",
"$mixTestFailure"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new"
}
},
{
"label": "Test Current File",
"command": "mix test ${relativeFile}",
"group": "test",
"type": "shell",
"problemMatcher": [
"$mixCompileError",
"$mixCompileWarning",
"$mixTestFailure"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
}
]
}
@whazzmaster
Copy link
Author

Place a copy of this file in your Elixir project's .vscode directory. Bring up the command palette and type Run Test Task and then Enter, then choose one of the listed test tasks. By setting a Focused File you can then run it tests in that file repeatedly no matter what file buffer has focus.

@Manzanit0
Copy link

Hi! Great compilation of tasks, I've found this snippet super useful :-)

By the way, do you where the references $mixCompileError, etc. come from? I can't seem to track them down and VS Code doesn't like them - it says: Error: Invalid problemMatcher reference: $mixCompileError.

I did check the official vscode-elixir repository out: https://github.com/fr1zle/vscode-elixir#problem-reporting, but it doesn't give any context on where they come from, so I'm not really sure how to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment