Package detail

spritesmith-engine-test

twolfson70MIT5.1.1

Common test suite for spritesmith engines

spritesmith, test, engine

readme

spritesmith-engine-test Build Status

Common test suite for spritesmith engines

These files were written for usage with mocha

Specification version

The current repository version is built to match specification version:

2.0.0

Specification documentation can be found at:

https://github.com/twolfson/spritesmith-engine-spec/tree/2.0.0

Getting started

Install the module via: npm install spritesmith-engine-test

Create files that require and run the test suite:

test/myengine_test.js:

// Load in dependencies
var spritesmithEngineTest = require('spritesmith-engine-test');
var MyEngine = require('../lib/engine');

// Run our test suite
// DEV: This loads and define multiple `mocha` test suites
spritesmithEngineTest.run({
  engine: MyEngine,
  engineName: 'myengine'
});

Run your tests via mocha:

# Install test dependencies
npm install mocha

# Run mocha test suite
./node_modules/.bin/mocha test/
#  myengine
#    interpretting an image file
#      ✓ gathers statistics on an image file
#  ...

Documentation

spritesmith-engine-test exports the following keys its module.exports:

  • config Object - Assortment of configurations used for each test suite
    • See lib/config.js for documentation
    • Feel free to reuse these in any of your one-off tests
  • run Function - Test suite runner
    • Documentation cane be found below
  • spritesmithUtils Object - One-off utilities for our test mocha suites
    • See lib/utils/ for documentation
    • Feel free to reuse these in any of your one-off tests

run(params)

Generates a set of mocha test suites for a spritesmith engine

  • params Object - Container for test setup
    • engine Object - spritesmith engine as defined by spritesmith-engine-spec
    • engineName String - Name of engine to use in test suites
    • engineOptions Object - Optional options to pass to engine constructor
    • tests Object - Optional overrides to enable/disable tests
      • By default, all tests will run
      • Signature should be testName: boolean (e.g. {interpretPngImage: false})
      • A list of tests can be found below

Example with tests:

spritesmithEngineTest.run({
  engine: myengine,
  engineName: 'myengine',
  // Skip over rendering a GIF image
  tests: {
    renderGifCanvas: false
  }
});

Tests

Our test suite has the following tests built into it:

  • assertSpecVersion - Verify the engine has a specVersion for the corresponding specification
  • interpretPngImage - Loads a PNG image and asserts we get the correct height/width
  • interpretJpegImage - Same as interpretPngImage but for a JPEG (using format: 'jpeg')
  • interpretJpgImage - Same as interpretPngImage but for a JPEG (using format: 'jpg')
  • interpretGifImage - Same as interpretPngImage but for a GIF
  • renderPngCanvas - Loads a PNG image, renders it via the export, and asserts the image is more/less the same
  • renderJpgCanvas - Same as renderPngCanvas but for a JPG
  • renderGifCanvas - Same as renderPngCanvas but for a GIF
  • renderPngBufferVinylCanvas - Same as renderPngCanvas but uses a buffer-based Vinyl object instead of a filepath
  • renderPngStreamVinylCanvas - Same as renderPngCanvas but uses a stream-based Vinyl object instead of a filepath
  • renderPngNullVinylCanvas - Same as renderPngCanvas but uses a null-based Vinyl object instead of a filepath
  • renderMultiplePngImages - Load multiple images, place them at different spots on a canvas, and verify the placements are respected
  • renderManyPngImages - Load 500 images and render them on a canvas
    • This is to verify each engine can handle a signficant amount of images
  • interpretLargePngImage - Load an 800x600 image and assert we get the correct height/width
    • This is part of a regression we encountered in phantomjssmith

Donating

Support this project and others by twolfson via donations.

http://twolfson.com/support-me

License

Copyright (c) 2013-2014 Todd Wolfson

Licensed under the MIT license.

changelog

spritesmith-engine-test

5.1.1 - Updated dependencies to fix vulnerabilities, via @striezel in #3

5.1.0 - Moved to Node.js>=14 to fix Travis CI

5.0.1 - Moved to Node.js>=4 to fix Travis CI

5.0.0 - Upgraded to Vinyl@2 to support Gulp@4

4.0.1 - Replaced Gratipay with support me page

4.0.0 - Added support for spritesmith-engine-spec@2.0.0

3.1.0 - Added assertion for specVersion

3.0.0 - Refactored to allow enabling/disabling of single tests and expanded image tests

2.1.4 - Replaced specification content with link to spritesmith-engine-spec

2.1.3 - Added Travis CI

2.1.2 - Added twolfson-style for linting

2.1.1 - Added foundry for release

2.1.0 - Fixed hardcoded values for exporting and debugging

2.0.1 - Fixed mistake with pixel assertions

2.0.0 - Moved to mocha + utilities system for testing

1.2.1 - Corrected improper dependency listing for get-pixels

1.2.0 - Moved to get-pixels and internal image for comparing engine results

1.1.0 - Added config file (allows for png-only tests) and environment var for debugging tests

1.0.0 - Upgraded to doubleshot@2.13.1

Before 1.0.0 - See git log