[0] | 1 | Python envjasmine wrapper
|
---|
| 2 | =========================
|
---|
| 3 |
|
---|
| 4 | This is a thin python wrapper around the envjasmine_ JavaScript
|
---|
| 5 | testing framework.
|
---|
| 6 |
|
---|
| 7 | .. _envjasmine : https://github.com/trevmex/EnvJasmine
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | Running the tests of this python module:
|
---|
| 11 | ----------------------------------------
|
---|
| 12 |
|
---|
| 13 | To run the tests on this code here (as opposed to *your* JavaScript
|
---|
| 14 | code you want to test), install this into a virtualenv, install
|
---|
| 15 | nose and maybe coverage in that virtualenv and then run::
|
---|
| 16 |
|
---|
| 17 | nosetests --cover-package=pyenvjasmine --cover-erase \
|
---|
| 18 | --with-coverage --with-doctest $*
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | Run your own tests
|
---|
| 22 | ------------------
|
---|
| 23 |
|
---|
| 24 | The easiest way is to put your "specs" (JavaScript tests) into
|
---|
| 25 | some directory in your code, then in your python tests, add a new
|
---|
| 26 | TestCase with just one test that runs all your JavaScript tests.
|
---|
| 27 |
|
---|
| 28 | The simplest solution is to set capture_output to False, so you see
|
---|
| 29 | the output from the js tests on the console. Something like this::
|
---|
| 30 |
|
---|
| 31 | import unittest
|
---|
| 32 | from pyenvjasmine.runner import TestRunner
|
---|
| 33 |
|
---|
| 34 | class JavaScriptTests(unittest.TestCase):
|
---|
| 35 | def test_my_javascript(self):
|
---|
| 36 | runner = TestRunner(
|
---|
| 37 | testdir='/path/to/my/testdir',
|
---|
| 38 | configfile='relative/path/to/configfile')
|
---|
| 39 | runner.run(capture_output=False)
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | If you want a more integrated
|
---|
| 43 | test control, you could set capture_output to True, then parse the test
|
---|
| 44 | output that is returned from the run() method, with something like this::
|
---|
| 45 |
|
---|
| 46 | def test_my_javascript_no_output(self):
|
---|
| 47 | runner = TestRunner(
|
---|
| 48 | testdir='/path/to/my/testdir',
|
---|
| 49 | configfile='relative/path/to/configfile')
|
---|
| 50 | res = runner.run(capture_output=True)
|
---|
| 51 | lines = res.splitlines()
|
---|
| 52 | self.assertTrue('Failed: 0' in lines)
|
---|
| 53 |
|
---|