From ac04d6a54ba0fdd5fdad0fb9fd57b3018f7e9481 Mon Sep 17 00:00:00 2001 From: Phillip Johnsen Date: Mon, 8 Jul 2019 21:59:05 +0200 Subject: [PATCH] Start linting all test/ files as part of test script 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. --- package.json | 2 +- test/.eslintrc | 6 ++ test/_files/ampersand_escape.js | 4 +- test/_files/apostrophe.js | 2 +- test/_files/array_of_strings.js | 2 +- .../avoids_obj_prototype_in_view_cache.js | 2 +- test/_files/backslashes.js | 4 +- test/_files/bug_11_eating_whitespace.js | 4 +- test/_files/bug_length_property.js | 2 +- test/_files/changing_delimiters.js | 6 +- test/_files/check_falsy.js | 8 +-- test/_files/comments.js | 4 +- test/_files/complex.js | 12 ++-- test/_files/context_lookup.js | 10 +-- test/_files/delimiters.js | 10 +-- test/_files/disappearing_whitespace.js | 2 +- test/_files/dot_notation.js | 10 +-- test/_files/double_render.js | 6 +- test/_files/empty_list.js | 2 +- test/_files/empty_sections.js | 2 +- test/_files/empty_string.js | 6 +- test/_files/empty_template.js | 2 +- test/_files/error_not_found.js | 2 +- test/_files/escaped.js | 4 +- test/_files/falsy.js | 14 ++-- test/_files/falsy_array.js | 16 ++--- test/_files/grandparent_context.js | 2 +- test/_files/higher_order_sections.js | 8 +-- test/_files/implicit_iterator.js | 2 +- test/_files/included_tag.js | 4 +- test/_files/inverted_section.js | 4 +- test/_files/keys_with_questionmarks.js | 6 +- test/_files/malicious_template.js | 2 +- test/_files/multiline_comment.js | 2 +- test/_files/nested_dot.js | 2 +- test/_files/nested_iterating.js | 2 +- test/_files/nesting.js | 2 +- test/_files/nesting_same_name.js | 2 +- test/_files/null_lookup_array.js | 16 ++--- test/_files/null_lookup_object.js | 40 ++++++------ test/_files/null_string.js | 6 +- test/_files/null_view.js | 2 +- test/_files/partial_array.js | 2 +- test/_files/partial_array_of_partials.js | 2 +- .../partial_array_of_partials_implicit.js | 2 +- test/_files/partial_empty.js | 2 +- test/_files/partial_template.js | 6 +- test/_files/partial_view.js | 8 +-- test/_files/partial_whitespace.js | 8 +-- test/_files/recursion_with_same_names.js | 2 +- test/_files/reuse_of_enumerables.js | 2 +- test/_files/section_as_context.js | 2 +- test/_files/section_functions_in_partials.js | 10 +-- test/_files/simple.js | 4 +- test/_files/string_as_context.js | 2 +- test/_files/two_in_a_row.js | 6 +- test/_files/two_sections.js | 2 +- test/_files/unescaped.js | 4 +- test/_files/uses_props_from_view_prototype.js | 14 ++-- test/_files/whitespace.js | 6 +- test/_files/zero_view.js | 2 +- test/cli-test.js | 64 +++++++++---------- test/mustache-spec-test.js | 14 ++-- test/parse-test.js | 18 +++--- test/render-helper.js | 10 +-- test/render-test.js | 6 +- 66 files changed, 225 insertions(+), 219 deletions(-) create mode 100644 test/.eslintrc diff --git a/package.json b/package.json index d7d51f0ed..c7dfffcd3 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "npm": ">=1.4.0" }, "scripts": { - "pretest": "eslint mustache.js bin/mustache", + "pretest": "eslint mustache.js bin/mustache test/**/*.js", "test": "mocha --reporter spec test/*-test.js", "test-render": "mocha --reporter spec test/render-test", "pre-test-browser": "node test/create-browser-suite.js", diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 000000000..9c7852322 --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,6 @@ +{ + "extends": "../.eslintrc", + "rules": { + "func-names": 0 + } +} diff --git a/test/_files/ampersand_escape.js b/test/_files/ampersand_escape.js index df6409fa1..07da0c783 100644 --- a/test/_files/ampersand_escape.js +++ b/test/_files/ampersand_escape.js @@ -1,3 +1,3 @@ ({ - message: "Some " -}) + message: 'Some ' +}); diff --git a/test/_files/apostrophe.js b/test/_files/apostrophe.js index 183c6d540..7acfce057 100644 --- a/test/_files/apostrophe.js +++ b/test/_files/apostrophe.js @@ -1,4 +1,4 @@ ({ 'apos': "'", 'control': 'X' -}) +}); diff --git a/test/_files/array_of_strings.js b/test/_files/array_of_strings.js index 6926612f5..6eb9e63e9 100644 --- a/test/_files/array_of_strings.js +++ b/test/_files/array_of_strings.js @@ -1,3 +1,3 @@ ({ array_of_strings: ['hello', 'world'] -}) +}); diff --git a/test/_files/avoids_obj_prototype_in_view_cache.js b/test/_files/avoids_obj_prototype_in_view_cache.js index 2ab58cdb7..ae88d2bc8 100644 --- a/test/_files/avoids_obj_prototype_in_view_cache.js +++ b/test/_files/avoids_obj_prototype_in_view_cache.js @@ -1,4 +1,4 @@ ({ valueOf: 'Avoids methods', watch: 'in Object.prototype' -}) +}); diff --git a/test/_files/backslashes.js b/test/_files/backslashes.js index 427acd9d2..0a5d84501 100644 --- a/test/_files/backslashes.js +++ b/test/_files/backslashes.js @@ -1,3 +1,3 @@ ({ - value: "\\abc" -}) + value: '\\abc' +}); diff --git a/test/_files/bug_11_eating_whitespace.js b/test/_files/bug_11_eating_whitespace.js index e41ccd15d..3a91f9608 100644 --- a/test/_files/bug_11_eating_whitespace.js +++ b/test/_files/bug_11_eating_whitespace.js @@ -1,3 +1,3 @@ ({ - tag: "yo" -}) + tag: 'yo' +}); diff --git a/test/_files/bug_length_property.js b/test/_files/bug_length_property.js index 74c483bbf..c63899e56 100644 --- a/test/_files/bug_length_property.js +++ b/test/_files/bug_length_property.js @@ -1,3 +1,3 @@ ({ length: 'hello' -}) +}); diff --git a/test/_files/changing_delimiters.js b/test/_files/changing_delimiters.js index b808f4c8b..0bb3b13e0 100644 --- a/test/_files/changing_delimiters.js +++ b/test/_files/changing_delimiters.js @@ -1,4 +1,4 @@ ({ - "foo": "foooooooooooooo", - "bar": "bar!" -}) + 'foo': 'foooooooooooooo', + 'bar': 'bar!' +}); diff --git a/test/_files/check_falsy.js b/test/_files/check_falsy.js index 5a599cab7..aeb742221 100644 --- a/test/_files/check_falsy.js +++ b/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); - } + }; } -}) +}); diff --git a/test/_files/comments.js b/test/_files/comments.js index f20b8b11c..af291cbe0 100644 --- a/test/_files/comments.js +++ b/test/_files/comments.js @@ -1,5 +1,5 @@ ({ title: function () { - return "A Comedy of Errors"; + return 'A Comedy of Errors'; } -}) +}); diff --git a/test/_files/complex.js b/test/_files/complex.js index 68a48093e..d6c3ae267 100644 --- a/test/_files/complex.js +++ b/test/_files/complex.js @@ -1,14 +1,14 @@ ({ header: function () { - return "Colors"; + return 'Colors'; }, 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 () { - return this["current"] !== true; + return this['current'] !== true; }, list: function () { return this.item.length !== 0; @@ -16,4 +16,4 @@ empty: function () { return this.item.length === 0; } -}) +}); diff --git a/test/_files/context_lookup.js b/test/_files/context_lookup.js index 8ce62999e..b9f891c27 100644 --- a/test/_files/context_lookup.js +++ b/test/_files/context_lookup.js @@ -1,8 +1,8 @@ ({ - "outer": { - "id": 1, - "second": { - "nothing": 2 + 'outer': { + 'id': 1, + 'second': { + 'nothing': 2 } } -}) +}); diff --git a/test/_files/delimiters.js b/test/_files/delimiters.js index 365d01e8e..b4c9f5075 100644 --- a/test/_files/delimiters.js +++ b/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!.' +}); diff --git a/test/_files/disappearing_whitespace.js b/test/_files/disappearing_whitespace.js index 973dd1c9c..1d2f392a4 100644 --- a/test/_files/disappearing_whitespace.js +++ b/test/_files/disappearing_whitespace.js @@ -1,4 +1,4 @@ ({ bedrooms: true, total: 1 -}) +}); diff --git a/test/_files/dot_notation.js b/test/_files/dot_notation.js index 955651fe6..8dbef438e 100644 --- a/test/_files/dot_notation.js +++ b/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: { value: 200, vat: function () { @@ -13,12 +13,12 @@ }, availability: { status: true, - text: "In Stock" + text: 'In Stock' }, // And now, some truthy false values truthy: { zero: 0, notTrue: false }, - singletonList: [{singletonItem: "singleton item"}] -}) + singletonList: [{singletonItem: 'singleton item'}] +}); diff --git a/test/_files/double_render.js b/test/_files/double_render.js index 28acb2c1a..d8ade03de 100644 --- a/test/_files/double_render.js +++ b/test/_files/double_render.js @@ -1,5 +1,5 @@ ({ foo: true, - bar: "{{win}}", - win: "FAIL" -}) + bar: '{{win}}', + win: 'FAIL' +}); diff --git a/test/_files/empty_list.js b/test/_files/empty_list.js index c0e115942..c40f6d81c 100644 --- a/test/_files/empty_list.js +++ b/test/_files/empty_list.js @@ -1,3 +1,3 @@ ({ jobs: [] -}) +}); diff --git a/test/_files/empty_sections.js b/test/_files/empty_sections.js index b4100a597..b3bf1ddb0 100644 --- a/test/_files/empty_sections.js +++ b/test/_files/empty_sections.js @@ -1 +1 @@ -({}) +({}); diff --git a/test/_files/empty_string.js b/test/_files/empty_string.js index be6e05876..59de15d2e 100644 --- a/test/_files/empty_string.js +++ b/test/_files/empty_string.js @@ -1,6 +1,6 @@ ({ - description: "That is all!", + description: 'That is all!', child: { - description: "" + description: '' } -}) +}); diff --git a/test/_files/empty_template.js b/test/_files/empty_template.js index b4100a597..b3bf1ddb0 100644 --- a/test/_files/empty_template.js +++ b/test/_files/empty_template.js @@ -1 +1 @@ -({}) +({}); diff --git a/test/_files/error_not_found.js b/test/_files/error_not_found.js index 10e470918..6dcb14fbe 100644 --- a/test/_files/error_not_found.js +++ b/test/_files/error_not_found.js @@ -1,3 +1,3 @@ ({ bar: 2 -}) +}); diff --git a/test/_files/escaped.js b/test/_files/escaped.js index 4276a39cd..8345ecbc1 100644 --- a/test/_files/escaped.js +++ b/test/_files/escaped.js @@ -1,7 +1,7 @@ ({ title: function () { - return "Bear > Shark"; + return 'Bear > Shark'; }, symbol: null, entities: "" \"'<>`=/" -}) +}); diff --git a/test/_files/falsy.js b/test/_files/falsy.js index ae9b9bf25..e3fd42255 100644 --- a/test/_files/falsy.js +++ b/test/_files/falsy.js @@ -1,8 +1,8 @@ ({ - "emptyString": "", - "emptyArray": [], - "zero": 0, - "null": null, - "undefined": undefined, - "NaN": 0/0 -}) \ No newline at end of file + 'emptyString': '', + 'emptyArray': [], + 'zero': 0, + 'null': null, + 'undefined': undefined, + 'NaN': 0/0 +}); \ No newline at end of file diff --git a/test/_files/falsy_array.js b/test/_files/falsy_array.js index f26530878..209c58965 100644 --- a/test/_files/falsy_array.js +++ b/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'] ] -}) \ No newline at end of file +}); \ No newline at end of file diff --git a/test/_files/grandparent_context.js b/test/_files/grandparent_context.js index 97dbfd398..4d304005f 100644 --- a/test/_files/grandparent_context.js +++ b/test/_files/grandparent_context.js @@ -16,4 +16,4 @@ ] } ] -}) +}); diff --git a/test/_files/higher_order_sections.js b/test/_files/higher_order_sections.js index bacb0a44a..6a4a3103d 100644 --- a/test/_files/higher_order_sections.js +++ b/test/_files/higher_order_sections.js @@ -1,9 +1,9 @@ ({ - name: "Tater", - helper: "To tinker?", + name: 'Tater', + helper: 'To tinker?', bolder: function () { return function (text, render) { return text + ' => ' + render(text) + ' ' + this.helper; - } + }; } -}) +}); diff --git a/test/_files/implicit_iterator.js b/test/_files/implicit_iterator.js index 2be2997e4..47a6b6876 100644 --- a/test/_files/implicit_iterator.js +++ b/test/_files/implicit_iterator.js @@ -5,4 +5,4 @@ name: 'janl' } } -}) +}); diff --git a/test/_files/included_tag.js b/test/_files/included_tag.js index eb032a42c..2dfc0c3b4 100644 --- a/test/_files/included_tag.js +++ b/test/_files/included_tag.js @@ -1,3 +1,3 @@ ({ - html: "I like {{mustache}}" -}) + html: 'I like {{mustache}}' +}); diff --git a/test/_files/inverted_section.js b/test/_files/inverted_section.js index f8f08fd26..40fcba870 100644 --- a/test/_files/inverted_section.js +++ b/test/_files/inverted_section.js @@ -1,3 +1,3 @@ ({ - "repos": [] -}) + 'repos': [] +}); diff --git a/test/_files/keys_with_questionmarks.js b/test/_files/keys_with_questionmarks.js index becd63102..345e97f6b 100644 --- a/test/_files/keys_with_questionmarks.js +++ b/test/_files/keys_with_questionmarks.js @@ -1,5 +1,5 @@ ({ - "person?": { - name: "Jon" + 'person?': { + name: 'Jon' } -}) +}); diff --git a/test/_files/malicious_template.js b/test/_files/malicious_template.js index b4100a597..b3bf1ddb0 100644 --- a/test/_files/malicious_template.js +++ b/test/_files/malicious_template.js @@ -1 +1 @@ -({}) +({}); diff --git a/test/_files/multiline_comment.js b/test/_files/multiline_comment.js index b4100a597..b3bf1ddb0 100644 --- a/test/_files/multiline_comment.js +++ b/test/_files/multiline_comment.js @@ -1 +1 @@ -({}) +({}); diff --git a/test/_files/nested_dot.js b/test/_files/nested_dot.js index 2c22f8e38..72493f69e 100644 --- a/test/_files/nested_dot.js +++ b/test/_files/nested_dot.js @@ -1 +1 @@ -({ name: 'Bruno' }) +({ name: 'Bruno' }); diff --git a/test/_files/nested_iterating.js b/test/_files/nested_iterating.js index 2708b2db5..333d92508 100644 --- a/test/_files/nested_iterating.js +++ b/test/_files/nested_iterating.js @@ -5,4 +5,4 @@ bar: 'bar' }] }] -}) +}); diff --git a/test/_files/nesting.js b/test/_files/nesting.js index 264cc2f77..d0eab3ab4 100644 --- a/test/_files/nesting.js +++ b/test/_files/nesting.js @@ -4,4 +4,4 @@ {a: {b: 2}}, {a: {b: 3}} ] -}) +}); diff --git a/test/_files/nesting_same_name.js b/test/_files/nesting_same_name.js index 10a0c1401..84bc5c0bc 100644 --- a/test/_files/nesting_same_name.js +++ b/test/_files/nesting_same_name.js @@ -5,4 +5,4 @@ items: [1, 2, 3, 4] } ] -}) +}); diff --git a/test/_files/null_lookup_array.js b/test/_files/null_lookup_array.js index 9ebf56a22..40efeea51 100644 --- a/test/_files/null_lookup_array.js +++ b/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] + ] +}); diff --git a/test/_files/null_lookup_object.js b/test/_files/null_lookup_object.js index 2f2efd7fd..6f6b0e5bf 100644 --- a/test/_files/null_lookup_object.js +++ b/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 } } -}) +}); diff --git a/test/_files/null_string.js b/test/_files/null_string.js index 984ee516a..4fc1033ac 100644 --- a/test/_files/null_string.js +++ b/test/_files/null_string.js @@ -1,10 +1,10 @@ ({ - name: "Elise", + name: 'Elise', glytch: true, binary: false, value: null, undef: undefined, - numeric: function() { + numeric: function () { return NaN; } -}) +}); diff --git a/test/_files/null_view.js b/test/_files/null_view.js index dbdae728e..7f82792d3 100644 --- a/test/_files/null_view.js +++ b/test/_files/null_view.js @@ -1,4 +1,4 @@ ({ name: 'Joe', friends: null -}) +}); diff --git a/test/_files/partial_array.js b/test/_files/partial_array.js index 2a6ddf1cf..30b3c7711 100644 --- a/test/_files/partial_array.js +++ b/test/_files/partial_array.js @@ -1,3 +1,3 @@ ({ array: ['1', '2', '3', '4'] -}) +}); diff --git a/test/_files/partial_array_of_partials.js b/test/_files/partial_array_of_partials.js index 03f13c946..4f21b7549 100644 --- a/test/_files/partial_array_of_partials.js +++ b/test/_files/partial_array_of_partials.js @@ -5,4 +5,4 @@ {i: '3'}, {i: '4'} ] -}) +}); diff --git a/test/_files/partial_array_of_partials_implicit.js b/test/_files/partial_array_of_partials_implicit.js index 9ec0c00ff..350ad17d5 100644 --- a/test/_files/partial_array_of_partials_implicit.js +++ b/test/_files/partial_array_of_partials_implicit.js @@ -1,3 +1,3 @@ ({ numbers: ['1', '2', '3', '4'] -}) +}); diff --git a/test/_files/partial_empty.js b/test/_files/partial_empty.js index 82b8c2242..03db6fd93 100644 --- a/test/_files/partial_empty.js +++ b/test/_files/partial_empty.js @@ -1,3 +1,3 @@ ({ foo: 1 -}) +}); diff --git a/test/_files/partial_template.js b/test/_files/partial_template.js index a913f8784..a527657f6 100644 --- a/test/_files/partial_template.js +++ b/test/_files/partial_template.js @@ -1,6 +1,6 @@ ({ title: function () { - return "Welcome"; + return 'Welcome'; }, - again: "Goodbye" -}) + again: 'Goodbye' +}); diff --git a/test/_files/partial_view.js b/test/_files/partial_view.js index 3ad70d35c..6a83f54fc 100644 --- a/test/_files/partial_view.js +++ b/test/_files/partial_view.js @@ -1,14 +1,14 @@ ({ greeting: function () { - return "Welcome"; + return 'Welcome'; }, farewell: function () { - return "Fair enough, right?"; + return 'Fair enough, right?'; }, - name: "Chris", + name: 'Chris', value: 10000, taxed_value: function () { return this.value - (this.value * 0.4); }, in_ca: true -}) +}); diff --git a/test/_files/partial_whitespace.js b/test/_files/partial_whitespace.js index 3ad70d35c..6a83f54fc 100644 --- a/test/_files/partial_whitespace.js +++ b/test/_files/partial_whitespace.js @@ -1,14 +1,14 @@ ({ greeting: function () { - return "Welcome"; + return 'Welcome'; }, farewell: function () { - return "Fair enough, right?"; + return 'Fair enough, right?'; }, - name: "Chris", + name: 'Chris', value: 10000, taxed_value: function () { return this.value - (this.value * 0.4); }, in_ca: true -}) +}); diff --git a/test/_files/recursion_with_same_names.js b/test/_files/recursion_with_same_names.js index ce2650291..fd0f7d081 100644 --- a/test/_files/recursion_with_same_names.js +++ b/test/_files/recursion_with_same_names.js @@ -5,4 +5,4 @@ {name: 't1', index: 0}, {name: 't2', index: 1} ] -}) +}); diff --git a/test/_files/reuse_of_enumerables.js b/test/_files/reuse_of_enumerables.js index 4368b5743..b59b4a8f6 100644 --- a/test/_files/reuse_of_enumerables.js +++ b/test/_files/reuse_of_enumerables.js @@ -3,4 +3,4 @@ {name: 't1', index: 0}, {name: 't2', index: 1} ] -}) +}); diff --git a/test/_files/section_as_context.js b/test/_files/section_as_context.js index 425b29cb4..aeb7b1feb 100644 --- a/test/_files/section_as_context.js +++ b/test/_files/section_as_context.js @@ -7,4 +7,4 @@ {label: 'listitem2'} ] } -}) +}); diff --git a/test/_files/section_functions_in_partials.js b/test/_files/section_functions_in_partials.js index 4672778bd..ece5fc9d8 100644 --- a/test/_files/section_functions_in_partials.js +++ b/test/_files/section_functions_in_partials.js @@ -1,7 +1,7 @@ ({ - bold: function(){ - return function(text, render) { - return "" + render(text) + ""; - } + bold: function (){ + return function (text, render) { + return '' + render(text) + ''; + }; } -}) +}); diff --git a/test/_files/simple.js b/test/_files/simple.js index 1d8d6f425..6c6b1f07e 100644 --- a/test/_files/simple.js +++ b/test/_files/simple.js @@ -1,8 +1,8 @@ ({ - name: "Chris", + name: 'Chris', value: 10000, taxed_value: function () { return this.value - (this.value * 0.4); }, in_ca: true -}) +}); diff --git a/test/_files/string_as_context.js b/test/_files/string_as_context.js index e8bb4da00..118e2b5e7 100644 --- a/test/_files/string_as_context.js +++ b/test/_files/string_as_context.js @@ -1,4 +1,4 @@ ({ a_string: 'aa', a_list: ['a','b','c'] -}) +}); diff --git a/test/_files/two_in_a_row.js b/test/_files/two_in_a_row.js index 9c17c1173..272f86039 100644 --- a/test/_files/two_in_a_row.js +++ b/test/_files/two_in_a_row.js @@ -1,4 +1,4 @@ ({ - name: "Joe", - greeting: "Welcome" -}) + name: 'Joe', + greeting: 'Welcome' +}); diff --git a/test/_files/two_sections.js b/test/_files/two_sections.js index b4100a597..b3bf1ddb0 100644 --- a/test/_files/two_sections.js +++ b/test/_files/two_sections.js @@ -1 +1 @@ -({}) +({}); diff --git a/test/_files/unescaped.js b/test/_files/unescaped.js index 0659b69d0..3b4d3cb8f 100644 --- a/test/_files/unescaped.js +++ b/test/_files/unescaped.js @@ -1,6 +1,6 @@ ({ title: function () { - return "Bear > Shark"; + return 'Bear > Shark'; }, symbol: null -}) +}); diff --git a/test/_files/uses_props_from_view_prototype.js b/test/_files/uses_props_from_view_prototype.js index 5fff76a29..6754348c1 100644 --- a/test/_files/uses_props_from_view_prototype.js +++ b/test/_files/uses_props_from_view_prototype.js @@ -1,9 +1,9 @@ var Aaa = (function () { - function Aaa(x, y) { + function Aaa (x, y) { this.x = x; this._y = y; } - Object.defineProperty(Aaa.prototype, "y", { + Object.defineProperty(Aaa.prototype, 'y', { get: function () { return this._y; }, @@ -16,15 +16,15 @@ var Aaa = (function () { return Aaa; })(); var Bbb = (function () { - function Bbb() { + function Bbb () { } return Bbb; })(); var b = new Bbb(); -b.item = new Aaa("0", "00"); +b.item = new Aaa('0', '00'); 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); diff --git a/test/_files/whitespace.js b/test/_files/whitespace.js index f41cb5640..dc12fe297 100644 --- a/test/_files/whitespace.js +++ b/test/_files/whitespace.js @@ -1,4 +1,4 @@ ({ - tag1: "Hello", - tag2: "World" -}) + tag1: 'Hello', + tag2: 'World' +}); diff --git a/test/_files/zero_view.js b/test/_files/zero_view.js index 986460860..d584042c6 100644 --- a/test/_files/zero_view.js +++ b/test/_files/zero_view.js @@ -1 +1 @@ -({ nums: [0, 1, 2] }) +({ nums: [0, 1, 2] }); diff --git a/test/cli-test.js b/test/cli-test.js index 11edc1543..28e25023e 100644 --- a/test/cli-test.js +++ b/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 moduleVersion = require('../package').version; -function changeForOS(command) { +function changeForOS (command) { - if(process.platform === 'win32') { + if (process.platform === 'win32') { return command .replace(/bin\/mustache/g, 'node bin\\mustache') .replace(/\bcat\b/g, 'type') @@ -20,7 +20,7 @@ function changeForOS(command) { return command; } -function exec() { +function exec () { arguments[0] = changeForOS(arguments[0]); return child_process.exec.apply(child_process, arguments); } @@ -29,37 +29,37 @@ describe('Mustache CLI', function () { 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); 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); 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); 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); 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); 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(stderr, ''); 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'; - 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(stderr, ''); 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(stderr, ''); 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)); 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)); 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); 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(stderr, ''); 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(stderr, ''); assert.equal(stdout, expectedOutput); done(); }); }); - }) + }); }); diff --git a/test/mustache-spec-test.js b/test/mustache-spec-test.js index 0c6e537ac..08a52517e 100644 --- a/test/mustache-spec-test.js +++ b/test/mustache-spec-test.js @@ -42,7 +42,7 @@ var noSkip = process.env.NOSKIP; var fileToRun = process.env.TEST; // Mustache should work on node 0.6 that doesn't have fs.existsSync -function existsDir(path) { +function existsDir (path) { try { return fs.statSync(path).isDirectory(); } catch (x) { @@ -63,21 +63,21 @@ if (fileToRun) { specFiles = []; } -function getSpecs(specArea) { +function getSpecs (specArea) { return JSON.parse(fs.readFileSync(path.join(specsDir, specArea + '.' + 'json'), 'utf8')); } -describe('Mustache spec compliance', function() { +describe('Mustache spec compliance', function () { beforeEach(function () { Mustache.clearCache(); }); - specFiles.forEach(function(specArea) { - describe('- ' + specArea + ':', function() { + specFiles.forEach(function (specArea) { + describe('- ' + specArea + ':', function () { 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; - it_(test.name + ' - ' + test.desc, function() { + it_(test.name + ' - ' + test.desc, function () { if (test.data.lambda && test.data.lambda.__tag__ === 'code') test.data.lambda = eval('(function() { return ' + test.data.lambda.js + '; })'); var output = Mustache.render(test.template, test.data, test.partials); diff --git a/test/parse-test.js b/test/parse-test.js index 959699bc2..0b0891c5d 100644 --- a/test/parse-test.js +++ b/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 parsedWithBrackets = Mustache.parse(template, ['[', ']']); 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 parsedWithBrackets = Mustache.parse(template, ['[', ']']); 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 oldTags = Mustache.tags; diff --git a/test/render-helper.js b/test/render-helper.js index 11e73c9f7..4b70480ac 100644 --- a/test/render-helper.js +++ b/test/render-helper.js @@ -3,7 +3,7 @@ var path = require('path'); var _files = path.join(__dirname, '_files'); -function getContents(testName, ext) { +function getContents (testName, ext) { try { return fs.readFileSync(path.join(_files, testName + '.' + ext), 'utf8'); } catch (ex) { @@ -11,13 +11,13 @@ function getContents(testName, ext) { } } -function getView(testName) { +function getView (testName) { var view = getContents(testName, 'js'); if (!view) throw new Error('Cannot find view for test "' + testName + '"'); return view; } -function getPartial(testName) { +function getPartial (testName) { try { return getContents(testName, 'partial'); } catch (error) { @@ -40,7 +40,7 @@ if (testToRun) { }); } -function getTest(testName) { +function getTest (testName) { return { name: testName, view: getView(testName), @@ -50,6 +50,6 @@ function getTest(testName) { }; } -exports.getTests = function getTests() { +exports.getTests = function getTests () { return testNames.map(getTest); }; \ No newline at end of file diff --git a/test/render-test.js b/test/render-test.js index 1041dd40b..008852101 100644 --- a/test/render-test.js +++ b/test/render-test.js @@ -40,7 +40,7 @@ describe('Mustache.render', function () { assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['[[', ']]']), 'foobar<>'); }); - it('does not mutate Mustache.tags when given tags argument', function() { + it('does not mutate Mustache.tags when given tags argument', function () { var correctMustacheTags = ['{{', '}}']; Mustache.tags = correctMustacheTags; @@ -56,8 +56,8 @@ describe('Mustache.render', function () { }, ['<%', '%>']); assert.equal(output, 'Santa Claus'); - }) - }) + }); + }); tests.forEach(function (test) { var view = eval(test.view);