How to use Mocha testrunner instead of built-in - javascript

I'm creating e2e test using WebdriverIO.
As I understand test-runner calling sequence is smth like
NPM (package.json) -> WDIO (wdio.conf.js) -> Mocha (via "wdio-mocha-framework")
As far as i know, Wdio is designed for using built-in test-runner. But is there way for call wdio from mocha? This is needed for debug in IDE and run test separately.

You can use 'standalone' mode to require the test runner via Mocha.
There are a bunch of examples of standalone mode on their github page.

Related

IntelliJ IDEA: Can I run "green arrow" unit tests directly with Mocha, when both Karma and Mocha are installed?

I have unit tests set up with Karma and Mocha. Karma is important here because some of the functionality I'm testing needs a web browser (even if a fake headless one). But much of the code can run either in a browser or Node.js. For debugging tests it would be much easier to skip launching Karma and use Mocha directly most of the time.
I can do that easily enough if running the whole test suite, but I'd like to be able to use the convenience of the little green play-button style arrows for individual tests. Unfortunately, even for a single unit test, these always launch Karma now.
Disabling the Karma plugin doesn't help. Instead, that makes all of the green arrows go away, with no easy access to either Karma or Mocha.
Is there a way to configure IDEA so that these convenience arrows ignore Karma, and directly run Mocha tests instead?
The logic used for determining what test runner is available for a given test file is based on dependencies declarations in package.json nearest to the current file.
Note that if you have a single package.json, with both karma and mocha included, and there is a karma config in your project, karma is preferred - see https://youtrack.jetbrains.com/issue/WEB-26070#comment=27-2088951. To force using Mocha test runner for files in a certain directory, create a Mocha run configuration with Test directory: set to this directory - when running tests from gutter in this folder, mocha will be used.

Run tests with js wdio test runner via WebStorm IDE

I'm trying to build a test framework using mocha + webdriver.io.
I've chosen wdio test runner and all tests are running good via CLI but I want to configure WebStorm IDE to run single test in debug mode and can't understand how to do it.
As I understood there is no WebStorm support for this directly and I need to configure default Node.js run with valid parameters in order to trigger wdio runner with my test case.
Check https://alippai.github.io/ for a brief guide. It's running the tests with the mocha executable instead of the default wdio.
The next config is working for me (wdio+jasmine)

Run Jasmine tests from WebStorm

WebStorm shows icons next to Jasmine's test cases and it seems as if there should be an option to run it, but the menu just says: Nothing here.
As I did not find any documentation about this feature, I wonder if it should be possible to run tests like this and if yes, what the conditions are.
This likely means that no suitable test runners have been found. WebStorm doesn't manage test running directly. This job is done by a test runner. WebStorm supports several test runners - Mocha, Karma, Jest, JsTestDriver, nodeunit,... The logic used for determining what test runner is available for a given test file is based on dependencies declarations in nearest package.json file.

Jasmine testing with Phantom js

I wrote the Jasmine test for the javascript. I am trying to run the Jasmine tests using Phantomjs. I downloaded the Phantomjs from Phantomjs.org and tried running it using phantomjs.exe //path to phantom jasmine http://localhost/myJasmineTestRunner.html. Googling doesn't help me out. Can someone suggest me how to test jasmine tests using phantomjs.
Running the Tests
In order to run our jasmine test suite on the command line, all we need is:
PhantomJS
Installing PhantomJS from phantomjs.org is fairly trivial (at least on a mac).
A URL to our Jasmine test suite
We already covered jasmine test suites, so we have a URL to a jasmine test suite.
A script that loads our URL and parses the results
Fortunately, PhantomJS provides a working jasmine runner example – all we have to do is download it and use it.
Once we got these, all we have to do is run the following command:
phantomjs
It doesn’t take more than a few seconds(!) and we are provided with the test results.
This is it.
Now, lets run it with our build tool.
* For the purpose of this article, lets assume PhantomJS is installed on the system, our jasmine runner is located at /path/to/run-jasmine.js and our jasmine test suite is located at http://localhost/js/test/unit/
Source.

Making mocha "use strict" when running in node

Is there a way to make Mocha run tests in strict mode when running on node?
Normally you can enable this in node by running node --use_strict. Is there a way to do the same thing for mocha?
Add --use_strict to the mocha command.
So your command might look like this :
mocha ./test --recursive --use_strict
There is no way to pass --use_strict into mocha and this was done in purpose. Read the discussion for details.
If you really want this behaviour you could fork mocha's sources or load this npm module as a first thing in your tests.
I would just start test scripts with
'use strict';

Categories