Permalink
Browse files

previous dustjs test recovered. make file working.

  • Loading branch information...
Jairo de Morais
Jairo de Morais committed Mar 19, 2012
1 parent 554f962 commit 1523ad65085d7bcf577c0828d91f85ef5394b022
View
@@ -2,7 +2,13 @@
# Run all tests
#
test:
- node tests/server/specRunner.js
+ node test/server.js
+
+#
+# Run jasmine-test
+#
+jasmine:
+ node test/jasmine-test/server/specRunner.js
#
# Run the benchmarks
View
@@ -0,0 +1,83 @@
+(function(exports){
+
+exports.coreSetup = function(suite, auto) {
+ auto.forEach(function(test) {
+ suite.test(test.name, function(){
+ testRender(this, test.source, test.context, test.expected);
+ });
+ });
+
+ suite.test("base context", function() {
+ var base = dust.makeBase({
+ sayHello: function() { return "Hello!" }
+ });
+ testRender(this, "{sayHello} {foo}", base.push({foo: "bar"}), "Hello! bar");
+ });
+
+ suite.test("valid keys", function() {
+ testRender(this, "{_foo}{$bar}{baz1}", {_foo: 1, $bar: 2, baz1: 3}, "123");
+ });
+
+ suite.test("onLoad callback", function() {
+ var unit = this;
+ dust.onLoad = function(name, cb) {
+ cb(null, "Loaded: " + name);
+ };
+ dust.render("onLoad", {}, function(err, out) {
+ try {
+ unit.ifError(err);
+ unit.equals(out, "Loaded: onLoad");
+ } catch(err) {
+ unit.fail(err);
+ return;
+ }
+ unit.pass();
+ });
+ });
+
+ suite.test("renderSource (callback)", function() {
+ var unit = this;
+ dust.renderSource('Hello World', {}, function(err, out) {
+ try {
+ unit.ifError(err);
+ unit.equals(out, "Hello World");
+ } catch(err) {
+ unit.fail(err);
+ return;
+ }
+ unit.pass();
+ });
+ });
+
+ suite.test("renderSource (stream)", function() {
+ var unit = this;
+ dust.renderSource('Hello World', {}).on('data', function(data) {
+ try {
+ unit.equals('Hello World', data);
+ } catch(err) {
+ unit.fail(err);
+ return;
+ }
+ unit.pass();
+ }).on('error', function(err) {
+ unit.fail(err);
+ });
+ });
+}
+
+function testRender(unit, source, context, expected) {
+ var name = unit.id;
+ dust.loadSource(dust.compile(source, name));
+ dust.render(name, context, function(err, output) {
+ try {
+ unit.ifError(err);
+ unit.equals(output, expected);
+ } catch(err) {
+ unit.fail(err);
+ return;
+ }
+ unit.pass();
+ });
+}
+
+})(typeof exports !== "undefined" ? exports : window);
Oops, something went wrong.

0 comments on commit 1523ad6

Please sign in to comment.