Git Product home page Git Product logo

djamocha's Introduction

Djamocha

Integrating Django and Mocha for great good.

But how?

Djamocha, lovingly named after a sort-of-gross-but-sometimes-appealing beverage from Arby's, provides a new management command: djamochatest and a metaclass DSL for defining tests.

How does it work?

  • Djamocha is designed to run a single browser against the entire test suite at a time, automatically.

Djamocha looks for subclasses of djamocha.Test using the same process that manage.py test looks for unit tests. Running manage.py djamochatest will run manage.py testserver in the background, and tell you to hit http://localhost:8000/idle/. When you do so, it will automatically open up a popup that cycles through all of your Djamocha test cases. When it finishes, your command line program will exit with the number of failures as its exit code. If you wish to run again, assuming your browser is still on the idle page, you can simply rerun the management command.

While a test suite is running, it assumes full control over the URL structure of your Django app -- you may provide a link to a urls.py, a patterns object, or nothing at all in your test -- and stub XHR-based views this way.

Djamocha automatically runs a static server that provides your Media, excluding your tests.

Your tests are pulled from a js directory alongside the test file containing the unit test, which allows you to keep your JavaScript tests separate from your static media.

The DSL

The python side of things:

# myapp/tests/jstests.py

import djamocha

class JSTest(djamocha.Test):
    # the media to be tested
    class Media:
        css = {}
        js = []

    # the routes that will be available while this 
    # test case is running
    routes = 'routes.for.my.app' 

    # the tests to run against that media
    tests = ['some.test.js']

You may define as many of these as you like in a single file.

routes accepts a string (to import) or a patterns object. You may use this to stub out XHR requests (or perform full stack testing -- up to you!)

tests is a list of JavaScript files containing Mocha test suites to pull from the current test's adjacent js directory. You have access to jQuery, suite, test, and assert (patterned off of Node's assert module).

A look at our JavaScript:

// myapp/tests/js/some.test.js

suite("test", function() {
  test("hello world", function() {
    assert.equal(2, 1 + 1)
  })
})

LICENSE

new BSD

djamocha's People

Contributors

chrisdickinson avatar mortonfox avatar

Watchers

James Cloos avatar

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.