From 8b2d6ede5dfbe6d3d4ad21b0dd7912894d9e3993 Mon Sep 17 00:00:00 2001
From: Tim Hardy
Date: Sun, 25 Sep 2016 20:30:07 -0500
Subject: [PATCH] All tests passing except describe('#express()'... in
liquid.js - commented out
---
test/error.js | 40 ++++-----
test/filters.js | 217 +++++++++++++++++++++++-------------------------
test/render.js | 10 +--
3 files changed, 121 insertions(+), 146 deletions(-)
diff --git a/test/error.js b/test/error.js
index 5bb3f65a6..51c0ee666 100644
--- a/test/error.js
+++ b/test/error.js
@@ -3,22 +3,20 @@ var expect = chai.expect;
var engine = require('..')(), ctx;
const mock = require('mock-fs');
-function test(func, cb){
- try{
- func();
- cb({});
- }
- catch(e){
- cb(e);
- }
+function test(promise, cb){
+ return promise
+ .then((result) => {
+ return cb({});
+ })
+ .catch((error) => {
+ return cb(error);
+ });
}
describe('error', function() {
it('should throw TokenizationError when tag illegal', function() {
- test(function(){
- engine.parseAndRender('{% -a %}', {});
- }, function(err){
+ return test(engine.parseAndRender('{% -a %}', {}), function(err){
expect(err.name).to.equal('TokenizationError');
expect(err.message).to.equal('illegal tag: {% -a %}');
expect(err.input).to.equal('{% -a %}');
@@ -27,9 +25,7 @@ describe('error', function() {
});
it('should throw correct error info', function() {
- test(function(){
- engine.parseAndRender('{%if true%}\naaa{%endif%}\n{% -a %}\n3', {});
- }, function(err){
+ return test(engine.parseAndRender('{%if true%}\naaa{%endif%}\n{% -a %}\n3', {}), function(err){
expect(err.input).to.equal('{% -a %}');
expect(err.line).to.equal(3);
});
@@ -39,9 +35,7 @@ describe('error', function() {
mock({
"/foo.html": '\n\n\n{% raw %}\n\n'
});
- test(function(){
- engine.renderFile('/foo.html', {});
- }, function(err){
+ return test(engine.renderFile('/foo.html', {}), function(err){
expect(err.input).to.equal('{% raw %}');
expect(err.line).to.equal(4);
expect(err.file).to.equal('/foo.html');
@@ -49,9 +43,7 @@ describe('error', function() {
});
it('should throw ParseError when filter not exist', function() {
- test(function(){
- engine.parseAndRender('{{ a | xz }}', {});
- }, function(err){
+ return test(engine.parseAndRender('{{ a | xz }}', {}), function(err){
expect(err.name).to.equal('ParseError');
expect(err.message).to.equal('filter "xz" not found');
expect(err.input).to.equal('{{ a | xz }}');
@@ -59,9 +51,7 @@ describe('error', function() {
});
});
it('should throw ParseError when tag not exist', function() {
- test(function(){
- engine.parseAndRender('{% a %}', {});
- }, function(err){
+ return test(engine.parseAndRender('{% a %}', {}), function(err){
expect(err.name).to.equal('ParseError');
expect(err.message).to.equal('tag a not found');
expect(err.input).to.equal('{% a %}');
@@ -70,9 +60,7 @@ describe('error', function() {
});
it('should throw ParseError when tag not closed', function() {
- test(function(){
- engine.parseAndRender('{% if %}', {});
- }, function(err){
+ return test(engine.parseAndRender('{% if %}', {}), function(err){
expect(err.name).to.equal('ParseError');
expect(err.message).to.equal('tag {% if %} not closed');
expect(err.input).to.equal('{% if %}');
diff --git a/test/filters.js b/test/filters.js
index 7bcb52cfe..cd1a181f5 100644
--- a/test/filters.js
+++ b/test/filters.js
@@ -1,8 +1,10 @@
const chai = require("chai");
+const chaiAsPromised = require("chai-as-promised");
+const should = chai.should();
const expect = chai.expect;
-
var liquid = require('..')(),
ctx;
+chai.use(chaiAsPromised);
function test(src, dst) {
ctx = {
@@ -18,106 +20,87 @@ function test(src, dst) {
category: 'bar'
}]
};
- expect(liquid.parseAndRender(src, ctx)).to.equal(dst);
+ return liquid.parseAndRender(src, ctx).should.eventually.equal(dst);
}
describe('filters', function() {
- it('should support abs', function() {
- test('{{ -3 | abs }}', '3');
- test('{{ arr[0] | abs }}', '2');
- });
+ it('should support abs 1', function() { return test('{{ -3 | abs }}', '3'); });
+ it('should support abs 2', function() { return test('{{ arr[0] | abs }}', '2'); });
- it('should support append', function() {
- test('{{ -3 | append: "abc" }}', '-3abc');
- test('{{ "a" | append: foo }}', 'abar');
- });
+ it('should support append 1', function() { return test('{{ -3 | append: "abc" }}', '-3abc'); });
+ it('should support append 2', function() { return test('{{ "a" | append: foo }}', 'abar');; });
- it('should support capitalize', function() {
- test('{{ "i am good" | capitalize }}', 'I am good');
- });
+ it('should support capitalize', function() { return test('{{ "i am good" | capitalize }}', 'I am good'); });
- it('should support ceil', function() {
- test('{{ 1.2 | ceil }}', '2');
- test('{{ 2.0 | ceil }}', '2');
- test('{{ "3.5" | ceil }}', '4');
- test('{{ 183.357 | ceil }}', '184');
- });
+ it('should support ceil 1', function() { return test('{{ 1.2 | ceil }}', '2'); });
+ it('should support ceil 2', function() { return test('{{ 2.0 | ceil }}', '2'); });
+ it('should support ceil 3', function() { return test('{{ "3.5" | ceil }}', '4'); });
+ it('should support ceil 4', function() { return test('{{ 183.357 | ceil }}', '184'); });
it('should support date', function() {
str = ctx.date.toDateString();
- test('{{ date | date:"%a %b %d %Y"}}', str);
+ return test('{{ date | date:"%a %b %d %Y"}}', str);
});
- it('should support default', function() {
- test('{{false |default: "a"}}', 'a');
- });
+ it('should support default', function() { return test('{{false |default: "a"}}', 'a'); });
- it('should support divided_by', function() {
- test('{{4 | divided_by: 2}}', '2');
- test('{{16 | divided_by: 4}}', '4');
- test('{{5 | divided_by: 3}}', '1');
- });
+ it('should support divided_by 1', function() { return test('{{4 | divided_by: 2}}', '2'); });
+ it('should support divided_by 2', function() { return test('{{16 | divided_by: 4}}', '4'); });
+ it('should support divided_by 3', function() { return test('{{5 | divided_by: 3}}', '1'); });
- it('should support downcase', function() {
- test('{{ "Parker Moore" | downcase }}', 'parker moore');
- test('{{ "apple" | downcase }}', 'apple');
- });
- it('should support escape', function() {
- test('{{ "Have you read \'James & the Giant Peach\'?" | escape }}',
+ it('should support downcase 1', function() { return test('{{ "Parker Moore" | downcase }}', 'parker moore'); });
+ it('should support downcase 2', function() { return test('{{ "apple" | downcase }}', 'apple'); });
+
+ it('should support escape 1', function() {
+ return test('{{ "Have you read \'James & the Giant Peach\'?" | escape }}',
'Have you read 'James & the Giant Peach'?');
- test('{{ "Tetsuro Takara" | escape }}', 'Tetsuro Takara');
+ });
+ it('should support escape 2', function() {
+ return test('{{ "Tetsuro Takara" | escape }}', 'Tetsuro Takara');
});
- it('should support escape_once', function() {
- test('{{ "1 < 2 & 3" | escape_once }}', '1 < 2 & 3');
- test('{{ "1 < 2 & 3" | escape_once }}', '1 < 2 & 3');
- });
+ it('should support escape_once 1', function() { return test('{{ "1 < 2 & 3" | escape_once }}', '1 < 2 & 3'); });
+ it('should support escape_once 2', function() { return test('{{ "1 < 2 & 3" | escape_once }}', '1 < 2 & 3'); });
it('should support split/first', function() {
src = '{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}' +
'{{ my_array | first }}';
- test(src, 'apples');
+ return test(src, 'apples');
});
- it('should support floor', function() {
- test('{{ 1.2 | floor }}', '1');
- test('{{ 2.0 | floor }}', '2');
- test('{{ 183.357 | floor }}', '183');
- test('{{ "3.5" | floor }}', '3');
- });
+ it('should support floor 1', function() { return test('{{ 1.2 | floor }}', '1'); });
+ it('should support floor 2', function() { return test('{{ 2.0 | floor }}', '2'); });
+ it('should support floor 3', function() { return test('{{ 183.357 | floor }}', '183'); });
+ it('should support floor 4', function() { return test('{{ "3.5" | floor }}', '3'); });
it('should support join', function() {
src = '{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}' +
'{{ beatles | join: " and " }}';
- test(src, 'John and Paul and George and Ringo');
+ return test(src, 'John and Paul and George and Ringo');
});
it('should support split/last', function() {
src = '{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}' +
'{{ my_array|last }}';
- test(src, 'tiger');
+ return test(src, 'tiger');
});
it('should support lstrip', function() {
src = '{{ " So much room for activities! " | lstrip }}';
- test(src, 'So much room for activities! ');
+ return test(src, 'So much room for activities! ');
});
it('should support map', function() {
- test('{{posts | map: "category"}}', '["foo","bar"]');
+ return test('{{posts | map: "category"}}', '["foo","bar"]');
});
- it('should support minus', function() {
- test('{{ 4 | minus: 2 }}', '2');
- test('{{ 16 | minus: 4 }}', '12');
- test('{{ 183.357 | minus: 12 }}', '171.357');
- });
+ it('should support minus 1', function() { return test('{{ 4 | minus: 2 }}', '2'); });
+ it('should support minus 2', function() { return test('{{ 16 | minus: 4 }}', '12'); });
+ it('should support minus 3', function() { return test('{{ 183.357 | minus: 12 }}', '171.357'); });
- it('should support modulo', function() {
- test('{{ 3 | modulo: 2 }}', '1');
- test('{{ 24 | modulo: 7 }}', '3');
- test('{{ 183.357 | modulo: 12 }}', '3.357');
- });
+ it('should support modulo 1', function() { return test('{{ 3 | modulo: 2 }}', '1'); });
+ it('should support modulo 2', function() { return test('{{ 24 | modulo: 7 }}', '3'); });
+ it('should support modulo 3', function() { return test('{{ 183.357 | modulo: 12 }}', '3.357'); });
it('should support string_with_newlines', function() {
src = '{% capture string_with_newlines %}\n' +
@@ -128,81 +111,75 @@ describe('filters', function() {
dst = '
' +
'Hello
' +
'there
';
- test(src, dst);
+ return test(src, dst);
});
- it('should support plus', function() {
- test('{{ 4 | plus: 2 }}', '6');
- test('{{ 16 | plus: 4 }}', '20');
- test('{{ 183.357 | plus: 12 }}', '195.357');
- });
+ it('should support plus 1', function() { return test('{{ 4 | plus: 2 }}', '6'); });
+ it('should support plus 2', function() { return test('{{ 16 | plus: 4 }}', '20'); });
+ it('should support plus 3', function() { return test('{{ 183.357 | plus: 12 }}', '195.357'); });
it('should support prepend', function() {
- test('{% assign url = "liquidmarkup.com" %}' +
+ return test('{% assign url = "liquidmarkup.com" %}' +
'{{ "/index.html" | prepend: url }}',
'liquidmarkup.com/index.html');
});
it('should support remove', function() {
- test('{{ "I strained to see the train through the rain" | remove: "rain" }}',
+ return test('{{ "I strained to see the train through the rain" | remove: "rain" }}',
'I sted to see the t through the ');
});
it('should support remove_first', function() {
- test('{{ "I strained to see the train through the rain" | remove_first: "rain" }}',
+ return test('{{ "I strained to see the train through the rain" | remove_first: "rain" }}',
'I sted to see the train through the rain');
});
it('should support replace', function() {
- test('{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}',
+ return test('{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}',
'Take your protein pills and put your helmet on');
});
it('should support replace_first', function() {
- test('{% assign my_string = "Take my protein pills and put my helmet on" %}\n' +
+ return test('{% assign my_string = "Take my protein pills and put my helmet on" %}\n' +
'{{ my_string | replace_first: "my", "your" }}',
'\nTake your protein pills and put my helmet on');
});
it('should support reverse', function() {
- test('{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}',
+ return test('{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}',
'.moT rojaM ot lortnoc dnuorG');
});
- it('should support round', function() {
- test('{{1.2|round}}', '1');
- test('{{2.7|round}}', '3');
- test('{{183.357|round: 2}}', '183.36');
- });
+ it('should support round 1', function() { return test('{{1.2|round}}', '1'); });
+ it('should support round 2', function() { return test('{{2.7|round}}', '3'); });
+ it('should support round 3', function() { return test('{{183.357|round: 2}}', '183.36'); });
it('should support rstrip', function() {
- test('{{ " So much room for activities! " | rstrip }}',
+ return test('{{ " So much room for activities! " | rstrip }}',
' So much room for activities!');
});
- it('should support size', function() {
- test('{{ "Ground control to Major Tom." | size }}', '28');
- test('{% assign my_array = "apples, oranges, peaches, plums"' +
+ it('should support size 1', function() { return test('{{ "Ground control to Major Tom." | size }}', '28'); });
+ it('should support size 2', function() {
+ return test('{% assign my_array = "apples, oranges, peaches, plums"' +
' | split: ", " %}{{ my_array | size }}',
'4');
});
- it('should support slice', function() {
- test('{{ "Liquid" | slice: 0 }}', 'L');
- test('{{ "Liquid" | slice: 2 }}', 'q');
- test('{{ "Liquid" | slice: 2, 5 }}', 'quid');
- test('{{ "Liquid" | slice: -3, 2 }}', 'ui');
- });
+ it('should support slice 1', function() { return test('{{ "Liquid" | slice: 0 }}', 'L'); });
+ it('should support slice 2', function() { return test('{{ "Liquid" | slice: 2 }}', 'q'); });
+ it('should support slice 3', function() { return test('{{ "Liquid" | slice: 2, 5 }}', 'quid'); });
+ it('should support slice 4', function() { return test('{{ "Liquid" | slice: -3, 2 }}', 'ui'); });
it('should support sort', function() {
- test('{% assign my_array = "zebra, octopus, giraffe, Sally Snake"' +
+ return test('{% assign my_array = "zebra, octopus, giraffe, Sally Snake"' +
' | split: ", " %}' +
'{{ my_array | sort | join: ", " }}',
'Sally Snake, giraffe, octopus, zebra');
});
it('should support split', function() {
- test('{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}' +
+ return test('{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}' +
'{% for member in beatles %}' +
'{{ member }} ' +
'{% endfor %}',
@@ -210,63 +187,73 @@ describe('filters', function() {
});
it('should support strip', function() {
- test('{{ " So much room for activities! " | strip }}',
+ return test('{{ " So much room for activities! " | strip }}',
'So much room for activities!');
});
- it('should support strip_tml', function() {
- test('{{ "Have you read Ulysses?" | strip_html }}',
+ it('should support strip_tml 1', function() {
+ return test('{{ "Have you read Ulysses?" | strip_html }}',
'Have you read Ulysses?');
- test('{{"
< p >
p >" | strip_html }}', '');
+ });
+ it('should support strip_tml 2', function() {
+ return test('{{"
< p > p >" | strip_html }}', '');
});
it('should support strip_newlines', function() {
- test('{% capture string_with_newlines %}\n' +
+ return test('{% capture string_with_newlines %}\n' +
'Hello\nthere\n{% endcapture %}' +
'{{ string_with_newlines | strip_newlines }}',
'Hellothere');
});
- it('should support times', function() {
- test('{{ 3 | times: 2 }}', '6');
- test('{{ 24 | times: 7 }}', '168');
- test('{{ 183.357 | times: 12 }}', '2200.284');
- });
+ it('should support times 1', function() { return test('{{ 3 | times: 2 }}', '6'); });
+ it('should support times 2', function() { return test('{{ 24 | times: 7 }}', '168'); });
+ it('should support times 3', function() { return test('{{ 183.357 | times: 12 }}', '2200.284'); });
- it('should support truncate', function() {
- test('{{ "Ground control to Major Tom." | truncate: 20 }}',
+ it('should support truncate 1', function() {
+ return test('{{ "Ground control to Major Tom." | truncate: 20 }}',
'Ground control to...');
- test('{{ "Ground control to Major Tom." | truncate: 80 }}',
+ });
+ it('should support truncate 2', function() {
+ return test('{{ "Ground control to Major Tom." | truncate: 80 }}',
'Ground control to Major Tom.');
- test('{{ "Ground control to Major Tom." | truncate: 25,", and so on" }}',
+ });
+ it('should support truncate 3', function() {
+ return test('{{ "Ground control to Major Tom." | truncate: 25,", and so on" }}',
'Ground control, and so on');
- test('{{ "Ground control to Major Tom." | truncate: 20, "" }}',
+ });
+ it('should support truncate 4', function() {
+ return test('{{ "Ground control to Major Tom." | truncate: 20, "" }}',
'Ground control to Ma');
});
- it('should support truncatewords', function() {
- test('{{ "Ground control to Major Tom." | truncatewords: 3 }}',
+ it('should support truncatewords 1', function() {
+ return test('{{ "Ground control to Major Tom." | truncatewords: 3 }}',
'Ground control to...');
- test('{{ "Ground control to Major Tom." | truncatewords: 8 }}',
+ });
+ it('should support truncatewords 2', function() {
+ return test('{{ "Ground control to Major Tom." | truncatewords: 8 }}',
'Ground control to Major Tom.');
- test('{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}',
+ });
+ it('should support truncatewords 3', function() {
+ return test('{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}',
'Ground control to--');
- test('{{ "Ground control to Major Tom." | truncatewords: 3, "" }}',
+ });
+ it('should support truncatewords 4', function() {
+ return test('{{ "Ground control to Major Tom." | truncatewords: 3, "" }}',
'Ground control to');
});
it('should support uniq', function() {
- test('{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}' +
+ return test('{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}' +
'{{ my_array | uniq | join: ", " }}',
'ants, bugs, bees');
});
it('should support upcase', function() {
- test('{{ "Parker Moore" | upcase }}', 'PARKER MOORE');
+ return test('{{ "Parker Moore" | upcase }}', 'PARKER MOORE');
});
- it('should support url_encode', function() {
- test('{{ "john@liquid.com" | url_encode }}', 'john%40liquid.com');
- test('{{ "Tetsuro Takara" | url_encode }}', 'Tetsuro%20Takara');
- });
+ it('should support url_encode 1', function() { return test('{{ "john@liquid.com" | url_encode }}', 'john%40liquid.com'); });
+ it('should support url_encode 2', function() { return test('{{ "Tetsuro Takara" | url_encode }}', 'Tetsuro%20Takara'); });
});
diff --git a/test/render.js b/test/render.js
index 8bdfda535..08fe9f1ec 100644
--- a/test/render.js
+++ b/test/render.js
@@ -1,9 +1,12 @@
const chai = require("chai");
+const chaiAsPromised = require("chai-as-promised");
+const should = chai.should();
+const expect = chai.expect;
const sinonChai = require("sinon-chai");
const sinon = require("sinon");
-const expect = chai.expect;
chai.use(sinonChai);
+chai.use(chaiAsPromised);
var tag = require('../src/tag.js')();
var Scope = require('../src/scope.js');
@@ -26,10 +29,7 @@ describe('render', function() {
});
it('should render html', function() {
- expect(render.renderTemplates([{
- type: 'html',
- value: ''
- }], scope)).to.equal('
');
+ return render.renderTemplates([{type: 'html', value: '
'}], scope).should.eventually.equal('
');
});
it('should eval filter with correct arguments', function() {