A headless, self-contained tool for JavaScript Testing.
JavaScript Shell
Pull request Compare This branch is 21 commits ahead, 23 commits behind trevmex:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


EnvJasmine: Jasmine test runner for EnvJS.

EnvJasmine allows you to run headless JavaScript tests. This is a fork that supports installation
as a standalone tool, and also installation via RPM for easier provisioning of RedHat/CentOS/Fedora

Creating New Specs

Add your Jasmine Spec files to the specs directory to be run.

IMPORTANT: Make sure to load the file you are planning to test as the first line of the spec file using the EnvJasmine.load("file.js"); function.

Running JavaScript tests

To run the JavaScript test suite, execute the following:


To run an individual spec file, execute the following:

bin/run_test.sh specs/[your spec file].js

In Windows you do the same by running:

bin/run_test.bat specs/[your spec file].js

Adding Dependencies

Sometimes you will have libraries that you need to load for any of your JavaScript files to work. To make sure these are loaded before your tests are run, include them in the include/dependencies.js file using the EnvJasmine.load("file.js"); function.

You can alsodefine a custom config file location to replace include/dependencies.js by calling run_test or run_all_tests with the --configFile=<config js file> option.

Based on info from:

Originally created by Jeff Avallone and Trevor Lalish-Menagh. See LICENSE for lincensing information.

See CHANGELOG for changelog information.

Current version is found in the VERSION file.

A Basic Tutorial

How to set up EnvJasmine within a basic web project. Note that this tutorial assumes you’re working within a *nix environment.

1. Create a project directory.

Create a directory in which to house your project. Let’s call this demo. After creating the directory, enter it:

mkdir demo
cd demo

2. Create a JavaScript directory.

Create a js directory inside demo to house JavaScript files:

mkdir js

3. Create a tests directory.

Create a directory in demo to house your tests. As is often customary, let’s call this directory tests:

mkdir tests

4. Integrate EnvJasmine into the project.

Clone EnvJasmine into your tests directory:

git clone https://github.com/trevmex/EnvJasmine.git tests/EnvJasmine


git clone git://github.com/trevmex/EnvJasmine.git tests/EnvJasmine

5. Create a JavaScript file.

For the purposes of this example, let’s assume we need to create some JavaScript that adds two numbers and returns their sum. Let’s create a JavaScript file to house this code:

touch js/add-numbers.js

6. Create a spec file.

Create an EnvJasmine spec file, inside of which we’ll write a test against the functionality of js/add-numbers.js:

touch tests/EnvJasmine/specs/add-numbers.spec.js

7. Load the necessary JavaScript into the test spec.

Inside tests/EnvJasmine/specs/add-numbers.spec.js, let’s load the file containing the code we’re testing, in this case js/add-numbers.js. This can be done by adding the following line:

EnvJasmine.load(EnvJasmine.jsDir + "/add-numbers.js");

8. Configure your EnvJasmine.

But what’s this EnvJasmine.jsDir business? It’s a configuration variable used to define the primary directory housing your JavaScript. It’s defined in tests/EnvJasmine/include/dependencies.js and defaults to a top-level directory of js. Change this if you’re using a different scheme:

mkdir -p tests/EnvJasmine/etc/conf
cp tests/EnvJasmine/include/dependencies.js tests/EnvJasmine/etc/conf/demo.conf.js

And edit the following line:

EnvJasmine.jsDir = EnvJasmine.rootDir + "/../../js";

in tests/EnvJasmine/etc/conf/demo.conf.js with your favourite text editor.

Please note the need for the leading slash.

9. Write the framework for a basic test.

In add-numbers.spec.js, sketch out the basic framework for a unit test against the functionality within js/add-numbers.js. Let’s assume this file contains a single function, addNumbers():

describe("addNumbers", function () {
    it("returns the sum of the two integers it's passed", function() {
        // test specifics will go here

10. Write the code testing outlining expected behavior of a unit of JavaScript.

Utilizing Jasmine syntax and matchers, write the code testing the expected behavior of addNumbers():

describe("addNumbers", function () {
    it("returns the sum of the two integers it's passed", function() {
        expect(addNumbers(1, 2)).toEqual(3);

11. Run the test.

Run the test from the command line:

./tests/EnvJasmine/bin/run_test.sh --configFile=</absolute/path/to/demo/tests/EnvJasmine/etc/conf/demo.conf.js> specs/add-numbers.spec.js

Note that the above command will run just the add-numbers.spec.js code.

Also note that at this stage, the test should fail as we have not yet written the addNumbers() function.

12. Write your JavaScript

Write just enough code in js/add-numbers.js to make the test pass:

function addNumbers(a, b) {
    return a + b;

13. Run the test again.

Run the test again and confirm that it passes:

./tests/EnvJasmine/bin/run_test.sh --configFile=</absolute/path/to/demo/tests/EnvJasmine/etc/conf/demo.conf.js> specs/add-numbers.spec.js

That’s it! For more help on Jasmine docs at https://github.com/pivotal/jasmine/wiki

Please contact Trevor Lalish-Menagh through github (https://github.com/trevmex) with any defects or feature requests!

Box UK modifications

Running for any project

Use bin/jasmine-test.sh in your project. My default, it will run all tests in “spec/*.spec.js” and will
use “src” to look up source code. You can override these – see the file itself for details

Installing for standalone use

make a file, /usr/bin/jasmine-test, that contains something like:

/opt/BoxUK/jasmine/EnvJasGav/bin/jasmine-test.sh $@

(change the path to point to wherever jasmine-test.sh is on your system)

Make sure it’s executable (e.g. chmod a+x /usr/bin/jasmine-test), then you can
have an ant task like:

RPM build and installation

Building the RPM

A helper script, “rpmbuild/builder.sh”, might work for you, YMMV.

Installing the RPM

  1. Make sure it’s not installed, remove it if it is
    yes | sudo yum remove envjasmine
  2. Install it. Version numbers may vary.
    yes | sudo yum install —nogpgcheck envjasmine-1-1.noarch.rpm
  3. Have a quick look at the directory tree. Optional. Requires tree to be
  4. installed.
    tree /opt/envjasmine

Using the RPM version

Add /opt/envjasmine/bin to your path. Then, you can do something like:

jasmine-test.sh /vagrant/kanbanise-redmine/src /vagrant/kanbanise-redmine/spec/*.spec.js