Git Product home page Git Product logo

riotjs's Introduction

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)

riotjs's People

Contributors

hojberg 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.