curran / d3-bundler-ui

A Web application for defining custom d3 builds.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make tests for bundles

curran opened this issue · comments

In order to guarantee that the bundle is being correctly generated, each module of each package should have a test that goes along with it. This test is just to make sure that the API of the module is properly exposed in the bundle. This is more of a sanity check than a rigorous functionality test (those are already present in the original packages).

As an example, the test for d3.select could be a copy of the first test case in the original select tests, but modified to work against a bundle generated with all D3 modules.

The test might look something like this:

var tape = require("tape"),
    jsdom = require("jsdom"),
    d3BundlerUI = require("../index.js");

// Generate the bundle with all modules from all D3 packages.
d3BundlerUI.generateBundle(d3BundlerUI.allModules(), function (bundle){

  // Load the bundle via Node.js require()
  fs.writeFileSync("d3-bundle-all-modules.js", bundle);
  var d3 = require("./d3-bundle-all-modules");

  // Test the modules in the bundle.
  tape("d3.select", function(test) {
    var document = global.document = jsdom.jsdom(),
        s = d3.select("body");
    test.ok(s instanceof d3.selection);
    test.equal(s._depth, 1);
    test.ok(Array.isArray(s._root));
    test.equal(s._root.length, 1);
    test.equal(s._root[0], document.body);
    test.equal(s._root._parent, undefined);
    test.equal(s._enter, null);
    test.equal(s._exit, null);
    test.end();
    delete global.document;
  });
});