Skip to content

Testrunner framework using RequireJS, Mocha (Chai) and Blanket.js

License

Notifications You must be signed in to change notification settings

easytobook/sugarspoon

 
 

Repository files navigation

sugarspoon

Sugar-coated testing framework built around RequireJS, Mocha, Chai and Blanket.js

Features

  • Easy configuration of Blanket.js with Mocha and AMD (based on the mochablanket adapter provided by Blanket.js)
  • Toggle Blanket.js coverage report with automatic browser reload
  • Persisted test settings ("mocha report", "coverage report" and "show fixtures") across reloads (using HTML5 local storage)
  • Base test utility functions for writing clean Mocha tests with less code

Compared to the standard Mocha HTML output, Sugarspoon adds a settings bar at the bottom:

Files names in the coverage report can be clicked to show line-based coverage (this is standard Blanket.js):

Usage

Changelog

0.4.0-alpha.1

  • The @utils.view.create() function exposed by viewTest() now supports a "root" option (takes a jQuery selector string) to allow binding to a nested view element (when combined with the "html" option), while still getting the entire HTML structure to be cleaned up automatically in the after().

0.3.6

  • ... and actually compiled v0.3.5 to JavaScript. It must be Friday.

0.3.5

  • Fix typo that broke @util.view.create()

0.3.4

  • Fixed error in ViewTestManager.setClass() if no "render" method is defined on your class.
  • Fixed error (usually thrown from afterEach()) if view class has no "remove" method.
  • Expanded the functionality of @util.view.create(): if no "el" is specified, it is automatically created as first child in the Fixtures container div. If it is specified, but false (e.g. {el: null}), it will rely the Backbone View to create the view element itself, after which it will append the view.$el to the Fixtures container div.

0.3.3

  • TestManager now has an autoResetSpies property (defaults to true). If set to false, you can reset the Sinon spies (created through the @sandbox) yourself using @testManager.resetSandboxSpies().

0.3.2

  • Add support for grunt-blanket-mocha for getting test coverage output on the command-line.
  • The blanketOptions passed to the TestRunner can now be a function, to allow for the grunt-blanket-mocha reporter option to be set only if running in PhantomJS (see the example directory).
  • Refactored the Gruntfile and TestRunner.

0.3.1

  • Moved many bower dependencies from dev-only dependencies to the normal "dependencies" list, since you will actually need them to use Sugarspoon.
  • Extensively updated documentation
  • Avoided loading the regular Mocha testrunner when using the Blanket coverage runner

0.3.0

  • Added baseTest(), viewTest(), modelTest() and collectionTest() utility functions, along with unit tests for their functionality.
  • Added a special meta/sanitycheck test suite to for checking left-behind properties on the Mocha test context.

0.2.2

  • Fix leftbehind loadNpmTasks calls in Gruntfile
  • Renamed adapters and runners directories to adapter and runner

0.2.1

  • Fix semver tag for bower

0.2.0

  • Mocha is no longer loaded using RequireJS – it should be loaded through a regular script tag instead. This is for compatibility with grunt-mocha
  • The API of the TestRunner.run() has changed; instead of passing the actual modules to run, you should now pass a list of module names to be loaded (using RequireJS). The TestRunner now makes sure to execute the test suites in order. Note that you still have to make sure to return a function from the test module instead of the direct call to describe().
  • Removed default Blanket filter in the CoverageRunner. Configuration options for Blanket can now be passed to the TestRunner as a blanketOptions object. The coverage option on the TestRunner has been removed.
  • Added .editorconfig and coffeelint for syntax checking.
  • Changed Sugarspoon source code from 4 spaces to 2 spaces.

0.1.1

  • More flexible jQuery dependency in bower.json; any 2.x version should be fine.

0.1.0

  • First public release; mostly to be considered as proof-of-concept

Background & credits

Sugarspoon started as part of the Goeie Jongens HTML5 toolkit and was further developed for Easytobook.com.

I wanted to unit test my JavaScript code and optionally have coverage reporting. Although Blanket.js has some separate examples of usage with AMD/RequireJS and Mocha, I found it non-trivial to get the combination to work.

Also, since adding Blanket.js introduces quite a bit of overhead (feels about 2x slower with coverage reporting enabled), I wanted a way to quickly enable or disable coverage in the Mocha web UI.

While I was at it, I also added some extra configuration options to show/hide the detailed Mocha output itself, as well as some very simple HTML fixtures management (Backbone view elements).

Finally, recognizing that the shared testing context in Mocha tests can lead to undesired side-effects between tests, several base test utility functions were added to help namespace data and behavior on the test context and clean them up automatically.

About

Testrunner framework using RequireJS, Mocha (Chai) and Blanket.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 58.8%
  • CoffeeScript 37.0%
  • CSS 3.5%
  • Ruby 0.7%