Skip to content

Convert engine_mustache_tests.js to use tape #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 116 additions & 109 deletions test/engine_mustache_tests.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
"use strict";
/*eslint-disable no-shadow*/

var tap = require('tap');
var path = require('path');
var pa = require('../core/lib/pattern_assembler');
var Pattern = require('../core/lib/object_factory').Pattern;
var testPatternsPath = path.resolve(__dirname, 'files', '_patterns');
var eol = require('os').EOL;

// don't run these tests unless mustache is installed
var engineLoader = require('../core/lib/pattern_engines');
if (!engineLoader.mustache) {
tap.test('Mustache engine not installed, skipping tests.', function (test) {
test.end();
});
return;
}

// fake pattern lab constructor:
// sets up a fake patternlab object, which is needed by the pattern processing
// apparatus.
Expand Down Expand Up @@ -33,7 +44,7 @@ function fakePatternLab() {

// function for testing sets of partials
function testFindPartials(test, partialTests) {
test.expect(partialTests.length + 1);
test.plan(partialTests.length + 1);

// setup current pattern from what we would have during execution
// docs on partial syntax are here:
Expand All @@ -55,11 +66,11 @@ function testFindPartials(test, partialTests) {
test.equals(results[index], testString);
});

test.done();
test.end();
}

function testFindPartialsWithStyleModifiers(test, partialTests) {
test.expect(partialTests.length + 1);
test.plan(partialTests.length + 1);

// setup current pattern from what we would have during execution
// docs on partial syntax are here:
Expand All @@ -81,11 +92,11 @@ function testFindPartialsWithStyleModifiers(test, partialTests) {
test.equals(results[index], testString);
});

test.done();
test.end();
}

function testFindPartialsWithPatternParameters(test, partialTests) {
test.expect(partialTests.length + 1);
test.plan(partialTests.length + 1);

// setup current pattern from what we would have during execution
// docs on partial syntax are here:
Expand All @@ -107,110 +118,106 @@ function testFindPartialsWithPatternParameters(test, partialTests) {
test.equals(results[index], testString);
});

test.done();
test.end();
}

exports['engine_mustache'] = {
'find_pattern_partials finds one simple partial': function (test) {
testFindPartials(test, [
"{{> molecules-comment-header}}"
]);
},

'find_pattern_partials finds simple partials under stressed circumstances': function (test) {
testFindPartials(test, [
"{{>molecules-comment-header}}",
"{{> " + eol + " molecules-comment-header" + eol + "}}",
"{{> molecules-weird-spacing }}"
]);
},

'find_pattern_partials finds one simple verbose partial': function (test) {
testFindPartials(test, [
'{{> 00-atoms/00-global/06-test }}'
]);
},

'find_pattern_partials finds partials with parameters': function (test) {
testFindPartials(test, [
"{{> molecules-single-comment(description: true) }}",
"{{> molecules-single-comment(description: 42) }}",
"{{> molecules-single-comment(description: '42') }}",
"{{> molecules-single-comment(description: \"42\") }}",
"{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}",
"{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}",
'{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
]);
},

'find_pattern_partials finds simple partials with style modifiers': function (test) {
testFindPartials(test, [
'{{> molecules-single-comment:foo }}',
'{{> molecules-single-comment:foo|bar }}'
]);
},
'find_pattern_partials finds mixed partials': function (test) {
testFindPartials(test, [
'{{> molecules-single-comment:foo(description: "test", anotherThing: true) }}',
'{{> molecules-single-comment:foo|bar(description: true) }}'
]);
},

'find_pattern_partials finds one simple partial with styleModifier': function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test}}"
]);
},
'find_pattern_partials finds partial with many styleModifiers': function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test|test2|test3}}"
]);
},
'find_pattern_partials finds partials with differing styleModifiers': function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test|test2|test3}}",
"{{> molecules-comment-header:foo-1}}",
"{{> molecules-comment-header:bar_1}}"
]);
},
'find_pattern_partials finds partials with styleModifiers when parameters present': function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test|test2|test3(description: true)}}",
"{{> molecules-comment-header:foo-1(description: 'foo')}}",
"{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
]);
},

'find_pattern_partials_with_parameters finds one simple partial with parameters': function (test) {
testFindPartialsWithPatternParameters(test, [
"{{> molecules-comment-header(description: 'test')}}"
]);
},
'find_pattern_partials_with_parameters finds partials with parameters': function (test) {
testFindPartialsWithPatternParameters(test, [
"{{> molecules-single-comment(description: true) }}",
"{{> molecules-single-comment(description: 42) }}",
"{{> molecules-single-comment(description: '42') }}",
"{{> molecules-single-comment(description: \"42\") }}",
"{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}",
"{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}",
'{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
]);
},
'find_pattern_partials finds partials with parameters when styleModifiers present': function (test) {
testFindPartialsWithPatternParameters(test, [
"{{> molecules-comment-header:test|test2|test3(description: true)}}",
"{{> molecules-comment-header:foo-1(description: 'foo')}}",
"{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
]);
}

};


// don't run these tests unless mustache is installed
var engineLoader = require('../core/lib/pattern_engines');
if (!engineLoader.mustache) {
console.log("Mustache engine not installed, skipping tests.");
delete exports.engine_mustache;
}
tap.test('find_pattern_partials finds one simple partial', function (test) {
testFindPartials(test, [
"{{> molecules-comment-header}}"
]);
});

tap.test('find_pattern_partials finds simple partials under stressed circumstances', function (test) {
testFindPartials(test, [
"{{>molecules-comment-header}}",
"{{> " + eol + " molecules-comment-header" + eol + "}}",
"{{> molecules-weird-spacing }}"
]);
});

tap.test('find_pattern_partials finds one simple verbose partial', function (test) {
testFindPartials(test, [
'{{> 00-atoms/00-global/06-test }}'
]);
});

tap.test('find_pattern_partials finds partials with parameters', function (test) {
testFindPartials(test, [
"{{> molecules-single-comment(description: true) }}",
"{{> molecules-single-comment(description: 42) }}",
"{{> molecules-single-comment(description: '42') }}",
"{{> molecules-single-comment(description: \"42\") }}",
"{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}",
"{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}",
'{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
]);
});

tap.test('find_pattern_partials finds simple partials with style modifiers', function (test) {
testFindPartials(test, [
'{{> molecules-single-comment:foo }}',
'{{> molecules-single-comment:foo|bar }}'
]);
});

tap.test('find_pattern_partials finds mixed partials', function (test) {
testFindPartials(test, [
'{{> molecules-single-comment:foo(description: "test", anotherThing: true) }}',
'{{> molecules-single-comment:foo|bar(description: true) }}'
]);
});

tap.test('find_pattern_partials finds one simple partial with styleModifier', function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test}}"
]);
});

tap.test('find_pattern_partials finds partial with many styleModifiers', function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test|test2|test3}}"
]);
});

tap.test('find_pattern_partials finds partials with differing styleModifiers', function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test|test2|test3}}",
"{{> molecules-comment-header:foo-1}}",
"{{> molecules-comment-header:bar_1}}"
]);
});

tap.test('find_pattern_partials finds partials with styleModifiers when parameters present', function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test|test2|test3(description: true)}}",
"{{> molecules-comment-header:foo-1(description: 'foo')}}",
"{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
]);
});

tap.test('find_pattern_partials_with_parameters finds one simple partial with parameters', function (test) {
testFindPartialsWithPatternParameters(test, [
"{{> molecules-comment-header(description: 'test')}}"
]);
});

tap.test('find_pattern_partials_with_parameters finds partials with parameters', function (test) {
testFindPartialsWithPatternParameters(test, [
"{{> molecules-single-comment(description: true) }}",
"{{> molecules-single-comment(description: 42) }}",
"{{> molecules-single-comment(description: '42') }}",
"{{> molecules-single-comment(description: \"42\") }}",
"{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}",
"{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}",
'{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
]);
});

tap.test('find_pattern_partials finds partials with parameters when styleModifiers present', function (test) {
testFindPartialsWithPatternParameters(test, [
"{{> molecules-comment-header:test|test2|test3(description: true)}}",
"{{> molecules-comment-header:foo-1(description: 'foo')}}",
"{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
]);
});