Git Product home page Git Product logo

envjasmine's Introduction

EnvJasmine: Jasmine test runner for EnvJS.

EnvJasmine allows you to run headless JavaScript tests.

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:

bin/run_all_tests.sh

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_all_tests.bat
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

or

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

Code Coverage

See lib/jscover/README.textile

EnvJasmine as a Ruby gem

EnvJasmine can also be compiled to a Ruby gem.

How to build and install the EnvJasmine gem

git clone git://github.com/trevmex/EnvJasmine.git cd EnvJasmine gem build EnvJasmine.gemspec gem install EnvJasmine-1.7.1.gem

Using the EnvJasmine Ruby gem

Note that, when used as a Ruby gem, EnvJasmine requires a few command line arguments be specified.

Here is a Ruby usage example:

envjs_run_test —configFile=‘some_spec_helper.js’ —testDir=‘specs’ —rootDir=‘some_project’

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

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

envjasmine's People

Contributors

andrewlarkin avatar dancrumb avatar dannyjf avatar die-tech avatar jakul avatar javallone avatar josephruscio avatar lolindrath avatar mdb avatar mortonfox avatar simpsonjulian avatar toddself avatar trevmex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

envjasmine's Issues

Tutorial errors

Hi, I'm just getting started with EnvJasmine, and after following the tutorial, I get the following error:

➜ demo ./tests/bin/run_test.sh specs/add-numbers.spec.js
[ Envjs/1.6 (Rhino; U; Linux i386 3.0.0-sabayon; en-US; rv:1.7.0.rc2) Resig/20070309 PilotFish/1.2.13 ]
js: "/home/dori/Projects/demo/tests/specs/add-numbers.spec.js", line 61655: uncaught JavaScript runtime exception: TypeError: Cannot call method "close" of undefined
at /home/dori/Projects/demo/tests/specs/add-numbers.spec.js:61655

I get this error all the time, and don't really understand what's going on here. Any help is much appreciated, thanks in advance !

Best place to discuss EnvJasmine?

Hey, trevmex.

Just wondering where is the best place to discuss EnvJasmine. The Jasmine Google Group? here? your blog? somewhere else?

-Ali

jasmine-jquery fixtures

Do you have any working examples of using jasmine-jquery's fixture capability? I can't seem to get them to work in my project. I've tried to calling readFixtures and loadFixtures, but it comes up empty (no errors).

Am I missing something or is the problem on my side?

improve time between test runs

EnvJasmine is AWESOME! The Maven integration is great! However, each run takes ~5 seconds to load Rhino w/Envjs. I'm trying to get into a rhythm of testing every change and the ~5 second delay is non-optimal . I'm not sure what the simplest/best solution is, but it seems like it might be possible to run Rhino in an interactive mode, so all a developer needs to do (in this mode) is re-run test script(s). Ideally we could preserve the awesomeness of command line unit tests and improve the time between manually executed test runs.

Fix dependency injection

Currently EnvJasmine has static versions of external libraries.

Add a way to make updating these libraries easier. (ala Maven or SBT)

Code Coverage

Are there plans to integrate code coverage within EnvJasmine?

DOM doesn't seem to be loading...

I'm trying to do some testing with appending elements to a DOM.

I edited envjasmine.html to contain a rudimentary skeleton of a webpage (added html, head and body tags), but whenever I try something as simple as:

console.log(document.getElementsByTagName('body')[0].tagName);

I get 'undefined' back.

Is it supposed to load that html file as the page to manipulate? Or how do I give EnvJS a DOM for it to play on?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.