testing.rst 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. Automated tests
  2. ===============
  3. Converse uses the `Karma <https://karma-runner.github.io/latest/index.html>`_ test runner and
  4. `Jasmine <https://jasmine.github.io/>`_ testing library for running tests.
  5. In addition, we use `ESlint <https://eslint.org/>`_ to run a static analysis (aka
  6. linting) of the source files and report errors.
  7. Whenever a commit is pushed to the Converse Github repo, all ESlint checks and
  8. Jasmine tests are run on `Travis CI <https://travis-ci.org/github/conversejs/converse.js>`_.
  9. Running tests
  10. -------------
  11. You can run ESlint by typing ``make eslint``. Similarly the tests can be run via ``make tests``.
  12. To run both eslint and the tests, you can use ``make check``.
  13. When running ``make test`` or ``make check``, a browser will automatically
  14. start up, open a tab at http://localhost:9876 and start running the tests.
  15. You'll see a green bar at the top of the page, and on the right inside it is a ``Debug`` button.
  16. It's often helpful to click that button and run the tests in debug mode. This
  17. way, you see better error output for failed tests.
  18. Automatically run tests on file changes
  19. ***************************************
  20. To automatically run the tests whenever you make a change to any of the
  21. Converse source code, you can run ``make watch`` in one terminal, and ``make
  22. tests`` or ``make check`` in another.
  23. ``make watch`` will build development bundles of Converse.js (in
  24. ``dist/converse.js`` and ``dist/converse.css``) and automatically rebuild them
  25. whenever a source file is modified.
  26. Similarly, Karma will make sure that the tests are re-executed when the
  27. bundle files are rebuilt.
  28. Running individual tests
  29. ************************
  30. Converse has over 400 tests, and it can take a few minutes to run through all of them.
  31. When developing on Converse, it's often preferable to have a more rapid
  32. turnaround time between editing a file and checking whether the most relevant
  33. tests have passed.
  34. Jasmine tests are described by `it` functions and the tests names are written to
  35. be read as plain English sentences that start with the word ``it``.
  36. For example:
  37. .. code-block:: javascript
  38. it("is rejected if it's an unencapsulated forwarded message",
  39. Tests are grouped by `describe` functions, and contained in spec files inside
  40. the `spec <https://github.com/jcbrand/converse.js/blob/master/spec/>`_ directory.
  41. To run only a single test, you can replace ``it(`` with ``fit(`` for the particular
  42. test that you want to run. You can also do this for multiple tests. All of them
  43. will be run whenever ``make test`` executes.
  44. To run only a group of tests, you can similarly replace ``describe(`` with ``fdescribe``.