• Stars
    star
    137
  • Rank 265,249 (Top 6 %)
  • Language
    JavaScript
  • Created almost 15 years ago
  • Updated almost 14 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript unit tests.

This is a JavaScript implementation of Riot.

It will run in a browser, Rhino, or Node.

Example

Tests look like this:

Riot.run(function() {
  context('basic riot functionality', function() {
    given('some simple equality tests', function() {
      asserts('a simple truth test should return true', true).isTrue();
      asserts('isNull is null', null).isNull();
    });

    given('another context', function() {
      asserts('equals should compare strings as expected', 'test string').equals('test string');
    });

    given('a context concerned with functions', function() {
      asserts('asserts() should allow functions to be compared', function() {
        return 'test string';
      }).equals('test string');
    });
  });

  given('yet another context', function() {
    asserts('equals should compare strings as expected', 'test string').equals('test string');
  });
});

There are a few aliases to make tests (and output) read more naturally:

  • context: given — Given will add “Given…” to the title in the test output
  • asserts: should

Assertions

  • equals – for example, asserts('description').equals('value')
  • matches – matches a regex
  • typeOf – aliased to isTypeOf, kindOf
  • isNull
  • isTrue
  • raises

Riot.run

Riot.run(function() { // your tests }); just adds your tests to window.onload. If there’s already an onload handler it won’t add itself. If there’s no window it will just run the tests.

Riot.load() can be used to load required scripts in a browser or interpreter. Riot.require() only loads files once by keeping a record of files that have already been loaded.

It can also be called with no parameters to run tests defined with Riot.context. This can be used to create a set of files with tests inside a Riot.context for each file

Packaging

Packaged as a RubyGem usable via XPCOMCore-RubyGemsriotjs-xpcc.

Writing a test for a browser AND interpreter

My current pattern looks like this:

var Riot;
if (typeof load !== 'undefined') {
  load('riot.js');
} else if (typeof require !== 'undefined') {
  Riot = require('./riot').Riot;
}

Riot.require('../turing.core.js');
Riot.require('../turing.oo.js');
Riot.require('fixtures/example_classes.js');  

Riot.context('turing.oo.js', function() {
  // Tests go here
});

Riot.run();
<!DOCTYPE html>
<html>
  <head>
    <title>Riot</title>
    <style>
p.pass { color: green; font-weight: bold; margin: 0 }
p.fail { color: red; font-weight: bold; margin: 0 }
#test-results ul { margin-bottom: 1em }
    </style>
    <script type="text/javascript" src="riot.js"></script>
    <script type="text/javascript" src="core_test.js"></script>
    <script type="text/javascript" src="oo_test.js"></script>
  </head>
  <body>
    <div id="test-results"></div>
  </body>
</html>

Note:

  • load() is no-op’d in browsers if it doesn’t exist by Riot
  • Riot.run() will only run once, so you can include multiple Riot test files
  • Specifying Riot.run() at the end of each test file lets you run that file with js Riot.run() in the console

Contributors

  • ac94 (Aron Carroll)
  • bgerrissen (Ben Gerrissen)

More Repositories

1

nodepad

A notepad app written with Node
JavaScript
750
star
2

ircd.js

A Node ircd (IRC daemon)
JavaScript
528
star
3

turing.js

DailyJS's JavaScript framework
JavaScript
309
star
4

ico

JavaScript graph library based on Raphael
JavaScript
223
star
5

jschat

JSON-based chat that has web and console clients, and a server
JavaScript
205
star
6

nodeinpractice

The source code for the book Node.js in Practice (ISBN: 9781617290930)
JavaScript
198
star
7

dailyjs-backbone-tutorial

JavaScript
182
star
8

nodejsinaction

The Node.js in Action (Manning) code repository
JavaScript
165
star
9

djsreader

A tutorial app for AngularJS, Yeoman, and some of their friends
JavaScript
101
star
10

usevim

A blog all about Vim
CSS
70
star
11

pop

A static site and blog generator
JavaScript
62
star
12

wingman

A to-do list app that can easily be deployed to Heroku, built with Rails 3, MongoDB, OpenID
JavaScript
60
star
13

javascript-dsl-examples

High-level examples of how to make DSLs in JavaScript
JavaScript
25
star
14

select

A JavaScript database library
JavaScript
24
star
15

zalgo

Ḫ̷̲̫̰̯̭̀̂̑̈ͅĚ̥̖̩̘̱͔͈͈ͬ̚ ̦̦͖̲̀ͦ͂C̜͓̲̹͐̔ͭ̏Oͭ͛͂̋ͭͬͬ͆͏̺͓̰͚͠ͅM̢͉̼̖͍̊̕Ḛ̭̭͗̉̀̆ͬ̐ͪ̒S͉̪͂͌̄
Ruby
23
star
16

dailyjs-survey

A survey for JavaScript programmers
18
star
17

dailyjs-contact-form-tutorial

JavaScript
16
star
18

dystopian_index

Rails plugin for Tokyo Dystopia
Ruby
16
star
19

securetrading-rails

Secure Trading Rails plugin
12
star
20

dailyjs-cloudinary-gallery

DailyJS Cloudinary tutorial
JavaScript
10
star
21

async-testing-tutorial

JavaScript
10
star
22

turing-test.js

DailyJS.com unit test tutorial
JavaScript
9
star
23

dailyjs-heroku-postgres

Heroku PostgreSQL example
JavaScript
9
star
24

stextile

A simple textile parser
JavaScript
9
star
25

jadedown

Combining Jade and Markdown
JavaScript
9
star
26

sirtet

JavaScript
8
star
27

captor

A GUI for Capistrano
Ruby
7
star
28

twitter-scheduler

Schedules posts to Twitter
Ruby
7
star
29

twitter2delicious

Imports links to your Delicious account from Twitter
Ruby
7
star
30

through

Small geolocation web app
Ruby
6
star
31

snake-shoes

A snake game written with Ruby and Shoes
6
star
32

conway-js

Conway's game of life made with Processing.js
JavaScript
5
star
33

closure

A little JavaScript OO and functional library
JavaScript
5
star
34

ssbx

Unified API for single site browsers
JavaScript
5
star
35

stateaware

A rails application that aims to centralise government data collection through APIs and screen scraping
Ruby
5
star
36

Azukilib

A collection of JavaScript classes, images and CSS for building web applications
JavaScript
5
star
37

alexyoung.org

Alex's blog
HTML
5
star
38

fire.js

Processing.js fire example
4
star
39

rsyncdiff

Makes it easier to visualize changes between local and remote stuff
4
star
40

pop-disqus

Pop Disqus plugin
JavaScript
4
star
41

pop-gallery

A gallery for Pop
JavaScript
4
star
42

weather

weather experiments
JavaScript
4
star
43

gobbler-js

4
star
44

http-wizard

An app for making HTTP requests
JavaScript
4
star
45

basecamp-mobile

An open source Rails application that wraps around Basecamp to provide a mobile-friendly interface
Ruby
4
star
46

gallery

A rails sample application used in a Linux Format tutorial
3
star
47

gitlocker

Sinatra application that stores versions of things in Git repositories
Ruby
3
star
48

jsmon

Tiny app that can be used to monitor remote services
Ruby
3
star
49

minesweeper

A basic Swift SpriteKit game for Mac OS
Swift
3
star
50

tunnel-p5r

Tunnel effect written with Ruby Processing
3
star
51

react-create-permitted-elements

Create React elements based on HTML strings
JavaScript
3
star
52

dailyjs-bot

IRC bot for freenode.net #dailyjs
JavaScript
3
star
53

twitterircbot

An IRC bot that allows you to access your twitter accounts from your favourite IRC client
Ruby
3
star
54

growlexample

An Objective-C example on how to use Growl
Objective-C
3
star
55

loom-exceptions-rails-plugin

Add Loom exception reporting to your Rails apps
Ruby
2
star
56

node-unix-slides

Slides about Node and Unix, powered by bash
Shell
2
star
57

gitlocker-client

A client library for Gitlocker, including a Rails ActiveRecord plugin
Ruby
2
star
58

shoes-ball

Bouncing balls examples for Shoes
Ruby
2
star
59

hackerstats

Uses JSON APIs to generate a developer profile
2
star
60

istype.js

JavaScript
2
star
61

gobbler

Displays a real time twitter stream
JavaScript
2
star
62

fire-p5r

A fire algorithm in Ruby Processing
2
star
63

mtail

tail multiple files
JavaScript
2
star
64

depwhack

Compares dependencies between a local and remote rails project
1
star
65

jackdaw

Clojure GUI apps
Clojure
1
star
66

notes

Programming notes
1
star
67

cojor

Colourful strings in Clojure
1
star
68

xpcomcore

XPCOM "Core" library emulating many of the features available in the standard Ruby one.
JavaScript
1
star
69

alexyoung.github.com

A page for me
1
star
70

plants.js

A Node test runner
JavaScript
1
star
71

kite

An experiment from back in 2007 to make a mobile search site
Ruby
1
star
72

helicoid_blog

Helicoid's Blog
Ruby
1
star
73

pop-pages

Pop blog
JavaScript
1
star
74

tiktrac-widget

A widget for Tiktrac.com
JavaScript
1
star