[Pkg-javascript-commits] [node-jade] 04/72: More tests and some refactoring

Jelmer Vernooij jelmer at moszumanska.debian.org
Sun Jul 3 18:03:24 UTC 2016


This is an automated email from the git hooks/post-receive script.

jelmer pushed a commit to annotated tag upstream/1.0.0
in repository node-jade.

commit 6b8231cc54038b79bde322844eb90a691236eea1
Author: Forbes Lindesay <forbes at lindesay.co.uk>
Date:   Tue Feb 10 10:11:54 2015 +0000

    More tests and some refactoring
---
 index.js                          | 139 +++++++++++++++++++++++++++----------
 package.json                      |   3 +-
 test/compile-async.js             |  16 ++++-
 test/compile-client-async.js      |  21 +++++-
 test/compile-client.js            |  20 +++++-
 test/compile-file-client-async.js |   5 --
 test/compile-file-client.js       |  11 ++-
 test/compile-file.js              |  11 ++-
 test/compile.js                   |  20 +++++-
 test/index.js                     |   1 +
 test/render-async.js              | 140 ++++++++++++++++++++++++++++++++++++++
 test/render.js                    |  36 +++++++++-
 test/test.js                      |   1 -
 13 files changed, 371 insertions(+), 53 deletions(-)

diff --git a/index.js b/index.js
index 780aba0..c095540 100644
--- a/index.js
+++ b/index.js
@@ -3,6 +3,7 @@
 var fs = require('fs');
 var assert = require('assert');
 var Promise = require('promise');
+var isPromise = require('is-promise');
 
 var tr = (module.exports = function (transformer) {
   return new Transformer(transformer);
@@ -15,9 +16,6 @@ tr.normalizeAsync = normalizeAsync;
 tr.readFile = Promise.denodeify(fs.readFile);
 tr.readFileSync = fs.readFileSync;
 
-function isPromise(value) {
-  return value && (typeof value === 'object' || typeof value === 'function') && typeof value.then === 'function';
-}
 function normalizeFn(result) {
   if (typeof result === 'function') {
     return {fn: result, dependencies: []};
@@ -98,38 +96,81 @@ function Transformer(tr) {
   this.outputFormat = this._tr.outputFormat;
 }
 
+var fallbacks = {
+  compile: ['compile'],
+  compileAsync: ['compileAsync', 'compile'],
+  compileFile: ['compileFile', 'compile'],
+  compileFileAsync: ['compileFileAsync', 'compileFile', 'compileAsync', 'compile'],
+  compileClient: ['compileClient'],
+  compileClientAsync: ['compileClientAsync', 'compileClient'],
+  compileFileClient: ['compileFileClient', 'compileClient'],
+  compileFileClientAsync: [
+    'compileFileClientAsync', 'compileFileClient', 'compileClientAsync', 'compileClient'
+  ],
+  render: ['render', 'compile'],
+  renderAsync: ['renderAsync', 'render', 'compileAsync', 'compile'],
+  renderFile: ['renderFile', 'render', 'compileFile', 'compile'],
+  renderFileAsync: [
+    'renderFileAsync', 'renderFile', 'renderAsync', 'render',
+    'compileFileAsync', 'compileFile', 'compileAsync', 'compile'
+  ]
+};
+
 Transformer.prototype._hasMethod = function (method) {
   return typeof this._tr[method] === 'function';
 };
+Transformer.prototype.can = function (method) {
+  return fallbacks[method].some(function (method) {
+    return this._hasMethod(method);
+  }.bind(this));
+};
 
 /* COMPILE */
 
 Transformer.prototype.compile = function (str, options) {
-  if (this._hasMethod('compile')) {
-    return tr.normalizeFn(this._tr.compile(str, options));
-  } else {
-    throw new Error('This transform does not support synchronous compiling of plain strings');
+  if (!this.can('compile')) {
+    if (this.can('compileAsync')) {
+      throw new Error('The Transform "' + this.name + '" does not support synchronous compilation');
+    } else if (this.can('compileFileAsync')) {
+      throw new Error('The Transform "' + this.name + '" does not support compiling plain strings');
+    } else {
+      throw new Error('The Transform "' + this.name + '" does not support compilation');
+    }
   }
+  return tr.normalizeFn(this._tr.compile(str, options));
 };
 Transformer.prototype.compileAsync = function (str, options, cb) {
+  if (!this.can('compileAsync')) {
+    if (this.can('compileFileAsync')) {
+      return Promise.reject(new Error('The Transform "' + this.name + '" does not support compiling plain strings')).nodeify(cb);
+    } else {
+      return Promise.reject(new Error('The Transform "' + this.name + '" does not support compilation')).nodeify(cb);
+    }
+  }
   if (this._hasMethod('compileAsync')) {
     return tr.normalizeFnAsync(this._tr.compileAsync(str, options), cb);
-  } else if (this._hasMethod('compile')) {
-    return tr.normalizeFnAsync(this._tr.compile(str, options), cb);
   } else {
-    return Promise.reject(new Error('This transform does not support compiling plain strings')).nodeify(cb);
+    return tr.normalizeFnAsync(this._tr.compile(str, options), cb);
   }
 };
 Transformer.prototype.compileFile = function (filename, options) {
+  if (!this.can('compileFile')) {
+    if (this.can('compileFileAsync')) {
+      throw new Error('The Transform "' + this.name + '" does not support synchronous compilation');
+    } else {
+      throw new Error('The Transform "' + this.name + '" does not support compilation');
+    }
+  }
   if (this._hasMethod('compileFile')) {
     return tr.normalizeFn(this._tr.compileFile(filename, options));
-  } else if (this._hasMethod('compile')) {
-    return tr.normalizeFn(this._tr.compile(tr.readFileSync(filename, 'utf8'), options));
   } else {
-    throw new Error('This transform does not support synchronous compiling');
+    return tr.normalizeFn(this._tr.compile(tr.readFileSync(filename, 'utf8'), options));
   }
 };
 Transformer.prototype.compileFileAsync = function (filename, options, cb) {
+  if (!this.can('compileFileAsync')) {
+    return Promise.reject(new Error('The Transform "' + this.name + '" does not support compilation'));
+  }
   if (this._hasMethod('compileFileAsync')) {
     return tr.normalizeFnAsync(this._tr.compileFileAsync(filename, options), cb);
   } else if (this._hasMethod('compileFile')) {
@@ -138,10 +179,8 @@ Transformer.prototype.compileFileAsync = function (filename, options, cb) {
     return tr.normalizeFnAsync(tr.readFile(filename, 'utf8').then(function (str) {
       if (this._hasMethod('compileAsync')) {
         return this._tr.compileAsync(str, options);
-      } else if (this._hasMethod('compile')) {
-        return this._tr.compile(str, options);
       } else {
-        throw new Error('Transform does not support compiling');
+        return this._tr.compile(str, options);
       }
     }.bind(this)), cb);
   }
@@ -151,31 +190,49 @@ Transformer.prototype.compileFileAsync = function (filename, options, cb) {
 
 
 Transformer.prototype.compileClient = function (str, options) {
-  if (this._hasMethod('compileClient')) {
-    return tr.normalize(this._tr.compileClient(str, options));
-  } else {
-    throw new Error('This transform does not support compile client plain strings');
+  if (!this.can('compileClient')) {
+    if (this.can('compileClientAsync')) {
+      throw new Error('The Transform "' + this.name + '" does not support compiling for the client synchronously.');
+    } else if (this.can('compileFileClientAsync')) {
+      throw new Error('The Transform "' + this.name + '" does not support compiling for the client from a string.');
+    } else {
+      throw new Error('The Transform "' + this.name + '" does not support compiling for the client');
+    }
   }
+  return tr.normalize(this._tr.compileClient(str, options));
 };
 Transformer.prototype.compileClientAsync = function (str, options, cb) {
+  if (!this.can('compileClientAsync')) {
+    if (this.can('compileFileClientAsync')) {
+      return Promise.reject(new Error('The Transform "' + this.name + '" does not support compiling for the client from a string.')).nodeify(cb);
+    } else {
+      return Promise.reject(new Error('The Transform "' + this.name + '" does not support compiling for the client')).nodeify(cb);
+    }
+  }
   if (this._hasMethod('compileClientAsync')) {
     return tr.normalizeAsync(this._tr.compileClientAsync(str, options), cb);
-  } else if (this._hasMethod('compileClient')) {
-    return tr.normalizeAsync(this._tr.compileClient(str, options), cb);
   } else {
-    return Promise.reject(new Error('This transform does not support compile client'));
+    return tr.normalizeAsync(this._tr.compileClient(str, options), cb);
   }
 };
 Transformer.prototype.compileFileClient = function (filename, options) {
+  if (!this.can('compileFileClient')) {
+    if (this.can('compileFileClientAsync')) {
+      throw new Error('The Transform "' + this.name + '" does not support compiling for the client synchronously.');
+    } else {
+      throw new Error('The Transform "' + this.name + '" does not support compiling for the client');
+    }
+  }
   if (this._hasMethod('compileFileClient')) {
     return tr.normalize(this._tr.compileFileClient(filename, options));
-  } else if (this._hasMethod('compileClient')) {
-    return tr.normalize(this._tr.compileClient(tr.readFileSync(filename, 'utf8'), options));
   } else {
-    throw new Error('This transform does not support synchronous compiling to client');
+    return tr.normalize(this._tr.compileClient(tr.readFileSync(filename, 'utf8'), options));
   }
 };
 Transformer.prototype.compileFileClientAsync = function (filename, options, cb) {
+  if (!this.can('compileFileClientAsync')) {
+    return Promise.reject(new Error('The Transform "' + this.name + '" does not support compiling for the client')).nodeify(cb)
+  }
   if (this._hasMethod('compileFileClientAsync')) {
     return tr.normalizeAsync(this._tr.compileFileClientAsync(filename, options), cb);
   } else if (this._hasMethod('compileFileClient')) {
@@ -184,10 +241,8 @@ Transformer.prototype.compileFileClientAsync = function (filename, options, cb)
     return tr.normalizeAsync(tr.readFile(filename, 'utf8').then(function (str) {
       if (this._hasMethod('compileClientAsync')) {
         return this._tr.compileClientAsync(str, options);
-      } else if (this._hasMethod('compileClient')) {
-        return this._tr.compileClient(str, options);
       } else {
-        throw new Error('Transform does not support compileFileClientAsync');
+        return this._tr.compileClient(str, options);
       }
     }.bind(this)), cb);
   }
@@ -196,17 +251,24 @@ Transformer.prototype.compileFileClientAsync = function (filename, options, cb)
 /* RENDER */
 
 Transformer.prototype.render = function (str, options, locals) {
+  if (!this.can('render')) {
+    if (this.can('renderAsync')) {
+      throw new Error('The Transform "' + this.name + '" does not support rendering synchronously.');
+    } else if (this.can('renderFileAsync')) {
+      throw new Error('The Transform "' + this.name + '" does not support rendering from a string.');
+    } else {
+      throw new Error('The Transform "' + this.name + '" does not support rendering');
+    }
+  }
   if (this._hasMethod('render')) {
     return tr.normalize(this._tr.render(str, options, locals));
-  } else if (this._hasMethod('compile')) {
+  } else {
     var compiled = tr.normalizeFn(this._tr.compile(str, options));
     var body = compiled.fn(options || locals);
     if (typeof body !== 'string') {
-      throw new Error('This transform does not support synchronous rendering');
+      throw new Error('The Transform "' + this.name + '" does not support rendering synchronously.');
     }
     return tr.normalize({body: body, dependencies: compiled.dependencies});
-  } else {
-    throw new Error('This transform does not support rendering plain strings');
   }
 };
 Transformer.prototype.renderAsync = function (str, options, locals, cb) {
@@ -214,16 +276,21 @@ Transformer.prototype.renderAsync = function (str, options, locals, cb) {
     cb = locals;
     locals = options;
   }
+  if (!this.can('renderAsync')) {
+    if (this.can('renderFileAsync')) {
+      return Promise.reject(new Error('The Transform "' + this.name + '" does not support rendering from a string.')).nodeify(cb);
+    } else {
+      return Promise.reject(new Error('The Transform "' + this.name + '" does not support rendering')).nodeify(cb);
+    }
+  }
   if (this._hasMethod('renderAsync')) {
     return tr.normalizeAsync(this._tr.renderAsync(str, options, locals), cb);
   } else if (this._hasMethod('render')) {
     return tr.normalizeAsync(this._tr.render(str, options, locals), cb);
-  } else if (this._hasMethod('compile') || this._hasMethod('compileAsync')) {
+  } else {
     return tr.normalizeAsync(this.compileAsync(str, options).then(function (compiled) {
       return {body: compiled.fn(options || locals), dependencies: compiled.dependencies};
     }), cb);
-  } else {
-    return Promise.reject(new Error('This transform does not support rendering of plain strings'));
   }
 };
 Transformer.prototype.renderFile = function (filename, options, locals) {
diff --git a/package.json b/package.json
index 8fb3bc4..2eeaf96 100644
--- a/package.json
+++ b/package.json
@@ -6,6 +6,7 @@
     "jstransformer"
   ],
   "dependencies": {
+    "is-promise": "^2.0.0",
     "promise": "^6.0.1"
   },
   "devDependencies": {
@@ -22,4 +23,4 @@
   },
   "author": "ForbesLindesay",
   "license": "MIT"
-}
\ No newline at end of file
+}
diff --git a/test/compile-async.js b/test/compile-async.js
index 9495435..41881d9 100644
--- a/test/compile-async.js
+++ b/test/compile-async.js
@@ -54,9 +54,21 @@ test('compileAsync - without tr.compile or tr.compileAsync', function () {
     render: function (str, options) {
     }
   });
-  return tr.compileAsync('example input', {}).then(function () {
+  var a = tr.compileAsync('example input', {}).then(function () {
     throw new Error('Expected error');
   }, function (err) {
-    if (!(/does not support/.test(err.message))) throw err;
+    if (!(/does not support compilation/.test(err.message))) throw err;
   });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileFile: function (filename, options) {
+    }
+  });
+  var b = tr.compileAsync('example input', {}).then(function () {
+    throw new Error('Expected error');
+  }, function (err) {
+    if (!(/does not support compiling plain strings/.test(err.message))) throw err;
+  });
+  return Promise.all([a, b]);
 });
diff --git a/test/compile-client-async.js b/test/compile-client-async.js
index 2eabe42..f7b061d 100644
--- a/test/compile-client-async.js
+++ b/test/compile-client-async.js
@@ -1,6 +1,7 @@
 'use strict';
 
 var assert = require('assert');
+var Promise = require('promise');
 var test = require('./test');
 var createTransformer = require('../');
 
@@ -46,18 +47,32 @@ test('compileClientAsync - with tr.compileClient(src, options) => fn', function
   });
   assert(tr.compileClientAsync('example input', sentinel, cbSentinel) === normalizedSentinel);
 });
-test('compile - without tr.compileClient', function () {
+test('compileClientAsync - without tr.compileClient', function () {
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileFileClientAsync : function () {
+    }
+  });
+  var a = tr.compileClientAsync('example input', {}).then(function () {
+    throw new Error('expected to have an error');
+  }, function (err) {
+    if (!/does not support compiling for the client from a string/.test(err.message)) {
+      throw err;
+    }
+  });
   var tr = createTransformer({
     name: 'test',
     outputFormat: 'html',
     compileFile: function () {
     }
   });
-  return tr.compileClientAsync('example input', {}).then(function () {
+  var b = tr.compileClientAsync('example input', {}).then(function () {
     throw new Error('expected to have an error');
   }, function (err) {
-    if (!/does not support/.test(err.message)) {
+    if (!/does not support compiling for the client/.test(err.message)) {
       throw err;
     }
   });
+  return Promise.all([a, b]);
 });
diff --git a/test/compile-client.js b/test/compile-client.js
index 59e4ca7..b37623d 100644
--- a/test/compile-client.js
+++ b/test/compile-client.js
@@ -28,10 +28,28 @@ test('compileClient - without tr.compileClient', function () {
   var tr = createTransformer({
     name: 'test',
     outputFormat: 'html',
+    compileClientAsync: function () {
+    }
+  });
+  assert.throws(function () {
+    tr.compileClient('example input', {});
+  }, /does not support compiling for the client synchronously/);
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileFileClient: function () {
+    }
+  });
+  assert.throws(function () {
+    tr.compileClient('example input', {});
+  }, /does not support compiling for the client from a string/);
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
     compileFile: function () {
     }
   });
   assert.throws(function () {
     tr.compileClient('example input', {});
-  }, /does not support/);
+  }, /does not support compiling for the client/);
 });
diff --git a/test/compile-file-client-async.js b/test/compile-file-client-async.js
index 06cb007..73e5847 100644
--- a/test/compile-file-client-async.js
+++ b/test/compile-file-client-async.js
@@ -94,11 +94,6 @@ test('compileFileClient - with tr.compileClient(filename, options) => fn', funct
 });
 
 test('compileFileClientAsync - without tr.compileClient, tr.compileClientAsync, tr.compileFileClient or tr.compileFileClientAsync', function (override) {
-  override('readFile', function (filename, encoding) {
-    assert(filename === 'example-input.txt');
-    assert(encoding === 'utf8');
-    return Promise.resolve('expected text');
-  });
   var tr = createTransformer({
     name: 'test',
     outputFormat: 'html',
diff --git a/test/compile-file-client.js b/test/compile-file-client.js
index 989da45..1da725c 100644
--- a/test/compile-file-client.js
+++ b/test/compile-file-client.js
@@ -54,10 +54,19 @@ test('compileFileClient - without tr.compileClient or tr.compileFileClient', fun
   var tr = createTransformer({
     name: 'test',
     outputFormat: 'html',
+    compileClientAsync: function () {
+    }
+  });
+  assert.throws(function () {
+    tr.compileFileClient('example-input.txt', {});
+  }, /does not support compiling for the client synchronously/);
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
     render: function () {
     }
   });
   assert.throws(function () {
     tr.compileFileClient('example-input.txt', {});
-  }, /does not support/);
+  }, /does not support compiling for the client/);
 });
diff --git a/test/compile-file.js b/test/compile-file.js
index 3812acb..5d37a10 100644
--- a/test/compile-file.js
+++ b/test/compile-file.js
@@ -50,10 +50,19 @@ test('compileFile - without tr.compile or tr.compileFile', function () {
   var tr = createTransformer({
     name: 'test',
     outputFormat: 'html',
+    compileAsync: function () {
+    }
+  });
+  assert.throws(function () {
+    tr.compileFile('example input', {});
+  }, /does not support synchronous compilation/);
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
     render: function () {
     }
   });
   assert.throws(function () {
     tr.compileFile('example input', {});
-  }, /does not support/);
+  }, /does not support compilation/);
 });
diff --git a/test/compile.js b/test/compile.js
index 346b73d..4d1bede 100644
--- a/test/compile.js
+++ b/test/compile.js
@@ -32,5 +32,23 @@ test('compile - without tr.compile', function () {
   });
   assert.throws(function () {
     tr.compile('example input', {});
-  }, /does not support/);
+  }, /does not support compiling plain strings/);
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileAsync: function () {
+    }
+  });
+  assert.throws(function () {
+    tr.compile('example input', {});
+  }, /does not support synchronous compilation/);
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    render: function () {
+    }
+  });
+  assert.throws(function () {
+    tr.compile('example input', {});
+  }, /does not support compilation/);
 });
diff --git a/test/index.js b/test/index.js
index b01165a..d7e7567 100644
--- a/test/index.js
+++ b/test/index.js
@@ -37,3 +37,4 @@ require('./compile-client-async');
 require('./compile-file-client');
 require('./compile-file-client-async');
 require('./render');
+require('./render-async');
diff --git a/test/render-async.js b/test/render-async.js
new file mode 100644
index 0000000..085064a
--- /dev/null
+++ b/test/render-async.js
@@ -0,0 +1,140 @@
+'use strict';
+
+var assert = require('assert');
+var Promise = require('promise');
+var test = require('./test');
+var createTransformer = require('../');
+
+test('renderAsync - with tr.renderAsync(src, options) => str', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  var fnSentinel = {};
+  var cbSentinel = function () {};
+  var normalizedSentinel = {};
+  override('normalizeAsync', function (body, cb) {
+    assert(body === fnSentinel);
+    assert(cb === cbSentinel);
+    return normalizedSentinel;
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    renderAsync: function (str, options) {
+      assert(str === 'example input');
+      assert(options === sentinel);
+      return fnSentinel;
+    }
+  });
+  assert(tr.renderAsync('example input', sentinel, cbSentinel) === normalizedSentinel);
+});
+test('renderAsync - with tr.render(src, options) => str', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  var fnSentinel = {};
+  var cbSentinel = function () {};
+  var normalizedSentinel = {};
+  override('normalizeAsync', function (body, cb) {
+    assert(body === fnSentinel);
+    assert(cb === cbSentinel);
+    return normalizedSentinel;
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    render: function (str, options) {
+      assert(str === 'example input');
+      assert(options === sentinel);
+      return fnSentinel;
+    }
+  });
+  assert(tr.renderAsync('example input', sentinel, cbSentinel) === normalizedSentinel);
+});
+test('renderAsync - with tr.compileAsync(src, options) => fn', function (override) {
+  var sentinel = {};
+  var fnSentinel = {};
+  var normalizedSentinel = {};
+  var cbSentinel = function () {};
+
+  override('normalizeAsync', function (result) {
+    assert.deepEqual(result, {
+      body: '<br />',
+      dependencies: ['example.js']
+    });
+    return normalizedSentinel;
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileAsync: function () {
+      throw new Error('Did not expect this to be called');
+    }
+  });
+  tr.compileAsync = function (str, options) {
+    assert(str === 'example input');
+    assert(options === sentinel);
+    return {then: function (fn) { return fn({fn: function (locals) {
+      assert(locals === sentinel);
+      return '<br />';
+    }, dependencies: ['example.js']}); }};
+  };
+  assert(tr.renderAsync('example input', sentinel, cbSentinel) === normalizedSentinel);
+});
+test('renderAsync - with tr.compile(src, options) => fn', function (override) {
+  var sentinel = {};
+  var fnSentinel = {};
+  var normalizedSentinel = {};
+  var cbSentinel = function () {};
+
+  override('normalizeAsync', function (result) {
+    assert.deepEqual(result, {
+      body: '<br />',
+      dependencies: ['example.js']
+    });
+    return normalizedSentinel;
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compile: function () {
+      throw new Error('Did not expect this to be called');
+    }
+  });
+  tr.compileAsync = function (str, options) {
+    assert(str === 'example input');
+    assert(options === sentinel);
+    return {then: function (fn) { return fn({fn: function (locals) {
+      assert(locals === sentinel);
+      return '<br />';
+    }, dependencies: ['example.js']}); }};
+  };
+  assert(tr.renderAsync('example input', sentinel, cbSentinel) === normalizedSentinel);
+});
+test('renderAsync - without tr.render', function () {
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    renderFileAsync : function () {
+    }
+  });
+  var a = tr.renderAsync('example input', {}).then(function () {
+    throw new Error('expected to have an error');
+  }, function (err) {
+    if (!/does not support rendering from a string/.test(err.message)) {
+      throw err;
+    }
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileFileClient: function () {
+    }
+  });
+  var b = tr.renderAsync('example input', {}).then(function () {
+    throw new Error('expected to have an error');
+  }, function (err) {
+    if (!/does not support rendering/.test(err.message)) {
+      throw err;
+    }
+  });
+  return Promise.all([a, b]);
+});
diff --git a/test/render.js b/test/render.js
index 84615b1..c490a77 100644
--- a/test/render.js
+++ b/test/render.js
@@ -1,6 +1,7 @@
 'use strict';
 
 var assert = require('assert');
+var Promise = require('promise');
 var test = require('./test');
 var createTransformer = require('../');
 
@@ -59,10 +60,43 @@ test('render - without tr.render', function () {
   var tr = createTransformer({
     name: 'test',
     outputFormat: 'html',
+    compileAsync: function () {
+    }
+  });
+  assert.throws(function () {
+    tr.render('example input', {});
+  }, /does not support rendering synchronously/);
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileFileAsync: function () {
+    }
+  });
+  assert.throws(function () {
+    tr.render('example input', {});
+  }, /does not support rendering from a string/);
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
     compileClient: function () {
     }
   });
   assert.throws(function () {
     tr.render('example input', {});
-  }, /does not support/);
+  }, /does not support rendering/);
+  assert.throws(function () {
+    tr.render('example input', {});
+  }, /does not support rendering/);
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compile: function () {
+      return function () {
+        return Promise.resolve('foo');
+      };
+    }
+  });
+  assert.throws(function () {
+    tr.render('example input', {});
+  }, /does not support rendering synchronously/);
 });
diff --git a/test/test.js b/test/test.js
index 86e624b..b97e1ff 100644
--- a/test/test.js
+++ b/test/test.js
@@ -34,7 +34,6 @@ function test(name, fn) {
         });
         throw err;
       });
-      throw new Error('Asynchronous tests cannot use mocks');
     } else {
       Object.keys(originals).forEach(function (key) {
         tr[key] = originals[key];

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-jade.git



More information about the Pkg-javascript-commits mailing list