![]() ![]() ![]() Here’s an example configuration which creates a task that, when executed, will run the mocha command line tool, passing the location of the current file as an argument. The key to running only the current file is the $ variable (thanks to Jordan Nelson for pointing that variable out to me). But that example is for running all of the tests, not just the current file. The current documentation for a custom task already provides a good example for running a test script. If you don’t have one already, you can create one by selecting Configure Tasks from the Tasks menu and selecting the Other option (see Custom Tasks for more info). All you need to do is add a task to the project’s tasks.json file. VS Code’s Tasks support this very nicely. node_modules/.bin/mocha test/someTest.ts I want to be able to run the tests in VS Code the same way I run them on the command line: But unless I’m trying to troubleshoot a problem, I’d rather not add the overhead of running the tests with a debugger connected. It comes with support for debugging Node.js programs out of the box. One way to run tests in VS Code would be to use the debugger. In this post, I’ll point out what needs to be done to get VS Code to kick off Mocha to run the tests in a current file. However, it wasn’t immediately obvious how to get VS Code to do that. For efficiency’s sake, I like to execute the tests in the test file I’m currently editing, right from the editor (I’ve written about setting up Vim to run the current test file in an external terminal in the past). ![]() As part of my normal workflow, I try to follow TDD practices as much as possible. It’s a pretty great editor, and its support for TypeScript is fantastic. ![]() For the last few months, I’ve been using Visual Studio Code on a Node.js project. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |