Bläddra i källkod

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.
pull/704/head
Phillip Johnsen 6 år sedan
förälder
incheckning
ac04d6a54b
66 ändrade filer med 225 tillägg och 219 borttagningar
  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 Visa fil

@@ -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",


+ 6
- 0
test/.eslintrc Visa fil

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

+ 2
- 2
test/_files/ampersand_escape.js Visa fil

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

+ 1
- 1
test/_files/apostrophe.js Visa fil

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

+ 1
- 1
test/_files/array_of_strings.js Visa fil

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

+ 1
- 1
test/_files/avoids_obj_prototype_in_view_cache.js Visa fil

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

+ 2
- 2
test/_files/backslashes.js Visa fil

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

+ 2
- 2
test/_files/bug_11_eating_whitespace.js Visa fil

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

+ 1
- 1
test/_files/bug_length_property.js Visa fil

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

+ 3
- 3
test/_files/changing_delimiters.js Visa fil

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

+ 4
- 4
test/_files/check_falsy.js Visa fil

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

+ 2
- 2
test/_files/comments.js Visa fil

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

+ 6
- 6
test/_files/complex.js Visa fil

@@ -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;
}
})
});

+ 5
- 5
test/_files/context_lookup.js Visa fil

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

+ 5
- 5
test/_files/delimiters.js Visa fil

@@ -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 Visa fil

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

+ 5
- 5
test/_files/dot_notation.js Visa fil

@@ -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'}]
});

+ 3
- 3
test/_files/double_render.js Visa fil

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

+ 1
- 1
test/_files/empty_list.js Visa fil

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

+ 1
- 1
test/_files/empty_sections.js Visa fil

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

+ 3
- 3
test/_files/empty_string.js Visa fil

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

+ 1
- 1
test/_files/empty_template.js Visa fil

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

+ 1
- 1
test/_files/error_not_found.js Visa fil

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

+ 2
- 2
test/_files/escaped.js Visa fil

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

+ 7
- 7
test/_files/falsy.js Visa fil

@@ -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 Visa fil

@@ -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 Visa fil

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

+ 4
- 4
test/_files/higher_order_sections.js Visa fil

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

+ 1
- 1
test/_files/implicit_iterator.js Visa fil

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

+ 2
- 2
test/_files/included_tag.js Visa fil

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

+ 2
- 2
test/_files/inverted_section.js Visa fil

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

+ 3
- 3
test/_files/keys_with_questionmarks.js Visa fil

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

+ 1
- 1
test/_files/malicious_template.js Visa fil

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

+ 1
- 1
test/_files/multiline_comment.js Visa fil

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

+ 1
- 1
test/_files/nested_dot.js Visa fil

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

+ 1
- 1
test/_files/nested_iterating.js Visa fil

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

+ 1
- 1
test/_files/nesting.js Visa fil

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

+ 1
- 1
test/_files/nesting_same_name.js Visa fil

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

+ 8
- 8
test/_files/null_lookup_array.js Visa fil

@@ -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 Visa fil

@@ -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 Visa fil

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

+ 1
- 1
test/_files/null_view.js Visa fil

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

+ 1
- 1
test/_files/partial_array.js Visa fil

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

+ 1
- 1
test/_files/partial_array_of_partials.js Visa fil

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

+ 1
- 1
test/_files/partial_array_of_partials_implicit.js Visa fil

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

+ 1
- 1
test/_files/partial_empty.js Visa fil

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

+ 3
- 3
test/_files/partial_template.js Visa fil

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

+ 4
- 4
test/_files/partial_view.js Visa fil

@@ -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
})
});

+ 4
- 4
test/_files/partial_whitespace.js Visa fil

@@ -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
})
});

+ 1
- 1
test/_files/recursion_with_same_names.js Visa fil

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

+ 1
- 1
test/_files/reuse_of_enumerables.js Visa fil

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

+ 1
- 1
test/_files/section_as_context.js Visa fil

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

+ 5
- 5
test/_files/section_functions_in_partials.js Visa fil

@@ -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 Visa fil

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

+ 1
- 1
test/_files/string_as_context.js Visa fil

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

+ 3
- 3
test/_files/two_in_a_row.js Visa fil

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

+ 1
- 1
test/_files/two_sections.js Visa fil

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

+ 2
- 2
test/_files/unescaped.js Visa fil

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

+ 7
- 7
test/_files/uses_props_from_view_prototype.js Visa fil

@@ -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);

+ 3
- 3
test/_files/whitespace.js Visa fil

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

+ 1
- 1
test/_files/zero_view.js Visa fil

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

+ 32
- 32
test/cli-test.js Visa fil

@@ -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();
});
});
})
});
});

+ 7
- 7
test/mustache-spec-test.js Visa fil

@@ -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);


+ 9
- 9
test/parse-test.js Visa fil

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


+ 5
- 5
test/render-helper.js Visa fil

@@ -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);
};

+ 3
- 3
test/render-test.js Visa fil

@@ -40,7 +40,7 @@ describe('Mustache.render', function () {
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 = ['{{', '}}'];
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);


Laddar…
Avbryt
Spara