vscode-mocha | Runs Mocha tests inside Visual Studio Code
kandi X-RAY | vscode-mocha Summary
kandi X-RAY | vscode-mocha Summary
Runs Mocha tests inside Visual Studio Code
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Runs tests .
- Finds test files .
- Select all tests .
- Returns the node path to the node executable .
- Initialize reporter .
- Registers the subscribers command .
- Run tests against a pattern
- Run all tests
- fork of node_js
- Convert a suite into Javascript object representation .
vscode-mocha Key Features
vscode-mocha Examples and Code Snippets
Community Discussions
Trending Discussions on vscode-mocha
QUESTION
I have run both npm i ts-node
and npm i ts-node --save-dev
with no changes. ts-node works fine when I run it from the command line, but for some reason I cannot run mocha tests through test explorer. I get the error below:
error:
...ANSWER
Answered 2020-Oct-28 at 03:13Turns out none of the package.json config options were working for me. I wound up implementing a .mocharc.json on the same level as my package.json which worked perfectly.
Example from this github repo (with more examples) copied here for posterity.
QUESTION
I've been playing with a Typescript project that doesn't yet have tests written. (Commit Adding Tests)
I've tried 2 different methods of adding tests written in Typescript.
- launch.json
- package.json
Both of these approaches currently work, and are able to be debugged via the normal task launch / debugging.
However I've tried 2 different VSCode Extensions, to add support to the test explorer to run these tests, to get better GUI and automatic feedback, visualize coverage etc.
Mocha-Sidebar and Mocha test Explorer
Neither of them have picked up the tests that I have written using the default configuration. And both of them have sparse documentation on how to setup Tests written in Typescript
All blog posts found online, currently seem to be relevant from testing from the command line / task launching.
How can Mocha-Sidebar or Mocha-Test-Explorer or Some other Test Explorer Adapter be configured to work with the tests in that commit.
And is it possible without committing further configuration files to the git repository, and have someone fork the project and be able to run the tests.
e.g. BDD style, inside test folder, named like test/hello-world.test.ts
written in Typescript, With full debugging support.
ANSWER
Answered 2020-Mar-20 at 23:42Invoking Mocha
When you invoke mocha
via command line, package.json, or launch.json, you provide mocha with two critical pieces of information:
- A glob pattern specifying where the test files are.
- A
--require
flag, specifying any additional modules to load.
When using one or both of the VSCode extensions mentioned, the extension(s) needs to be provided these two key pieces of information.
Configuring Extensions
These two extensions have a lot of overlap, so I'd recommend using one or the other. My personal preference is Mocha Test Explorer. I found the Mocha Sidebar was excessively slow in running larger test suites. At any rate, they are both configured a very similar fashion:
Mocha Explorer
Tell it where the tests are, and to use ts-node
for on-the-fly compilation. These settings go in settings.json
, at either the user level or the project level.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install vscode-mocha
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page