Преглед изворни кода

Start linting all test/ files as part of test script (#704)

In an effort of ensuring consistent code style in test files as with
the "production" source code, we should run eslint as part of the
`$ npm test` script as well.

Most of the related fixes was done by `eslint` using the `--fix` argument.

Only special configuration tweaks for tests compared to the other
source code, is to allow functions declaration without names. The
rationale for allowing that in tests, is that the important reason we
have them in the source code (proper stacktraces) aren't as important
in test files.
tags/v3.0.2
Phillip Johnsen GitHub пре 6 година
родитељ
комит
bb700c5433
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
66 измењених фајлова са 225 додато и 219 уклоњено
  1. +1
    -1
      package.json
  2. +6
    -0
      test/.eslintrc
  3. +2
    -2
      test/_files/ampersand_escape.js
  4. +1
    -1
      test/_files/apostrophe.js
  5. +1
    -1
      test/_files/array_of_strings.js
  6. +1
    -1
      test/_files/avoids_obj_prototype_in_view_cache.js
  7. +2
    -2
      test/_files/backslashes.js
  8. +2
    -2
      test/_files/bug_11_eating_whitespace.js
  9. +1
    -1
      test/_files/bug_length_property.js
  10. +3
    -3
      test/_files/changing_delimiters.js
  11. +4
    -4
      test/_files/check_falsy.js
  12. +2
    -2
      test/_files/comments.js
  13. +6
    -6
      test/_files/complex.js
  14. +5
    -5
      test/_files/context_lookup.js
  15. +5
    -5
      test/_files/delimiters.js
  16. +1
    -1
      test/_files/disappearing_whitespace.js
  17. +5
    -5
      test/_files/dot_notation.js
  18. +3
    -3
      test/_files/double_render.js
  19. +1
    -1
      test/_files/empty_list.js
  20. +1
    -1
      test/_files/empty_sections.js
  21. +3
    -3
      test/_files/empty_string.js
  22. +1
    -1
      test/_files/empty_template.js
  23. +1
    -1
      test/_files/error_not_found.js
  24. +2
    -2
      test/_files/escaped.js
  25. +7
    -7
      test/_files/falsy.js
  26. +8
    -8
      test/_files/falsy_array.js
  27. +1
    -1
      test/_files/grandparent_context.js
  28. +4
    -4
      test/_files/higher_order_sections.js
  29. +1
    -1
      test/_files/implicit_iterator.js
  30. +2
    -2
      test/_files/included_tag.js
  31. +2
    -2
      test/_files/inverted_section.js
  32. +3
    -3
      test/_files/keys_with_questionmarks.js
  33. +1
    -1
      test/_files/malicious_template.js
  34. +1
    -1
      test/_files/multiline_comment.js
  35. +1
    -1
      test/_files/nested_dot.js
  36. +1
    -1
      test/_files/nested_iterating.js
  37. +1
    -1
      test/_files/nesting.js
  38. +1
    -1
      test/_files/nesting_same_name.js
  39. +8
    -8
      test/_files/null_lookup_array.js
  40. +20
    -20
      test/_files/null_lookup_object.js
  41. +3
    -3
      test/_files/null_string.js
  42. +1
    -1
      test/_files/null_view.js
  43. +1
    -1
      test/_files/partial_array.js
  44. +1
    -1
      test/_files/partial_array_of_partials.js
  45. +1
    -1
      test/_files/partial_array_of_partials_implicit.js
  46. +1
    -1
      test/_files/partial_empty.js
  47. +3
    -3
      test/_files/partial_template.js
  48. +4
    -4
      test/_files/partial_view.js
  49. +4
    -4
      test/_files/partial_whitespace.js
  50. +1
    -1
      test/_files/recursion_with_same_names.js
  51. +1
    -1
      test/_files/reuse_of_enumerables.js
  52. +1
    -1
      test/_files/section_as_context.js
  53. +5
    -5
      test/_files/section_functions_in_partials.js
  54. +2
    -2
      test/_files/simple.js
  55. +1
    -1
      test/_files/string_as_context.js
  56. +3
    -3
      test/_files/two_in_a_row.js
  57. +1
    -1
      test/_files/two_sections.js
  58. +2
    -2
      test/_files/unescaped.js
  59. +7
    -7
      test/_files/uses_props_from_view_prototype.js
  60. +3
    -3
      test/_files/whitespace.js
  61. +1
    -1
      test/_files/zero_view.js
  62. +32
    -32
      test/cli-test.js
  63. +7
    -7
      test/mustache-spec-test.js
  64. +9
    -9
      test/parse-test.js
  65. +5
    -5
      test/render-helper.js
  66. +3
    -3
      test/render-test.js

+ 1
- 1
package.json Прегледај датотеку

@@ -32,7 +32,7 @@
"npm": ">=1.4.0" "npm": ">=1.4.0"
}, },
"scripts": { "scripts": {
"pretest": "eslint mustache.js bin/mustache",
"pretest": "eslint mustache.js bin/mustache test/**/*.js",
"test": "mocha --reporter spec test/*-test.js", "test": "mocha --reporter spec test/*-test.js",
"test-render": "mocha --reporter spec test/render-test", "test-render": "mocha --reporter spec test/render-test",
"pre-test-browser": "node test/create-browser-suite.js", "pre-test-browser": "node test/create-browser-suite.js",


+ 6
- 0
test/.eslintrc Прегледај датотеку

@@ -0,0 +1,6 @@
{
"extends": "../.eslintrc",
"rules": {
"func-names": 0
}
}

+ 2
- 2
test/_files/ampersand_escape.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
message: "Some <code>"
})
message: 'Some <code>'
});

+ 1
- 1
test/_files/apostrophe.js Прегледај датотеку

@@ -1,4 +1,4 @@
({ ({
'apos': "'", 'apos': "'",
'control': 'X' 'control': 'X'
})
});

+ 1
- 1
test/_files/array_of_strings.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
array_of_strings: ['hello', 'world'] array_of_strings: ['hello', 'world']
})
});

+ 1
- 1
test/_files/avoids_obj_prototype_in_view_cache.js Прегледај датотеку

@@ -1,4 +1,4 @@
({ ({
valueOf: 'Avoids methods', valueOf: 'Avoids methods',
watch: 'in Object.prototype' watch: 'in Object.prototype'
})
});

+ 2
- 2
test/_files/backslashes.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
value: "\\abc"
})
value: '\\abc'
});

+ 2
- 2
test/_files/bug_11_eating_whitespace.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
tag: "yo"
})
tag: 'yo'
});

+ 1
- 1
test/_files/bug_length_property.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
length: 'hello' length: 'hello'
})
});

+ 3
- 3
test/_files/changing_delimiters.js Прегледај датотеку

@@ -1,4 +1,4 @@
({ ({
"foo": "foooooooooooooo",
"bar": "<b>bar!</b>"
})
'foo': 'foooooooooooooo',
'bar': '<b>bar!</b>'
});

+ 4
- 4
test/_files/check_falsy.js Прегледај датотеку

@@ -1,7 +1,7 @@
({ ({
number: function(text, render) {
return function(text, render) {
number: function (text, render) {
return function (text, render) {
return +render(text); return +render(text);
}
};
} }
})
});

+ 2
- 2
test/_files/comments.js Прегледај датотеку

@@ -1,5 +1,5 @@
({ ({
title: function () { title: function () {
return "A Comedy of Errors";
return 'A Comedy of Errors';
} }
})
});

+ 6
- 6
test/_files/complex.js Прегледај датотеку

@@ -1,14 +1,14 @@
({ ({
header: function () { header: function () {
return "Colors";
return 'Colors';
}, },
item: [ item: [
{name: "red", current: true, url: "#Red"},
{name: "green", current: false, url: "#Green"},
{name: "blue", current: false, url: "#Blue"}
{name: 'red', current: true, url: '#Red'},
{name: 'green', current: false, url: '#Green'},
{name: 'blue', current: false, url: '#Blue'}
], ],
link: function () { link: function () {
return this["current"] !== true;
return this['current'] !== true;
}, },
list: function () { list: function () {
return this.item.length !== 0; return this.item.length !== 0;
@@ -16,4 +16,4 @@
empty: function () { empty: function () {
return this.item.length === 0; return this.item.length === 0;
} }
})
});

+ 5
- 5
test/_files/context_lookup.js Прегледај датотеку

@@ -1,8 +1,8 @@
({ ({
"outer": {
"id": 1,
"second": {
"nothing": 2
'outer': {
'id': 1,
'second': {
'nothing': 2
} }
} }
})
});

+ 5
- 5
test/_files/delimiters.js Прегледај датотеку

@@ -1,6 +1,6 @@
({ ({
first: "It worked the first time.",
second: "And it worked the second time.",
third: "Then, surprisingly, it worked the third time.",
fourth: "Fourth time also fine!."
})
first: 'It worked the first time.',
second: 'And it worked the second time.',
third: 'Then, surprisingly, it worked the third time.',
fourth: 'Fourth time also fine!.'
});

+ 1
- 1
test/_files/disappearing_whitespace.js Прегледај датотеку

@@ -1,4 +1,4 @@
({ ({
bedrooms: true, bedrooms: true,
total: 1 total: 1
})
});

+ 5
- 5
test/_files/dot_notation.js Прегледај датотеку

@@ -1,6 +1,6 @@
({ ({
name: "A Book",
authors: ["John Power", "Jamie Walsh"],
name: 'A Book',
authors: ['John Power', 'Jamie Walsh'],
price: { price: {
value: 200, value: 200,
vat: function () { vat: function () {
@@ -13,12 +13,12 @@
}, },
availability: { availability: {
status: true, status: true,
text: "In Stock"
text: 'In Stock'
}, },
// And now, some truthy false values // And now, some truthy false values
truthy: { truthy: {
zero: 0, zero: 0,
notTrue: false notTrue: false
}, },
singletonList: [{singletonItem: "singleton item"}]
})
singletonList: [{singletonItem: 'singleton item'}]
});

+ 3
- 3
test/_files/double_render.js Прегледај датотеку

@@ -1,5 +1,5 @@
({ ({
foo: true, foo: true,
bar: "{{win}}",
win: "FAIL"
})
bar: '{{win}}',
win: 'FAIL'
});

+ 1
- 1
test/_files/empty_list.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
jobs: [] jobs: []
})
});

+ 1
- 1
test/_files/empty_sections.js Прегледај датотеку

@@ -1 +1 @@
({})
({});

+ 3
- 3
test/_files/empty_string.js Прегледај датотеку

@@ -1,6 +1,6 @@
({ ({
description: "That is all!",
description: 'That is all!',
child: { child: {
description: ""
description: ''
} }
})
});

+ 1
- 1
test/_files/empty_template.js Прегледај датотеку

@@ -1 +1 @@
({})
({});

+ 1
- 1
test/_files/error_not_found.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
bar: 2 bar: 2
})
});

+ 2
- 2
test/_files/escaped.js Прегледај датотеку

@@ -1,7 +1,7 @@
({ ({
title: function () { title: function () {
return "Bear > Shark";
return 'Bear > Shark';
}, },
symbol: null, symbol: null,
entities: "&quot; \"'<>`=/" entities: "&quot; \"'<>`=/"
})
});

+ 7
- 7
test/_files/falsy.js Прегледај датотеку

@@ -1,8 +1,8 @@
({ ({
"emptyString": "",
"emptyArray": [],
"zero": 0,
"null": null,
"undefined": undefined,
"NaN": 0/0
})
'emptyString': '',
'emptyArray': [],
'zero': 0,
'null': null,
'undefined': undefined,
'NaN': 0/0
});

+ 8
- 8
test/_files/falsy_array.js Прегледај датотеку

@@ -1,10 +1,10 @@
({ ({
"list": [
["", "emptyString"],
[[], "emptyArray"],
[0, "zero"],
[null, "null"],
[undefined, "undefined"],
[0/0, "NaN"]
'list': [
['', 'emptyString'],
[[], 'emptyArray'],
[0, 'zero'],
[null, 'null'],
[undefined, 'undefined'],
[0/0, 'NaN']
] ]
})
});

+ 1
- 1
test/_files/grandparent_context.js Прегледај датотеку

@@ -16,4 +16,4 @@
] ]
} }
] ]
})
});

+ 4
- 4
test/_files/higher_order_sections.js Прегледај датотеку

@@ -1,9 +1,9 @@
({ ({
name: "Tater",
helper: "To tinker?",
name: 'Tater',
helper: 'To tinker?',
bolder: function () { bolder: function () {
return function (text, render) { return function (text, render) {
return text + ' => <b>' + render(text) + '</b> ' + this.helper; return text + ' => <b>' + render(text) + '</b> ' + this.helper;
}
};
} }
})
});

+ 1
- 1
test/_files/implicit_iterator.js Прегледај датотеку

@@ -5,4 +5,4 @@
name: 'janl' name: 'janl'
} }
} }
})
});

+ 2
- 2
test/_files/included_tag.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
html: "I like {{mustache}}"
})
html: 'I like {{mustache}}'
});

+ 2
- 2
test/_files/inverted_section.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
"repos": []
})
'repos': []
});

+ 3
- 3
test/_files/keys_with_questionmarks.js Прегледај датотеку

@@ -1,5 +1,5 @@
({ ({
"person?": {
name: "Jon"
'person?': {
name: 'Jon'
} }
})
});

+ 1
- 1
test/_files/malicious_template.js Прегледај датотеку

@@ -1 +1 @@
({})
({});

+ 1
- 1
test/_files/multiline_comment.js Прегледај датотеку

@@ -1 +1 @@
({})
({});

+ 1
- 1
test/_files/nested_dot.js Прегледај датотеку

@@ -1 +1 @@
({ name: 'Bruno' })
({ name: 'Bruno' });

+ 1
- 1
test/_files/nested_iterating.js Прегледај датотеку

@@ -5,4 +5,4 @@
bar: 'bar' bar: 'bar'
}] }]
}] }]
})
});

+ 1
- 1
test/_files/nesting.js Прегледај датотеку

@@ -4,4 +4,4 @@
{a: {b: 2}}, {a: {b: 2}},
{a: {b: 3}} {a: {b: 3}}
] ]
})
});

+ 1
- 1
test/_files/nesting_same_name.js Прегледај датотеку

@@ -5,4 +5,4 @@
items: [1, 2, 3, 4] items: [1, 2, 3, 4]
} }
] ]
})
});

+ 8
- 8
test/_files/null_lookup_array.js Прегледај датотеку

@@ -1,9 +1,9 @@
({ ({
"name": "David",
"twitter": "@dasilvacontin",
"farray": [
["Flor", "@florrts"],
["Miquel", null],
["Chris", undefined]
]
})
'name': 'David',
'twitter': '@dasilvacontin',
'farray': [
['Flor', '@florrts'],
['Miquel', null],
['Chris', undefined]
]
});

+ 20
- 20
test/_files/null_lookup_object.js Прегледај датотеку

@@ -1,31 +1,31 @@
({ ({
"name": "David",
"twitter": "@dasilvacontin",
"fobject": [
'name': 'David',
'twitter': '@dasilvacontin',
'fobject': [
{ {
"name": "Flor",
"twitter": "@florrts"
'name': 'Flor',
'twitter': '@florrts'
}, },
{ {
"name": "Miquel",
"twitter": null
'name': 'Miquel',
'twitter': null
}, },
{ {
"name": "Chris",
"twitter": undefined
'name': 'Chris',
'twitter': undefined
} }
], ],
"favorites": {
"color": "blue",
"president": "Bush",
"show": "Futurama"
'favorites': {
'color': 'blue',
'president': 'Bush',
'show': 'Futurama'
}, },
"mascot": {
"name": "Squid",
"favorites": {
"color": "orange",
"president": undefined,
"show": null
'mascot': {
'name': 'Squid',
'favorites': {
'color': 'orange',
'president': undefined,
'show': null
} }
} }
})
});

+ 3
- 3
test/_files/null_string.js Прегледај датотеку

@@ -1,10 +1,10 @@
({ ({
name: "Elise",
name: 'Elise',
glytch: true, glytch: true,
binary: false, binary: false,
value: null, value: null,
undef: undefined, undef: undefined,
numeric: function() {
numeric: function () {
return NaN; return NaN;
} }
})
});

+ 1
- 1
test/_files/null_view.js Прегледај датотеку

@@ -1,4 +1,4 @@
({ ({
name: 'Joe', name: 'Joe',
friends: null friends: null
})
});

+ 1
- 1
test/_files/partial_array.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
array: ['1', '2', '3', '4'] array: ['1', '2', '3', '4']
})
});

+ 1
- 1
test/_files/partial_array_of_partials.js Прегледај датотеку

@@ -5,4 +5,4 @@
{i: '3'}, {i: '3'},
{i: '4'} {i: '4'}
] ]
})
});

+ 1
- 1
test/_files/partial_array_of_partials_implicit.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
numbers: ['1', '2', '3', '4'] numbers: ['1', '2', '3', '4']
})
});

+ 1
- 1
test/_files/partial_empty.js Прегледај датотеку

@@ -1,3 +1,3 @@
({ ({
foo: 1 foo: 1
})
});

+ 3
- 3
test/_files/partial_template.js Прегледај датотеку

@@ -1,6 +1,6 @@
({ ({
title: function () { title: function () {
return "Welcome";
return 'Welcome';
}, },
again: "Goodbye"
})
again: 'Goodbye'
});

+ 4
- 4
test/_files/partial_view.js Прегледај датотеку

@@ -1,14 +1,14 @@
({ ({
greeting: function () { greeting: function () {
return "Welcome";
return 'Welcome';
}, },
farewell: function () { farewell: function () {
return "Fair enough, right?";
return 'Fair enough, right?';
}, },
name: "Chris",
name: 'Chris',
value: 10000, value: 10000,
taxed_value: function () { taxed_value: function () {
return this.value - (this.value * 0.4); return this.value - (this.value * 0.4);
}, },
in_ca: true in_ca: true
})
});

+ 4
- 4
test/_files/partial_whitespace.js Прегледај датотеку

@@ -1,14 +1,14 @@
({ ({
greeting: function () { greeting: function () {
return "Welcome";
return 'Welcome';
}, },
farewell: function () { farewell: function () {
return "Fair enough, right?";
return 'Fair enough, right?';
}, },
name: "Chris",
name: 'Chris',
value: 10000, value: 10000,
taxed_value: function () { taxed_value: function () {
return this.value - (this.value * 0.4); return this.value - (this.value * 0.4);
}, },
in_ca: true in_ca: true
})
});

+ 1
- 1
test/_files/recursion_with_same_names.js Прегледај датотеку

@@ -5,4 +5,4 @@
{name: 't1', index: 0}, {name: 't1', index: 0},
{name: 't2', index: 1} {name: 't2', index: 1}
] ]
})
});

+ 1
- 1
test/_files/reuse_of_enumerables.js Прегледај датотеку

@@ -3,4 +3,4 @@
{name: 't1', index: 0}, {name: 't1', index: 0},
{name: 't2', index: 1} {name: 't2', index: 1}
] ]
})
});

+ 1
- 1
test/_files/section_as_context.js Прегледај датотеку

@@ -7,4 +7,4 @@
{label: 'listitem2'} {label: 'listitem2'}
] ]
} }
})
});

+ 5
- 5
test/_files/section_functions_in_partials.js Прегледај датотеку

@@ -1,7 +1,7 @@
({ ({
bold: function(){
return function(text, render) {
return "<b>" + render(text) + "</b>";
}
bold: function (){
return function (text, render) {
return '<b>' + render(text) + '</b>';
};
} }
})
});

+ 2
- 2
test/_files/simple.js Прегледај датотеку

@@ -1,8 +1,8 @@
({ ({
name: "Chris",
name: 'Chris',
value: 10000, value: 10000,
taxed_value: function () { taxed_value: function () {
return this.value - (this.value * 0.4); return this.value - (this.value * 0.4);
}, },
in_ca: true in_ca: true
})
});

+ 1
- 1
test/_files/string_as_context.js Прегледај датотеку

@@ -1,4 +1,4 @@
({ ({
a_string: 'aa', a_string: 'aa',
a_list: ['a','b','c'] a_list: ['a','b','c']
})
});

+ 3
- 3
test/_files/two_in_a_row.js Прегледај датотеку

@@ -1,4 +1,4 @@
({ ({
name: "Joe",
greeting: "Welcome"
})
name: 'Joe',
greeting: 'Welcome'
});

+ 1
- 1
test/_files/two_sections.js Прегледај датотеку

@@ -1 +1 @@
({})
({});

+ 2
- 2
test/_files/unescaped.js Прегледај датотеку

@@ -1,6 +1,6 @@
({ ({
title: function () { title: function () {
return "Bear > Shark";
return 'Bear > Shark';
}, },
symbol: null symbol: null
})
});

+ 7
- 7
test/_files/uses_props_from_view_prototype.js Прегледај датотеку

@@ -1,9 +1,9 @@
var Aaa = (function () { var Aaa = (function () {
function Aaa(x, y) {
function Aaa (x, y) {
this.x = x; this.x = x;
this._y = y; this._y = y;
} }
Object.defineProperty(Aaa.prototype, "y", {
Object.defineProperty(Aaa.prototype, 'y', {
get: function () { get: function () {
return this._y; return this._y;
}, },
@@ -16,15 +16,15 @@ var Aaa = (function () {
return Aaa; return Aaa;
})(); })();
var Bbb = (function () { var Bbb = (function () {
function Bbb() {
function Bbb () {
} }
return Bbb; return Bbb;
})(); })();


var b = new Bbb(); var b = new Bbb();
b.item = new Aaa("0", "00");
b.item = new Aaa('0', '00');
b.items = []; b.items = [];
b.items.push({ a: new Aaa("1", "2") });
b.items.push({ a: new Aaa("3", "4") });
b.items.push({ a: new Aaa('1', '2') });
b.items.push({ a: new Aaa('3', '4') });


(b)
(b);

+ 3
- 3
test/_files/whitespace.js Прегледај датотеку

@@ -1,4 +1,4 @@
({ ({
tag1: "Hello",
tag2: "World"
})
tag1: 'Hello',
tag2: 'World'
});

+ 1
- 1
test/_files/zero_view.js Прегледај датотеку

@@ -1 +1 @@
({ nums: [0, 1, 2] })
({ nums: [0, 1, 2] });

+ 32
- 32
test/cli-test.js Прегледај датотеку

@@ -8,9 +8,9 @@ var cliTxt = path.resolve(_files, 'cli.txt');
var cliPartialsTxt = path.resolve(_files, 'cli_with_partials.txt'); var cliPartialsTxt = path.resolve(_files, 'cli_with_partials.txt');
var moduleVersion = require('../package').version; var moduleVersion = require('../package').version;


function changeForOS(command) {
function changeForOS (command) {


if(process.platform === 'win32') {
if (process.platform === 'win32') {
return command return command
.replace(/bin\/mustache/g, 'node bin\\mustache') .replace(/bin\/mustache/g, 'node bin\\mustache')
.replace(/\bcat\b/g, 'type') .replace(/\bcat\b/g, 'type')
@@ -20,7 +20,7 @@ function changeForOS(command) {
return command; return command;
} }


function exec() {
function exec () {
arguments[0] = changeForOS(arguments[0]); arguments[0] = changeForOS(arguments[0]);
return child_process.exec.apply(child_process, arguments); return child_process.exec.apply(child_process, arguments);
} }
@@ -29,37 +29,37 @@ describe('Mustache CLI', function () {


var expectedOutput; var expectedOutput;


it('writes syntax hints into stderr when runned with wrong number of arguments', function(done) {
exec('bin/mustache', function(err, stdout, stderr) {
it('writes syntax hints into stderr when runned with wrong number of arguments', function (done) {
exec('bin/mustache', function (err, stdout, stderr) {
assert.notEqual(stderr.indexOf('Syntax'), -1); assert.notEqual(stderr.indexOf('Syntax'), -1);
done(); done();
}); });
}); });


it('writes hints about JSON parsing errors when given invalid JSON', function(done) {
exec('echo {name:"lebron"} | bin/mustache - test/_files/cli.mustache', function(err, stdout, stderr) {
it('writes hints about JSON parsing errors when given invalid JSON', function (done) {
exec('echo {name:"lebron"} | bin/mustache - test/_files/cli.mustache', function (err, stdout, stderr) {
assert.notEqual(stderr.indexOf('Shooot, could not parse view as JSON'), -1); assert.notEqual(stderr.indexOf('Shooot, could not parse view as JSON'), -1);
done(); done();
}); });
}); });


it('writes module version into stdout when runned with --version', function(done){
exec('bin/mustache --version', function(err, stdout, stderr) {
it('writes module version into stdout when runned with --version', function (done){
exec('bin/mustache --version', function (err, stdout, stderr) {
assert.notEqual(stdout.indexOf(moduleVersion), -1); assert.notEqual(stdout.indexOf(moduleVersion), -1);
done(); done();
}); });
}); });


it('writes module version into stdout when runned with -v', function(done){
exec('bin/mustache -v', function(err, stdout, stderr) {
it('writes module version into stdout when runned with -v', function (done){
exec('bin/mustache -v', function (err, stdout, stderr) {
assert.notEqual(stdout.indexOf(moduleVersion), -1); assert.notEqual(stdout.indexOf(moduleVersion), -1);
done(); done();
}); });
}); });


describe("without partials", function(){
before(function(done) {
fs.readFile(cliTxt, function onFsEnd(err, data) {
describe('without partials', function (){
before(function (done) {
fs.readFile(cliTxt, function onFsEnd (err, data) {
if (err) return done(err); if (err) return done(err);


expectedOutput = data.toString(); expectedOutput = data.toString();
@@ -67,8 +67,8 @@ describe('Mustache CLI', function () {
}); });
}); });


it('writes rendered template into stdout when successfull', function(done) {
exec('bin/mustache test/_files/cli.json test/_files/cli.mustache', function(err, stdout, stderr) {
it('writes rendered template into stdout when successfull', function (done) {
exec('bin/mustache test/_files/cli.json test/_files/cli.mustache', function (err, stdout, stderr) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(stderr, ''); assert.equal(stderr, '');
assert.equal(stdout, expectedOutput); assert.equal(stdout, expectedOutput);
@@ -76,9 +76,9 @@ describe('Mustache CLI', function () {
}); });
}); });


it('writes rendered template into the file specified by the third argument', function(done) {
it('writes rendered template into the file specified by the third argument', function (done) {
var outputFile = 'test/_files/cli_output.txt'; var outputFile = 'test/_files/cli_output.txt';
exec('bin/mustache test/_files/cli.json test/_files/cli.mustache ' + outputFile, function(err, stdout, stderr) {
exec('bin/mustache test/_files/cli.json test/_files/cli.mustache ' + outputFile, function (err, stdout, stderr) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(stderr, ''); assert.equal(stderr, '');
assert.equal(stdout, ''); assert.equal(stdout, '');
@@ -88,8 +88,8 @@ describe('Mustache CLI', function () {
}); });
}); });


it('reads view data from stdin when first argument equals "-"', function(done){
exec('cat test/_files/cli.json | bin/mustache - test/_files/cli.mustache', function(err, stdout, stderr) {
it('reads view data from stdin when first argument equals "-"', function (done){
exec('cat test/_files/cli.json | bin/mustache - test/_files/cli.mustache', function (err, stdout, stderr) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(stderr, ''); assert.equal(stderr, '');
assert.equal(stdout, expectedOutput); assert.equal(stdout, expectedOutput);
@@ -97,15 +97,15 @@ describe('Mustache CLI', function () {
}); });
}); });


it('writes it couldnt find template into stderr when second argument doesnt resolve to a file', function(done) {
exec('bin/mustache test/_files/cli.json test/_files/non-existing-template.mustache', function(err, stdout, stderr) {
it('writes it couldnt find template into stderr when second argument doesnt resolve to a file', function (done) {
exec('bin/mustache test/_files/cli.json test/_files/non-existing-template.mustache', function (err, stdout, stderr) {
assert.isOk(/Could not find file: .+non-existing-template\.mustache/.test(stderr)); assert.isOk(/Could not find file: .+non-existing-template\.mustache/.test(stderr));
done(); done();
}); });
}); });


it('writes it couldnt find view into stderr when first argument doesnt resolve to a file', function(done) {
exec('bin/mustache test/_files/non-existing-view.json test/_files/cli.mustache', function(err, stdout, stderr) {
it('writes it couldnt find view into stderr when first argument doesnt resolve to a file', function (done) {
exec('bin/mustache test/_files/non-existing-view.json test/_files/cli.mustache', function (err, stdout, stderr) {
assert.isOk(/Could not find file: .+non-existing-view\.json/.test(stderr)); assert.isOk(/Could not find file: .+non-existing-view\.json/.test(stderr));
done(); done();
}); });
@@ -113,9 +113,9 @@ describe('Mustache CLI', function () {
}); });




describe("with partials", function(){
before(function(done) {
fs.readFile(cliPartialsTxt, function onFsEnd(err, data) {
describe('with partials', function (){
before(function (done) {
fs.readFile(cliPartialsTxt, function onFsEnd (err, data) {
if (err) return done(err); if (err) return done(err);


expectedOutput = data.toString(); expectedOutput = data.toString();
@@ -123,8 +123,8 @@ describe('Mustache CLI', function () {
}); });
}); });


it('writes rendered template with partials into stdout', function(done) {
exec('bin/mustache test/_files/cli_with_partials.json test/_files/cli_with_partials.mustache -p test/_files/cli.mustache -p test/_files/comments.mustache', function(err, stdout, stderr) {
it('writes rendered template with partials into stdout', function (done) {
exec('bin/mustache test/_files/cli_with_partials.json test/_files/cli_with_partials.mustache -p test/_files/cli.mustache -p test/_files/comments.mustache', function (err, stdout, stderr) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(stderr, ''); assert.equal(stderr, '');
assert.equal(stdout, expectedOutput); assert.equal(stdout, expectedOutput);
@@ -132,13 +132,13 @@ describe('Mustache CLI', function () {
}); });
}); });


it('writes rendered template with partials when partials args before required args', function(done) {
exec('bin/mustache -p test/_files/cli.mustache -p test/_files/comments.mustache test/_files/cli_with_partials.json test/_files/cli_with_partials.mustache', function(err, stdout, stderr) {
it('writes rendered template with partials when partials args before required args', function (done) {
exec('bin/mustache -p test/_files/cli.mustache -p test/_files/comments.mustache test/_files/cli_with_partials.json test/_files/cli_with_partials.mustache', function (err, stdout, stderr) {
assert.equal(err, null); assert.equal(err, null);
assert.equal(stderr, ''); assert.equal(stderr, '');
assert.equal(stdout, expectedOutput); assert.equal(stdout, expectedOutput);
done(); done();
}); });
}); });
})
});
}); });

+ 7
- 7
test/mustache-spec-test.js Прегледај датотеку

@@ -42,7 +42,7 @@ var noSkip = process.env.NOSKIP;
var fileToRun = process.env.TEST; var fileToRun = process.env.TEST;


// Mustache should work on node 0.6 that doesn't have fs.existsSync // Mustache should work on node 0.6 that doesn't have fs.existsSync
function existsDir(path) {
function existsDir (path) {
try { try {
return fs.statSync(path).isDirectory(); return fs.statSync(path).isDirectory();
} catch (x) { } catch (x) {
@@ -63,21 +63,21 @@ if (fileToRun) {
specFiles = []; specFiles = [];
} }


function getSpecs(specArea) {
function getSpecs (specArea) {
return JSON.parse(fs.readFileSync(path.join(specsDir, specArea + '.' + 'json'), 'utf8')); return JSON.parse(fs.readFileSync(path.join(specsDir, specArea + '.' + 'json'), 'utf8'));
} }


describe('Mustache spec compliance', function() {
describe('Mustache spec compliance', function () {
beforeEach(function () { beforeEach(function () {
Mustache.clearCache(); Mustache.clearCache();
}); });


specFiles.forEach(function(specArea) {
describe('- ' + specArea + ':', function() {
specFiles.forEach(function (specArea) {
describe('- ' + specArea + ':', function () {
var specs = getSpecs(specArea); var specs = getSpecs(specArea);
specs.tests.forEach(function(test) {
specs.tests.forEach(function (test) {
var it_ = (!noSkip && skipTests[specArea] && skipTests[specArea].indexOf(test.name) >= 0) ? it.skip : it; var it_ = (!noSkip && skipTests[specArea] && skipTests[specArea].indexOf(test.name) >= 0) ? it.skip : it;
it_(test.name + ' - ' + test.desc, function() {
it_(test.name + ' - ' + test.desc, function () {
if (test.data.lambda && test.data.lambda.__tag__ === 'code') if (test.data.lambda && test.data.lambda.__tag__ === 'code')
test.data.lambda = eval('(function() { return ' + test.data.lambda.js + '; })'); test.data.lambda = eval('(function() { return ' + test.data.lambda.js + '; })');
var output = Mustache.render(test.template, test.data, test.partials); var output = Mustache.render(test.template, test.data, test.partials);


+ 9
- 9
test/parse-test.js Прегледај датотеку

@@ -107,27 +107,27 @@ describe('Mustache.parse', function () {
}); });
}); });


describe('when parsing a template without tags specified followed by the same template with tags specified', function() {
it('returns different tokens for the latter parse', function() {
var template = "{{foo}}[bar]";
describe('when parsing a template without tags specified followed by the same template with tags specified', function () {
it('returns different tokens for the latter parse', function () {
var template = '{{foo}}[bar]';
var parsedWithBraces = Mustache.parse(template); var parsedWithBraces = Mustache.parse(template);
var parsedWithBrackets = Mustache.parse(template, ['[', ']']); var parsedWithBrackets = Mustache.parse(template, ['[', ']']);
assert.notDeepEqual(parsedWithBrackets, parsedWithBraces); assert.notDeepEqual(parsedWithBrackets, parsedWithBraces);
}); });
}); });


describe('when parsing a template with tags specified followed by the same template with different tags specified', function() {
it('returns different tokens for the latter parse', function() {
var template = "(foo)[bar]";
describe('when parsing a template with tags specified followed by the same template with different tags specified', function () {
it('returns different tokens for the latter parse', function () {
var template = '(foo)[bar]';
var parsedWithParens = Mustache.parse(template, ['(', ')']); var parsedWithParens = Mustache.parse(template, ['(', ')']);
var parsedWithBrackets = Mustache.parse(template, ['[', ']']); var parsedWithBrackets = Mustache.parse(template, ['[', ']']);
assert.notDeepEqual(parsedWithBrackets, parsedWithParens); assert.notDeepEqual(parsedWithBrackets, parsedWithParens);
}); });
}); });


describe('when parsing a template after already having parsed that template with a different Mustache.tags', function() {
it('returns different tokens for the latter parse', function() {
var template = "{{foo}}[bar]";
describe('when parsing a template after already having parsed that template with a different Mustache.tags', function () {
it('returns different tokens for the latter parse', function () {
var template = '{{foo}}[bar]';
var parsedWithBraces = Mustache.parse(template); var parsedWithBraces = Mustache.parse(template);


var oldTags = Mustache.tags; var oldTags = Mustache.tags;


+ 5
- 5
test/render-helper.js Прегледај датотеку

@@ -3,7 +3,7 @@ var path = require('path');


var _files = path.join(__dirname, '_files'); var _files = path.join(__dirname, '_files');


function getContents(testName, ext) {
function getContents (testName, ext) {
try { try {
return fs.readFileSync(path.join(_files, testName + '.' + ext), 'utf8'); return fs.readFileSync(path.join(_files, testName + '.' + ext), 'utf8');
} catch (ex) { } catch (ex) {
@@ -11,13 +11,13 @@ function getContents(testName, ext) {
} }
} }


function getView(testName) {
function getView (testName) {
var view = getContents(testName, 'js'); var view = getContents(testName, 'js');
if (!view) throw new Error('Cannot find view for test "' + testName + '"'); if (!view) throw new Error('Cannot find view for test "' + testName + '"');
return view; return view;
} }


function getPartial(testName) {
function getPartial (testName) {
try { try {
return getContents(testName, 'partial'); return getContents(testName, 'partial');
} catch (error) { } catch (error) {
@@ -40,7 +40,7 @@ if (testToRun) {
}); });
} }


function getTest(testName) {
function getTest (testName) {
return { return {
name: testName, name: testName,
view: getView(testName), view: getView(testName),
@@ -50,6 +50,6 @@ function getTest(testName) {
}; };
} }


exports.getTests = function getTests() {
exports.getTests = function getTests () {
return testNames.map(getTest); return testNames.map(getTest);
}; };

+ 3
- 3
test/render-test.js Прегледај датотеку

@@ -40,7 +40,7 @@ describe('Mustache.render', function () {
assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['[[', ']]']), 'foobar<<placeholder>>'); assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['[[', ']]']), 'foobar<<placeholder>>');
}); });


it('does not mutate Mustache.tags when given tags argument', function() {
it('does not mutate Mustache.tags when given tags argument', function () {
var correctMustacheTags = ['{{', '}}']; var correctMustacheTags = ['{{', '}}'];
Mustache.tags = correctMustacheTags; Mustache.tags = correctMustacheTags;


@@ -56,8 +56,8 @@ describe('Mustache.render', function () {
}, ['<%', '%>']); }, ['<%', '%>']);


assert.equal(output, 'Santa Claus'); assert.equal(output, 'Santa Claus');
})
})
});
});


tests.forEach(function (test) { tests.forEach(function (test) {
var view = eval(test.view); var view = eval(test.view);


Loading…
Откажи
Сачувај