Mocha: run tests in parallel and serial mode - mocha.js

I use mocha for running tests and mocha-teamcity-reporter as a reporter for teamcity.
I have test files that can be run in parallel. And also I have some test files that should be run one by one - in serial mode.
As I understood mocha documentation, mocha can run test files only in parallel or in serial mode. So I tried to do the following: run two mocha runs with & command in one yarn script, like this:
mocha --reporter mocha-teamcity-reporter --timeout 90000 -r ts-node/register/transpile-only src/Tests/.ts --parallel --jobs 4 & mocha --reporter mocha-teamcity-reporter --timeout 90000 -r ts-node/register/transpile-only src/Tests/seq.ts
But using this approach for some reason reporter does not work properly and TeamCity does not detect all tests that were run. Is there any way to run tests like I want with mocha and mocha-teamcity-reporter?

Okay, seems that this is the only way to do it. Mentioned issue with tests detecting was resolved in one of the recent mocha updates.

Related

Cypress run some of tests in parallel

I have done lot of research of running some tests in parallel and some in series. Still, not have any great options for doing that. We'll have 4 virtual machines to done this. All tose vm's has own docker for application with own database as well. I have few tests which need to be run at the same machine.
I'll thinking can there be given some tags or something which can be configured so that spesified tags will run on VM 1 example?
Found solution by plugin named Cypress grep, link is below. With it you can write tags to tests like this:
it('works', { tags: '#smoke' }, () => ...)
run all tests tagged #smoke
$ npx cypress run --env grepTags=#smoke
run all tests except tagged #smoke
$ npx cypress run --env grepTags=-#smoke
Install instructions and usage: https://www.npmjs.com/package/#cypress/grep
Work the way as the Robot Framework tags.

Cypress custom reporter problem with --spec flag

When I run tests via npx cypress run everything works fine, but when I want to run one or more tests via the --spec flag, I can't find this tests in the config and the reporter logic breaks, since the config doesn't changed testFiles field, if you specify the testFiles field in cypress.json or set it via the CLI npx cypress run --config testFiles='examp.spec.js' then everything works fine.
Here our cypress-reporter https://www.npmjs.com/package/#zebrunner/javascript-agent-cypress

Run cypress test without using the GUI

Is it possible to run a Cypress test without using the GUI where you can choose the test file. Currently I open it this way:
I type in CMD: node_modules/.bin/cypress open and then the GUI pops up where I can choose my test.
Is there a command which avoids that the GUI is popping up and what is the command?
You can run with command line in headed like this:
node_modules\\.bin\\cypress run --headed
this will run the tests by default in Electron browser.
And headless:
node_modules\\.bin\\cypress run
Yes, it is cypress run. It is all described in the documentation.
To run a specific file, you need to pass --spec argument, like this:
node_modules/.bin/cypress run --spec "cypress/integration/nameOfTheTest.js"

Disable Logging test results at Cypress

I run my tests in the docker container and I would not want to see the logs about the results of the tests (since I run several instances of cypress and logs are mixed). Is there any way to turn off logging?
I have read documentation but i haven't found anything.
As per this github issue: https://github.com/cypress-io/cypress/issues/2071.
That issue was resolved at the 4.9.0 release of Cypress.
You can now run your Cypress tests with the --quiet flag. e g.:
cypress run --quiet

Difference between Karma start and run Karma?

When I enter 'karma start' in the WebStorms' terminal, it opens Chrome and I can start testing, when I make some changes, it reruns the tests. But what is the difference when I type Karma start or when I click un Run Karma? Is Run Karma only for test reporters?
There are 2 console commands:
karma start
karma run
Karma start creates a karma server with the given config file and opens a browser window which connects to that server and waits for tests. You should use karma start after every change of your karma.conf.js file. The PhpStorm plugin does this automatically, by run it checks whether the config file is changed, and if so, it executes karma start before karma run.
Karma run sends your tests to the browser and runs them there. Your should use this after every change of your code or unit tests. Ofc the PhpStorm plugin does this automatically by every run.
The standard way is to run karma start and karma run as described by #inf3rno.
When running karma on CI/CD it's good to start karma, run the tests and exit. It's possible to reach using the singleRun: true option in the karma.conf.js. Check it out in the docs http://karma-runner.github.io/1.0/config/configuration-file.html.

Resources