Skip to main content
https://badge.fury.io/py/purelyjs.png https://travis-ci.org/numerodix/purelyjs.png?branch=master https://pypip.in/license/purelyjs/badge.png
  • 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

Metadata

Release files for purelyjs 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for purelyjs 0.1.4
File Size Uploaded
purelyjs-0.1.4.tar.gz 6.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for purelyjs 0.1.4
File Interpreter ABI Platform
purelyjs-0.1.4.linux-i686.tar.gz Details
purelyjs-0.1.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 25.5 kB

Release files / purelyjs-0.1.4.tar.gz

Download URL purelyjs-0.1.4.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4df65964218a91365c8b141c6954a6ff695f6661b5b151d7b62db525dcf5eba8
BLAKE2b-256 checksum
How to use checksums
fe50a8fd02aa3cff531d9c80fab94cee67cd14e79186727e6bfef82e6a32a100
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / purelyjs-0.1.4.linux-i686.tar.gz

Download URL purelyjs-0.1.4.linux-i686.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fb2eacf17a9c821c7d825ee710f123c9373de2c507458c15b790988f3436cc12
BLAKE2b-256 checksum
How to use checksums
b4bfd63712b100bdfb26753290ea9c0119a6386d219e519ea060f22068065c2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / purelyjs-0.1.4-py2.py3-none-any.whl

Download URL purelyjs-0.1.4-py2.py3-none-any.whl
Size 8.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2f36832c9f5991feecd38a97d02c39b676bcc28027f916a03a5ed1bed3ebffa1
BLAKE2b-256 checksum
How to use checksums
00cf0ec3a82e17c3dd68b75f5f23808bef801e2498923a43c26a0646a9e62328
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.4 This release

3 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page