I'm making an API for a website (this is open source you can find the repo and look by yourself here : https://github.com/PirateSeal/Operation-Green-Axe-2)
I'm making tests suites with jest and supertest and i'm using knex to connect and talk with my db.
My problem is that i can't run multiple tests suites because the first one is "locking" access to my db.
In each of my tests files I implemented the BeforeAll() and AfterAll() methods to create and teardown my db and instead of doing that for each test, i'd like to create a setup file that will run before all tests suites and after all.
I read about jest setup file but i didn't understand how to use it.
Can you help me please ?
(this is my first question here btw pls be kind :) )
Related
guys.
I have 2 folders under the Integration folder (API & UI - where I keep my API and UI spec.js - test case) and also have index.js (under support) where I keep my beforeEach().
Currently, when I run any test case from API or UI both beforeEach() runs in 1 time. But I want to run them accordingly as in the screenshot. Please advise how can I manage the file configuration.
What a purpose of save beforeEach() block into the /support/index.js ?
As I understand correct behavior for tests based on cypress - you can put beforeEach() into your spec file and the code in will run before each scenario in spec file.
Copy the beforeEach() and put into your spec files.
Here the example of cypress developers:
https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/testing-dom__select2/cypress/integration/spec.js
I use Jest with superset for testing working Koa's urls. All test placed in __test__ folder and I testing only request urls from my routes.
How can I use coverage for mark testing routes? Maybe I can use something special comments in routing source file or use some middleware for mark working routes?
Usually test coverage implies which part of code that your test imports was actually executed.
In your case it sounds like you are doing integration testing, and you want to know how many endpoints out of all endpoints are working.
If integration testing is what you really want, you could have an sdk of sorts, and then track line coverage of that. Separate your testing network requests from your integration tests.
I am having a small issue with WebStorm that I am hoping someone has experienced and solved before.
I am using WebStorm to build a angular.js app and I have it set up to use Karma to run my tests. This is fine for the most part: I have a Karma configuration setup and I can get to to run the tests or debug them with no issue.
My problem is that when I try to run a test individually by clicking on one of the test in the "Test Run" tree it goes off to a node configuration, tries to run it and fails (because its looking for js dependencies). After that I just go back to my 'karma config' and it runs through the whole of the test no problem.
Does anyone know how I can get the IDE hooked up so that I can trigger my tests from the UI?
Running tests from file right-click menu is only supported for those runners that allow executing individual tests (JSTestDriver, for example). There is currently no such possibility for Karma (WEB-13173). See the discussion at https://github.com/karma-runner/karma/issues/1235.
to run individual test files, you can have several karma configuration files with different sets of tests included. Plus you can rename individual tests/suits in the way mentioned in https://github.com/karma-runner/karma/issues/553
I have some Angular/Rails app where Rails part is just JSON API, all front works is doing by AngularJS. I've made model/controller test already using RSpec, and now I want to make some integration tests. Earlier I use request test (with Capybara, Selenium) of RSpec to test my pages/JS, but Angular is often tested by Karma/Jasmine, and I don't understand what way is preferred in Angular/Rails app. Please, give me advice, may be you share some experience with me. Thanks.
First of all you should test everything wisely. I will recommend great series of blog posts from the link below.
Since you are already familiar with RSpec, keep using it for your rails tests like models, controllers, request, etc.
For your Angularjs tests, karma and Jasmine are great choices. But Rails uses Sprockets for asset management so configuring karma can be a little bit tricky. For Rails and Jasmine I wrote a rake task. To run javascript tests you should simply run rake karma:start. I shared the link of the gist below.
The gist contains 2 files. You should put them:
karma.rake -> lib/tasks
karma.unit.js -> spec/javascripts/
Finally you should run feature/acceptance tests with Capybara.
Testing Series Intro
The Gist of Rake Task and Karma Configuration
I have got javascript tests running in visual studio using Resharper and Jasmine. It all works fine. Now however I want to run an integration test. After looking into this I just can't work out whether I should be using Karma or PhantomJs or both? And whether they link to resharper?
I then have to run all my tests on the continuous integration server using Team City. Doesn't seem like there is a clear logical way to architect front end testing from dev right through to the CI server.
For example do I really need to use Karma locally and on the CI server? I don't want to because it is not baked into visual studio and I will have to keep opening the command line and running my tests manually. This will annoy other developers and they won't bother running them I imagine. Help!
We are using Team City by the way....
Neither of these test runners are connected to Resharper in any form. I don't think there is a one and only "correct" way of running Jasmine tests in TeamCity currently - for all approaches I am aware of there is a bit of assembly required.
Personally I am using a combination of PhantomJS and the Jasmine TeamCity Reporter which works like this:
Get a list of unique test URLs from server - each of these test suites will use the Jasmine TeamCity Reporter to log results
for each test URL dynamically generate a test JS file to be used for phantom and write it to disk
use PhantomJS to run the JS file which now will load the test suite page and its test result will be written to console where they are picked up by TeamCity.