Skip to content
Christoph Burgmer edited this page May 7, 2014 · 19 revisions

API

The API of CSS Critic. Throughout the 0.x releases this API is subject to change (to allow us to move quickly). If you need stability, shout out loud enough.

csscritic.add(testCase)
  • Adds a test case to be executed, with testCase being an object of key/value pairs with
    • url link to the test case HTML document,
    • hover a selector matching a single element on the page that should receive a :hover effect,
    • active a selector matching a single element on the page that should receive a :active effect.
  • Optionally the url can be passed in directly if no other options are needed.
csscritic.addReporter(reporter)
  • Adds a reporter instance for reporting test results.
csscritic.execute()
  • Executes all test cases.
csscritic.BasicHTMLReporter()
  • A reporter that reports test results in the browser

Reporter API

The following interface can be implemented for custom reporters:

reporter.reportComparisonStarting(startingComparison, callback)
  • Called when a test case is starting to be evaluated with startingComparison being an object of key/value pairs with
    • testCase the test case as passed to csscritic.add().
  • The callback needs to be called when the reporter is finished processing.
reporter.reportComparison(comparison, callback)
  • Called when a test case has been evaluated with comparison being an object of key/value pairs with
    • status the result of the test (one out of passed, failed, referenceMissing, error),
    • testCase the test case as passed to csscritic.add(),
    • pageImage the image of the rendered page (if exists),
    • referenceImage the reference image (if exists),
    • renderErrors a list of error messages from rendering (if any),
    • resizePageImage(width, height, callback) a method to resize the rendered page (if exists),
    • acceptPage() a method to accept the rendered page as new reference (is exists).
  • The callback needs to be called when the reporter is finished processing.
reporter.report(result, callback)
  • Called when the test suite has run with result containing key/value pairs with
    • success true if all test passed, false otherwise.
  • The callback needs to be called when the reporter is finished processing.
Clone this wiki locally