🧪 vscode test current file task

While setting up a new project at Atlassian, I decided to dive into some vscodeworkspace settings to see how I could improve the developer experience. I found the task system to be pretty interesting and extensible, so I created a custom task to run te…


This content originally appeared on DEV Community and was authored by Omura

While setting up a new project at Atlassian, I decided to dive into some vscodeworkspace settings to see how I could improve the developer experience. I found the task system to be pretty interesting and extensible, so I created a custom task to run tests against the currently open file.

Custom task definitions are placed in .vscode/tasks.json. Most of the fields are straightforward, but the command property has some interesting bits. There are all sorts of variables you can use to get information about the current file and directory you're in. You can also do things like run a task when a workspace is opened with the runOn property. Here's what my task definition looked like.

{
"version": "2.0.0",
"tasks": [
{
"label": "test current file",
"type": "shell",
"command": "npm run test
${fileBasenameNoExtension}.test${fileExtname}",
"group": "test",
"presentation": {
"clear": true,
"close": false,
"panel": "dedicated"
}
}
]
}

To run this task, open up the command palette by pressingCmd+P. Then select Tasks: Run Tasks to view a list of custom tasks. Finally, choose the test current file task from the list. If you ask me, this is a much better workflow than executing npm run test and then entering in the exact file path you're looking for.


This content originally appeared on DEV Community and was authored by Omura


Print Share Comment Cite Upload Translate Updates
APA

Omura | Sciencx (2024-08-21T02:22:55+00:00) 🧪 vscode test current file task. Retrieved from https://www.scien.cx/2024/08/21/%f0%9f%a7%aa-vscode-test-current-file-task/

MLA
" » 🧪 vscode test current file task." Omura | Sciencx - Wednesday August 21, 2024, https://www.scien.cx/2024/08/21/%f0%9f%a7%aa-vscode-test-current-file-task/
HARVARD
Omura | Sciencx Wednesday August 21, 2024 » 🧪 vscode test current file task., viewed ,<https://www.scien.cx/2024/08/21/%f0%9f%a7%aa-vscode-test-current-file-task/>
VANCOUVER
Omura | Sciencx - » 🧪 vscode test current file task. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/21/%f0%9f%a7%aa-vscode-test-current-file-task/
CHICAGO
" » 🧪 vscode test current file task." Omura | Sciencx - Accessed . https://www.scien.cx/2024/08/21/%f0%9f%a7%aa-vscode-test-current-file-task/
IEEE
" » 🧪 vscode test current file task." Omura | Sciencx [Online]. Available: https://www.scien.cx/2024/08/21/%f0%9f%a7%aa-vscode-test-current-file-task/. [Accessed: ]
rf:citation
» 🧪 vscode test current file task | Omura | Sciencx | https://www.scien.cx/2024/08/21/%f0%9f%a7%aa-vscode-test-current-file-task/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.