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 explorer 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 Run QUnit tests
, or simply click the refresh button on the QUNIT TEST RESULTS title bar. The tree will be automatically expanded to show any failing tests.
You can install the latest version of the extension via the Visual Studio Marketplace here.
Alternatively, open Visual Studio code, press Ctrl+P
or Cmd+P
and type:
> ext install vscode-qunit
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:
vscode-qunit.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):
vscode-qunit.showExecutionTimes
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 accommodate them. Any feedback is welcome!
"Pass" and "Fail" icons made by Maxim Basinski from www.flaticon.com, licensed by CC 3.0 BY
"Refresh" icon stolen from Patryk Zawadzki's Code Outline extension, which was also used as inspiration and guidance for this one.
"QUnit" icon stolen from the QUnit twitter account.