broccoli-fixture
Fixture testing helpers for Broccoli
Last updated 3 years ago by joliss .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install broccoli-fixture 
SYNC missed versions from official npm registry.

Broccoli Fixture Helpers

Build Status

This package is useful for testing Broccoli plugins without interacting with the file system. It lets you turn fixturify objects into Broccoli nodes, and build Broccoli nodes back into fixturify objects.

Usage

Node: Fixture object to Broccoli node

Create a Broccoli source node whose contents are created by fixturify rather than coming from the file system:

var fixture = require('broccoli-fixture');

var inputFixture = {
  'foo.txt': 'foo.txt contents',
  'subdir': {
    'bar.txt': 'bar.txt contents'
  }
};

var node = new fixture.Node(inputFixture);

build: Broccoli node to fixture object

fixture.build(node)
  .then(function(outputFixture) {
    // outputFixture deep-equals
    // {
    //   'foo.txt': 'foo.txt contents',
    //   'subdir': {
    //     'bar.txt': 'bar.txt contents'
    //   }
    // }
  });

build creates a builder behind the scenes, and cleans up automatically. Do not call it more than once on the same node.

Chai example

If you use the Chai assertion library, your test code might look like this:

return fixture.build(node)
  .then(function(fixture) {
    expect(fixture).to.deep.equal({
      'foo.txt': 'foo.txt contents',
      'subdir': {
        'bar.txt': 'bar.txt contents'
      }
    })
  });

With chai-as-promised (eventually), it's even more concise:

return expect(fixture.build(node)).to.eventually.deep.equal({
  'foo.txt': 'foo.txt contents',
  'subdir': {
    'bar.txt': 'bar.txt contents'
  }
});

Builder: Building repeatedly

The build function builds only once. If you need to build repeatedly, for example to test caching logic, use the fixture.Builder class. It's used just like a regular Broccoli Builder, but the build method returns a promise to a fixturify object.

var fixtureBuilder = new fixture.Builder(node);

fixtureBuilder.build()
  .then(function(fixture) {
    // fixture is { 'foo.txt': ... }

    // Build again
    return fixtureBuilder.build();
  })
  .then(function(fixture) {
    // fixture is { 'foo.txt': ... }
  })
  .finally(function() {
    return fixtureBuilder.cleanup();
  });

See also

This package brings in Broccoli core as a dependency, so it's perhaps too heavy to use in "production" build code. If you only need fixture.Node, you can use the lightweight broccoli-fixturify. fixture.Node is simply an alias for broccoli-fixturify's Fixturify class.

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

2 Versions

  • 1.0.0                                ...           3 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (3)
Dev Dependencies (3)

Copyright 2014 - 2016 © taobao.org |