[Pkg-javascript-commits] [node-jade] 46/72: Add tests for normalize*Async
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 70d319081f990ff3aa875a3e46f7707f3ea53370
Author: Timothy Gu <timothygu99 at gmail.com>
Date: Wed Jul 8 01:51:17 2015 -0700
Add tests for normalize*Async
---
test/index.js | 1 +
test/normalize-async.js | 225 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 226 insertions(+)
diff --git a/test/index.js b/test/index.js
index 8ad0423..604b1a9 100644
--- a/test/index.js
+++ b/test/index.js
@@ -38,3 +38,4 @@ require('./render-async');
require('./input-formats');
require('./output-format');
require('./normalize');
+require('./normalize-async');
diff --git a/test/normalize-async.js b/test/normalize-async.js
new file mode 100644
index 0000000..99bc875
--- /dev/null
+++ b/test/normalize-async.js
@@ -0,0 +1,225 @@
+'use strict';
+
+var Promise = require('promise');
+var assert = require('assert');
+var test = require('./test');
+var tr = require('../');
+
+function testAsync (funcName, bodyVar, specs) {
+ var func = tr[funcName];
+ var bodyType = specs.good[0],
+ body = specs.good[1],
+ notBodyType = specs.bad[0],
+ notBody = specs.bad[1];
+
+ test(funcName, function () {
+ test('Using callbacks', function (done) {
+ var expected = { dependencies: [] };
+ expected[bodyVar] = body;
+ func(body, function (err, normalized) {
+ if (err) return done(err);
+ try {
+ assert.deepEqual(normalized, expected);
+ } catch (err) {
+ return done(err);
+ }
+ func(notBody, function (err, normalized) {
+ if (!err) return done(new Error('expecting error'));
+ done();
+ });
+ });
+ });
+
+ test(bodyType + ' => Promise({ ' + bodyVar + ', dependencies })', function () {
+ var expected = { dependencies: [] };
+ expected[bodyVar] = body;
+ return func(body).then(function (normalized) {
+ assert.deepEqual(normalized, expected);
+ });
+ });
+
+ test('{ ' + bodyVar + ': ' + bodyType + ' } => Promise({ ' + bodyVar + ', dependencies })', function () {
+ var input = {};
+ input[bodyVar] = body;
+ return func(input).then(function (normalized) {
+ input.dependencies = [];
+ assert.deepEqual(normalized, input);
+ });
+ });
+
+ test('{ ' + bodyVar + ': ' + bodyType + ', dependencies: [] } => Promise({ ' + bodyVar + ', dependencies })', function () {
+ var input = { dependencies: [] };
+ input[bodyVar] = body;
+ var promise1 = func(input).then(function (normalized) {
+ input.dependencies = [];
+ assert.deepEqual(normalized, input);
+ });
+
+ input.dependencies = [ '/tmp/a.txt' ];
+ var promise2 = func(input).then(function (normalized) {
+ input.dependencies = [ '/tmp/a.txt' ];
+ assert.deepEqual(normalized, input);
+ });
+
+ return Promise.all([promise1, promise2]);
+ });
+
+ test('{ ' + bodyVar + ': Promise(' + bodyType + ') } => Promise({ ' + bodyVar + ', dependencies })', function () {
+ var input = {};
+ input[bodyVar] = Promise.resolve(body);
+ return func(input).then(function (normalized) {
+ input.dependencies = [];
+ input[bodyVar] = body;
+ assert.deepEqual(normalized, input);
+ });
+ });
+
+ test('{ ' + bodyVar + ': Promise(' + bodyType + '), dependencies: [] } => Promise({ ' + bodyVar + ', dependencies })', function () {
+ var input = { dependencies: [] };
+ input[bodyVar] = Promise.resolve(body);
+ var promise1 = func(input).then(function (normalized) {
+ input.dependencies = [];
+ input[bodyVar] = body;
+ assert.deepEqual(normalized, input);
+ });
+
+ input.dependencies = [ '/tmp/a.txt' ];
+ var promise2 = func(input).then(function (normalized) {
+ input.dependencies = [ '/tmp/a.txt' ];
+ input[bodyVar] = body;
+ assert.deepEqual(normalized, input);
+ });
+
+ return Promise.all([promise1, promise2]);
+ });
+
+ test('Promise(' + bodyType + ') => Promise({ ' + bodyVar + ', dependencies })', function () {
+ var expected = { dependencies: [] };
+ expected[bodyVar] = body;
+ return func(Promise.resolve(body)).then(function (normalized) {
+ assert.deepEqual(normalized, expected);
+ });
+ });
+
+ test('Promise({ ' + bodyVar + ': ' + bodyType + ' }) => Promise({ ' + bodyVar + ', dependencies })', function () {
+ var input = {};
+ input[bodyVar] = body;
+ return func(Promise.resolve(input)).then(function (normalized) {
+ input.dependencies = [];
+ assert.deepEqual(normalized, input);
+ });
+ });
+
+ test('Promise({ ' + bodyVar + ': ' + bodyType + ', dependencies: [] }) => Promise({ ' + bodyVar + ', dependencies })', function () {
+ var input = { dependencies: [] };
+ input[bodyVar] = body;
+ var promise1 = func(Promise.resolve(input)).then(function (normalized) {
+ input.dependencies = [];
+ assert.deepEqual(normalized, input);
+ });
+
+ input.dependencies = [ '/tmp/a.txt' ];
+ var promise2 = func(Promise.resolve(input)).then(function (normalized) {
+ input.dependencies = [ '/tmp/a.txt' ];
+ assert.deepEqual(normalized, input);
+ });
+
+ return Promise.all([promise1, promise2]);
+ });
+
+ test('Promise({ ' + bodyVar + ': Promise(' + bodyType + '), dependencies: [] }) => Promise({ ' + bodyVar + ', dependencies })', function () {
+ var input = { dependencies: [] };
+ input[bodyVar] = Promise.resolve(body);
+ var promise1 = func(Promise.resolve(input)).then(function (normalized) {
+ input[bodyVar] = body;
+ input.dependencies = [];
+ assert.deepEqual(normalized, input);
+ });
+
+ // Use another promise
+ input[bodyVar] = Promise.resolve(body);
+ input.dependencies = [ '/tmp/a.txt' ];
+ var promise2 = func(Promise.resolve(input)).then(function (normalized) {
+ input[bodyVar] = body;
+ input.dependencies = [ '/tmp/a.txt' ];
+ assert.deepEqual(normalized, input);
+ });
+
+ return Promise.all([promise1, promise2]);
+ });
+
+ test(notBodyType + ' => Promise(throw)', function () {
+ return assertPromiseError(func(notBody), /Invalid result object/);
+ });
+
+ test('{ ' + bodyVar + ': ' + notBodyType + ', dependencies: [] } => Promise(throw)', function () {
+ var input = { dependencies: [] };
+ input[bodyVar] = notBody;
+ return assertPromiseError(func(input), /Invalid result object/);
+ });
+
+ test('{ ' + bodyVar + ': ' + bodyType + ', dependencies: Number } => Promise(throw)', function () {
+ var input = { dependencies: 1 };
+ input[bodyVar] = body;
+ return assertPromiseError(func(input), /dependencies .* array/);
+ });
+
+ test('Promise(' + notBodyType + ') => Promise(throw)', function () {
+ return assertPromiseError(func(Promise.resolve(notBody)), /Invalid result object/);
+ });
+
+ test('Promise({ ' + bodyVar + ': ' + notBodyType + ', dependencies: [] }) => Promise(throw)', function () {
+ var input = { dependencies: [] };
+ input[bodyVar] = notBody;
+ return assertPromiseError(func(Promise.resolve(input)), /Invalid result object/);
+ });
+
+ test('Promise({ ' + bodyVar + ': ' + bodyType + ', dependencies: Number }) => Promise(throw)', function () {
+ var input = { dependencies: 1 };
+ input[bodyVar] = body;
+ return assertPromiseError(func(Promise.resolve(input)), /dependencies .* array/);
+ });
+
+ test('{ ' + bodyVar + ': Promise(' + notBodyType + '), dependencies: [] } => Promise(throw)', function () {
+ var input = { dependencies: [] };
+ input[bodyVar] = Promise.resolve(notBody);
+ return assertPromiseError(func(input), /Invalid result object/);
+ });
+
+ test('{ ' + bodyVar + ': Promise(' + bodyType + '), dependencies: Number } => Promise(throw)', function () {
+ var input = { dependencies: 1 };
+ input[bodyVar] = Promise.resolve(body);
+ return assertPromiseError(func(input), /dependencies .* array/);
+ });
+
+ test('Promise({ ' + bodyVar + ': Promise(' + notBodyType + '), dependencies: [] }) => Promise(throw)', function () {
+ var input = { dependencies: [] };
+ input[bodyVar] = Promise.resolve(notBody);
+ return assertPromiseError(func(Promise.resolve(input)), /Invalid result object/);
+ });
+
+ test('Promise({ ' + bodyVar + ': Promise(' + bodyType + '), dependencies: Number }) => Promise(throw)', function () {
+ var input = { dependencies: 1 };
+ input[bodyVar] = Promise.resolve(body);
+ return assertPromiseError(func(Promise.resolve(input)), /dependencies .* array/);
+ });
+ });
+}
+
+testAsync('normalizeAsync', 'body', {
+ good: [ 'String', '<html></html>' ],
+ bad: [ 'Function', function () {} ]
+});
+testAsync('normalizeFnAsync', 'fn', {
+ good: [ 'Function', function () {} ],
+ bad: [ 'String', '<html></html>' ]
+});
+
+function assertPromiseError (promise, regex) {
+ return promise.then(function () {
+ throw new Error('expected error');
+ }, function (err) {
+ if (!regex || regex.test(err.message)) return;
+ throw new Error('not the expected error message: ' + err.message);
+ });
+}
--
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