diff --git a/package.json b/package.json index f299415..f95ea3e 100644 --- a/package.json +++ b/package.json @@ -47,9 +47,11 @@ "btoa": "^1.1.1", "clean-css": "^2.1.6", "domready": "^1.0.4", + "jsdom": "^9.6.0", "marked": "^0.3.2", "prettysize": "0.0.3", "rework": "^0.20.2", + "shelljs": "^0.7.4", "tap-spec": "^2.1.2", "tape": "^3.0.3", "uglify-js": "^2.4.15" diff --git a/test/bundle.js b/test/bundle.js index 6e7b858..b75d59e 100644 --- a/test/bundle.js +++ b/test/bundle.js @@ -1,11 +1,36 @@ var bundle = require('../').bundle var test = require('tape') var fs = require('fs') +var jsdom = require("jsdom") +var shell = require('shelljs') -test('bundle', function(t) { - bundle([fs.readFileSync(__dirname + '/fixture/sample-stats.json', 'utf8')], function(err, res) { - t.notOk(err) - t.ok(res) - t.end() +test('bundle callback', function(t) { + bundle([fs.readFileSync(__dirname + '/fixture/sample-stats.json', 'utf8')], function(err, res) { + t.notOk(err, 'no error') + t.ok(res, 'index.html response okay') + + jsdom.env(res, function(err, window) { + var div = window.document.createElement('div'); + div.innerHTML = res; + + t.equal(div.getElementsByClassName("chart").length, 1, 'svg chart div') + }) + + t.end() + }) +}) + +test('bundle cli', function(t) { + shell.exec('./bin/electrify /fixture/sample-stats.json', function(code, stdout, stderr) { + t.notOk(stderr, 'no error') + t.ok(stdout, 'stdout index.html') + jsdom.env(stdout, function(err, window) { + var div = window.document.createElement('div'); + div.innerHTML = stdout; + + t.equal(div.getElementsByClassName("chart").length, 1, 'svg chart div') }) + }) + + t.end() })