(function() {

  /* globals require, describe, it, expect, console */

  'use strict';

  try {

    var localdocument;
    var locald3;
    try {
      localdocument = document;
      locald3 = d3;
    } catch (e) {
      localdocument = require("jsdom").jsdom("<html><head></head><body></body></html>");
      locald3 = require("../src/d3.layout.cloud");
    }
    // window = localdocument.createWindow();
    // navigator = window.navigator;
    // CSSStyleDeclaration = window.CSSStyleDeclaration;

    describe('d3.layout.cloud', function() {

      it('should create an svg', function() {

        var w = 960 * 1,
          h = 600 * 1;

        var layout = locald3.layout.cloud()
          .padding(0)
          .size([w, h])
          .font("Impact")
          .text(function(d) {
            return d.key;
          })
          .on("end", draw);

        var start = +new Date();

        for (var i = 0; i < 2; i++) {
          parseText("this is a small cloud");
        }

        function parseText(text) {
          var tags = {};
          text.split(/\s+/g).forEach(function(word) {
            word = word.replace(/[^A-Za-z0-9]/g, "");
            if (word.length <= 3) return;
            tags[word] = (tags[word] || 0) + 1;
          });
          tags = locald3.entries(tags).sort(function(a, b) {
            return b.value - a.value;
          }).slice(0, 500);
          var min = +tags[tags.length - 1].value || 1,
            max = +tags[0].value;
          layout.fontSize(function(d) {
            return min + (d - min) / (max - min);
          }).words(tags).start();
        }

        function draw() {
          console.log(+new Date() - start);
        }

        expect(localdocument).toBeDefined();
        expect(localdocument.getElementsByTagName('svg')).toBeDefined();
        expect(localdocument.getElementsByTagName('svg').length).toEqual(' ');
      });

    });


  } catch (e) {
    console.log(e);
    console.log(e, e.stack);
  }

})();
@@ -63,17 +63,16 @@
 sole */%0A
-%0A
   'use s
@@ -563,21 +563,31 @@
 uld 
-create an svg
+parse a text into words
 ', f
@@ -611,16 +611,35 @@
     var 
+endTime,%0A          
 w = 960 
@@ -899,16 +899,17 @@
 r start 
+ 
 = +new D
@@ -1656,24 +1656,57 @@
 on draw() %7B%0A
+          endTime = +new Date();%0A
           co
@@ -1715,16 +1715,24 @@
 ole.log(
+%22Time%22, 
 +new Dat
@@ -1748,32 +1748,198 @@
 rt);%0A        %7D%0A%0A
+        expect(start).toBeDefined();%0A        expect(endTime).toBeDefined();%0A%0A        expect(layout).toBeDefined();%0A        expect(layout.words().length).toEqual(3);%0A%0A
         expect(l
@@ -2117,11 +2117,9 @@
 ual(
-' '
+0
 );%0A 

test was to create the layout, not render