[Pkg-javascript-commits] [node-jade] 48/72: Add tests for renderFile*

Jelmer Vernooij jelmer at moszumanska.debian.org
Sun Jul 3 18:03:28 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 1345b5e5d79562bbe4e2e353aab01d4c8eef2701
Author: Timothy Gu <timothygu99 at gmail.com>
Date:   Thu Jul 9 08:28:49 2015 +0800

    Add tests for renderFile*
---
 test/index.js             |   2 +
 test/render-file-async.js | 182 ++++++++++++++++++++++++++++++++++++++++++++++
 test/render-file.js       | 107 +++++++++++++++++++++++++++
 3 files changed, 291 insertions(+)

diff --git a/test/index.js b/test/index.js
index 7b67ec6..75f9a1f 100644
--- a/test/index.js
+++ b/test/index.js
@@ -35,5 +35,7 @@ require('./compile-file-client');
 require('./compile-file-client-async');
 require('./render');
 require('./render-async');
+require('./render-file');
+require('./render-file-async');
 require('./input-formats');
 require('./output-format');
diff --git a/test/render-file-async.js b/test/render-file-async.js
new file mode 100644
index 0000000..87eb760
--- /dev/null
+++ b/test/render-file-async.js
@@ -0,0 +1,182 @@
+'use strict';
+
+var Promise = require('promise');
+var assert = require('assert');
+var test = require('./test');
+var createTransformer = require('../');
+
+test('renderFileAsync', function () {
+
+test('with tr.renderFileAsync(file, options, locals) => Promise(str)', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    renderFileAsync: function (file, options, locals) {
+      assert(file === 'example-input.txt');
+      assert(options === sentinel);
+      assert(locals === localSentinel);
+      return Promise.resolve('example output');
+    }
+  });
+  return tr.renderFileAsync('example-input.txt', sentinel, localSentinel).then(function (rendered) {
+    assert(rendered.body === 'example output');
+  });
+});
+test('with tr.renderFile(file, options, locals) => str', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    renderFile: function (file, options, locals) {
+      assert(file === 'example-input.txt');
+      assert(options === sentinel);
+      assert(locals === localSentinel);
+      return 'example output';
+    }
+  });
+  return tr.renderFileAsync('example-input.txt', sentinel, localSentinel).then(function (rendered) {
+    assert(rendered.body === 'example output');
+  });
+});
+test('with tr.renderAsync(src, options, locals) => Promise(str)', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  override('readFile', function (filename) {
+    assert(filename === 'example-input.txt');
+    return Promise.resolve('example input');
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    renderAsync: function (str, options, locals) {
+      assert(str === 'example input');
+      assert(options === sentinel);
+      assert(locals === localSentinel);
+      return Promise.resolve('example output');
+    }
+  });
+  return tr.renderFileAsync('example-input.txt', sentinel, localSentinel).then(function (rendered) {
+    assert(rendered.body === 'example output');
+  });
+});
+test('with tr.render(src, options, locals) => str', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  override('readFile', function (filename) {
+    assert(filename === 'example-input.txt');
+    return Promise.resolve('example input');
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    render: function (str, options, locals) {
+      assert(str === 'example input');
+      assert(options === sentinel);
+      assert(locals === localSentinel);
+      return 'example output';
+    }
+  });
+  return tr.renderFileAsync('example-input.txt', sentinel, localSentinel).then(function (rendered) {
+    assert(rendered.body === 'example output');
+  });
+});
+test('with tr.compileFileAsync(file, options) => Promise(fn => Promise(str))', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileFileAsync: function (file, options) {
+      assert(file === 'example-input.txt');
+      assert(options === sentinel);
+      return Promise.resolve(function (locals) {
+        assert(locals === localSentinel);
+        return Promise.resolve('example output');
+      });
+    }
+  });
+  return tr.renderFileAsync('example-input.txt', sentinel, localSentinel).then(function (rendered) {
+    assert(rendered.body === 'example output');
+  });
+});
+test('with tr.compileFile(file, options) => fn', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileFile: function (file, options) {
+      assert(file === 'example-input.txt');
+      assert(options === sentinel);
+      return function (locals) {
+        assert(locals === localSentinel);
+        return 'example output';
+      };
+    }
+  });
+  return tr.renderFileAsync('example-input.txt', sentinel, localSentinel).then(function (rendered) {
+    assert(rendered.body === 'example output');
+  });
+});
+test('with tr.compileAsync(str, options) => Promise(fn => Promise(str))', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  override('readFile', function (filename) {
+    assert(filename === 'example-input.txt');
+    return Promise.resolve('example input');
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileAsync: function (str, options) {
+      assert(str === 'example input');
+      assert(options === sentinel);
+      return Promise.resolve(function (locals) {
+        assert(locals === localSentinel);
+        return Promise.resolve('example output');
+      });
+    }
+  });
+  return tr.renderFileAsync('example-input.txt', sentinel, localSentinel).then(function (rendered) {
+    assert(rendered.body === 'example output');
+  });
+});
+test('with tr.compile(str, options) => fn', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  override('readFile', function (filename) {
+    assert(filename === 'example-input.txt');
+    return Promise.resolve('example input');
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compile: function (str, options) {
+      assert(str === 'example input');
+      assert(options === sentinel);
+      return function (locals) {
+        assert(locals === localSentinel);
+        return 'example output';
+      };
+    }
+  });
+  return tr.renderFileAsync('example-input.txt', sentinel, localSentinel).then(function (rendered) {
+    assert(rendered.body === 'example output');
+  });
+});
+test('without any of the above', function (override) {
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileFileClientAsync: function () {
+    }
+  });
+  assert.throws(function () {
+    tr.renderFileAsync('example input', {}, {});
+  }, /does not support rendering/);
+});
+
+});
diff --git a/test/render-file.js b/test/render-file.js
new file mode 100644
index 0000000..03a787e
--- /dev/null
+++ b/test/render-file.js
@@ -0,0 +1,107 @@
+'use strict';
+
+var assert = require('assert');
+var test = require('./test');
+var createTransformer = require('../');
+
+test('renderFile', function () {
+
+test('with tr.renderFile(file, options, locals) => str', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  override('readFileSync', function (filename) {
+    assert(filename === 'example-input.txt');
+    return 'example input';
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    renderFile: function (file, options, locals) {
+      assert(file === 'example-input.txt');
+      assert(options === sentinel);
+      assert(locals === localSentinel);
+      return 'example output';
+    }
+  });
+  assert(tr.renderFile('example-input.txt', sentinel, localSentinel).body === 'example output');
+});
+test('with tr.render(src, options, locals) => str', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  override('readFileSync', function (filename) {
+    assert(filename === 'example-input.txt');
+    return 'example input';
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    render: function (str, options, locals) {
+      assert(str === 'example input');
+      assert(options === sentinel);
+      assert(locals === localSentinel);
+      return 'example output';
+    }
+  });
+  assert(tr.renderFile('example-input.txt', sentinel, localSentinel).body === 'example output');
+});
+test('with tr.compileFile(file, options) => fn', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileFile: function (file, options) {
+      assert(file === 'example-input.txt');
+      assert(options === sentinel);
+      return function (locals) {
+        assert(locals === localSentinel);
+        return 'example output';
+      };
+    }
+  });
+  assert(tr.renderFile('example-input.txt', sentinel, localSentinel).body === 'example output');
+});
+test('with tr.compile(str, options) => fn', function (override) {
+  var sentinel = {};
+  var localSentinel = {};
+  override('readFileSync', function (filename) {
+    assert(filename === 'example-input.txt');
+    return 'example input';
+  });
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compile: function (str, options) {
+      assert(str === 'example input');
+      assert(options === sentinel);
+      return function (locals) {
+        assert(locals === localSentinel);
+        return 'example output';
+      };
+    }
+  });
+  assert(tr.renderFile('example-input.txt', sentinel, localSentinel).body === 'example output');
+});
+test('without any of the above', function (override) {
+  var tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileAsync: function () {
+    }
+  });
+  assert.throws(function () {
+    tr.renderFile('example input', {}, {});
+  }, /does not support rendering synchronously/);
+
+  tr = createTransformer({
+    name: 'test',
+    outputFormat: 'html',
+    compileClient: function () {
+    }
+  });
+  assert.throws(function () {
+    tr.renderFile('example input', {}, {});
+  }, /does not support rendering synchronously/);
+});
+
+});

-- 
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