Skip to main content

A super simple testing framework for javascript

Project description

https://badge.fury.io/py/purelyjs.png https://pypip.in/d/purelyjs/badge.png https://travis-ci.org/numerodix/purelyjs.png?branch=master
  • Command line test runner with minimal hassle (only needs a javascript shell like node.js/rhino/spidermonkey - no browser).

  • Small library of JUnit-style testing primitives.

Quickstart

$ pip install purelyjs
$ purelyjs

Theory

The composition of a typical Javascript application tends to be a mix of library/framework code (jQuery, Backbone, Angular.js etc) and application specific code. Frameworks provide many hooks that allow the programmer to customize their behavior, which is accomplished through callbacks.

This tight coupling between the application and the framework makes it hard to unit test the application logic (the framework is generally known to work well already, that’s typically why it was chosen). Worse still, the effects of the application are manifest through side effects: network calls are made, ui components are updated etc. Many heavy weight testing frameworks have sprung up to address this need, and they are centered around driving a browser and observing the effects (Selenium, phantomjs, etc).

Application
--------------------------------------------
|                                          |
|            Callback spaghetti            |
|         Land of the side effect          |
|                                          |
--------------------------------------------
|                                          |
|               Pure code                  |
|                                          |
--------------------------------------------

Still, almost every application needs to perform some tasks that have no dependencies on network or browsers. Things like manipulating strings, numbers, dates, arrays, custom data structures, parsing text streams etc. This code is very amenable to unit testing, because it tends to be side effect free (ie. pure).

Testing purely

The basic idea behind purely is that you split out your pure code from your side-effectful code and write tests against it using the primitives purely provides. Your stack will look like this:

Stack
--------------------------------------------
|                                          |
|                  Tests                   |
|                                          |
--------------------------------------------      -----
|                                          |        |
|                purely.js                 |        |
|    assertEqual, assertNotEqual etc...    |        |
|                                          |       test
--------------------------------------------   dependencies
|                                          |        |
|                Pure code                 |        |
|                                          |        |
--------------------------------------------      -----

Since none of this code needs a browser to run, purely can run it on a javascript engine on the command line. First it will scan your test code to find all the tests. For each test it will assemble a test module as shown below (a single file containing all the code, plus the invocation of that one test) and execute it.

Test module
--------------------------------------------      -----
|                                          |        |
|                Pure code                 |        |
|                                          |       test
--------------------------------------------      module
|                                          |        |
|                purely.js                 |        |
|    assertEqual, assertNotEqual etc...    |        V
|                                          |
--------------------------------------------
|                                          |
|                  Tests                   |
|        function testThis() {...}         |
|        function testThat() {...}         |
|                                          |
--------------------------------------------
|                                          |
|               testThis();                |
|                                          |
--------------------------------------------

Usage

Run purelyjs with command line arguments:

$ purelyjs --test test/test_asserts.js
Running 10 tests on /usr/bin/js
..........

----------------------------------------------------------------------
Ran 10 tests in 0.568s

You can also set up a purelyjs.ini file:

[purelyjs]

# will be tried in order, first to succeed will be used
interpreters =
    js
    rhino

libs =
    static/js/code.js

tests =
    static/js/test/tests.js

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

purelyjs-0.1.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

purelyjs-0.1.1-py2.py3-none-any.whl (8.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file purelyjs-0.1.1.tar.gz.

File metadata

  • Download URL: purelyjs-0.1.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for purelyjs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 90db70a4a635b3d316ff2fc53dcf0e09107eac290c84a59612021c1bcfb79940
MD5 56bf6fdc893935bda1144a6998ec5f27
BLAKE2b-256 4ae3db9ed6472e527c916519f6dc1919f95c6738934d4764a10e020dd263d723

See more details on using hashes here.

File details

Details for the file purelyjs-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for purelyjs-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fa4257563d7034e6c9bc73eb950fb4f73d30f3077b9cf7f527fe8bc178fe940f
MD5 83b9e74d331e58bd78b66c1905841450
BLAKE2b-256 876555feafb58e38d1c94ddc12d1b2170aff066c67ab325708051cd0a497bc02

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page