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