This extension allows you to run your QUnit unit tests from inside Visual Studio Code, displaying the results in a tree view in the explorer pane. Clicking on the results in the tree view will attempt to reveal the tests and assertions in the tests file.
To get started, either right click your tests file in the exlorer window and select Set as file to run QUnit tests, or visit your preferences and set the file manually (see Configuration below). Note: If you use the context menu, the file is stored in your workspace preferences.
To run your tests, press F1, and select or enter
You can install the latest version of the extension via the Visual Studio Marketplace here.
Alternatively, open Visual Studio code, press
The extension is designed to work with version 2.4.1 of QUnit. It may possibly work with older versions.
The source code is available on GitHub here.
To make it work, you'll need to define the path to your test HTML file:
This should be set to the full path of the file you would normally load in the browser to execute your tests and view the results. This extension runs the file in a headless browser in order to parse the results and populate the tree.
There is also a setting to control display of test execution times (off by default):
Currently, revealing the assertions is done using a search with regular expressions. This works fine as long as your assertions are defined in order. If you put assertions into local functions within the test, it won't work. Sorry.
The view currently can't be refreshed without rebuilding the tree. This means that the expansion state of the tree is not preserved.
There are probably lots of use cases where it doesn't work properly. Please let me know and I'll try and accomodate them. Any feedback is welcome!
"Refresh" icon stolen from Patryk Zawadzki's Code Outline extension, which was also used as inspiriation and guidance for this one.
"QUnit" icon stolen from the QUnit twitter account.