[0] | 1 | Python envjasmine wrapper
|
---|
| 2 | =========================
|
---|
| 3 |
|
---|
| 4 | This is a thin python wrapper around the envjasmine_ JavaScript
|
---|
| 5 | testing framework.
|
---|
| 6 |
|
---|
[8] | 7 |
|
---|
| 8 | .. contents::
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | Installation
|
---|
| 12 | ------------
|
---|
| 13 |
|
---|
[24] | 14 | You can install pyenvjasmine using pip_::
|
---|
[8] | 15 |
|
---|
| 16 | pip install pyenvjasmine
|
---|
| 17 |
|
---|
[47] | 18 | Or you can grab the latest sources using Mercurial_ from https://code.codigo23.net/hg/pyenvjasmine::
|
---|
| 19 |
|
---|
| 20 | hg clone https://code.codigo23.net/hg/pyenvjasmine
|
---|
| 21 |
|
---|
| 22 | and install it from there::
|
---|
[8] | 23 |
|
---|
| 24 | python setup.py install
|
---|
| 25 |
|
---|
| 26 | Also, you can use it directly from the sources directory, in *development mode*
|
---|
| 27 | (useful if you want to contribute to the project)::
|
---|
| 28 |
|
---|
[21] | 29 | pip install -e .
|
---|
[8] | 30 |
|
---|
| 31 | .. note::
|
---|
| 32 |
|
---|
| 33 | More about the *development mode* here:
|
---|
| 34 |
|
---|
| 35 | https://packaging.python.org/en/latest/distributing.html#working-in-development-mode
|
---|
[0] | 36 |
|
---|
[40] | 37 | .. warning::
|
---|
| 38 |
|
---|
| 39 | Starting with version **0.3.0**, pyenvjasmine has support to run tests with
|
---|
| 40 | different browsers/engines. The headless browser rhino is included with
|
---|
| 41 | pyenvjasmine, but in order to use the other engines, you have to install the
|
---|
| 42 | needed browser(s).
|
---|
| 43 |
|
---|
| 44 | Right now, only phantomjs_ is supported, so ensure you have it installed if
|
---|
| 45 | you want to use that browser/engine to run tests on. **Required if you want
|
---|
| 46 | to run tests on jasmine 3.x** (also required to run pyenvjasmine's own
|
---|
| 47 | tests).
|
---|
| 48 |
|
---|
[0] | 49 |
|
---|
[11] | 50 | Running pyenvjasmine tests
|
---|
| 51 | --------------------------
|
---|
[0] | 52 |
|
---|
[11] | 53 | To run the tests on this code here (as opposed to *your* JavaScript code you
|
---|
[40] | 54 | want to test), install pyenvjasmine (and phantomjs) and then run::
|
---|
[0] | 55 |
|
---|
[26] | 56 | py.test
|
---|
[8] | 57 |
|
---|
[0] | 58 |
|
---|
| 59 | Run your own tests
|
---|
| 60 | ------------------
|
---|
| 61 |
|
---|
[11] | 62 | The easiest way is to put your "specs" (JavaScript tests) into some directory
|
---|
| 63 | in your code, then in your python tests, add a new TestCase with just one test
|
---|
| 64 | that runs all your JavaScript tests.
|
---|
[0] | 65 |
|
---|
[11] | 66 | The simplest solution is to set capture_output to False, so you see the output
|
---|
| 67 | from the js tests on the console. Something like this::
|
---|
[0] | 68 |
|
---|
[26] | 69 | import pytest
|
---|
[24] | 70 | from pyenvjasmine.runner import Runner
|
---|
[0] | 71 |
|
---|
[26] | 72 | class TestJavaScript(object):
|
---|
[0] | 73 | def test_my_javascript(self):
|
---|
[24] | 74 | runner = Runner(
|
---|
| 75 | testdir='/path/to/my/testdir',
|
---|
[40] | 76 | configfile='relative/path/to/configfile',
|
---|
| 77 | testing_environment='phantomjs')
|
---|
[26] | 78 | success, stdout = runner.run()
|
---|
| 79 | # assert on success, will be true if tests passed, False if any
|
---|
| 80 | # test failed
|
---|
[40] | 81 | assert success, "One or more javascript tests have failed"
|
---|
[26] | 82 | # you can inspect stdout if you want to get more info, but it
|
---|
| 83 | # will be printed to the console stdout anyway
|
---|
| 84 | assert b'Total: 120' in stdout
|
---|
[0] | 85 |
|
---|
[40] | 86 | In this example, the *phantomjs* browse/engine is used, replace that with
|
---|
| 87 | *rhino* to run tests on rhino + jasmine 1.x.
|
---|
| 88 |
|
---|
| 89 | .. note::
|
---|
| 90 |
|
---|
| 91 | *phantomjs* is the preferred browser/engine, so it is what pyenvjasmine
|
---|
| 92 | will use as a default if you don't set *testing_environment* when creating
|
---|
| 93 | a new *Runner* instance.
|
---|
[8] | 94 |
|
---|
[47] | 95 |
|
---|
| 96 | .. _Mercurial: https://www.mercurial-scm.org
|
---|
[8] | 97 | .. _envjasmine : https://github.com/trevmex/EnvJasmine
|
---|
| 98 | .. _pip: http://www.pip-installer.org/en/latest/index.html
|
---|
| 99 | .. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall
|
---|
[40] | 100 | .. _phantomjs: http://phantomjs.org
|
---|