I'd like to use Vows to test DOM-free JavaScript code, ideally directly running against the compiled JS.
My Vows are written in CoffeeScript, but I'm not sure how to load my JS; I've tried just inlining it using eval
:
vows = require "vows"
assert = require "assert"
eval('var e=this;function f(a,g){var c=a.split("."),b=e;!(c[0]in b)&&b.execScript&&b.execScript("var "+c[0]);for(var d;c.length&&(d=c.shift());)!c.length&&g!==void 0?b[d]=g:b=b[d]?b[d]:b[d]={}}function h(a){a.call(e)};(function(){var a;a={};h(function(){a=function(a){this.a=a};a.prototype.b=function(a){return this.a+a.a};f("Cl.LinearExpression",a);f("Cl.LinearExpression.prototype.plus",a.prototype.b)})}).call(this);');
vows
.describe("Linear Expression")
.addBatch
"initialized with a number":
topic: -> new Cl.LinearExpression 5
"adds up with scalar": (cle) -> assert.equal 7, cle.plus 2
.export(module)
but I get "ReferenceError: Cl is not defined".
Running the minified JS and new Cl.LinearExpression(5);
in a browser console works fine, so the compiled code is okay.
What's the best way to load JS into node for testing by Vows?
This is a namespace problem; importing with
adds all of the compiled JS objects to the current namespace, where they can be accessed in Vows.
Unfortunately, I still don't know why using
eval()
or backticks with the inlined contents ofcompiled.js
doesn't work.