Skip to content

Commit b552fbc

Browse files
committed
Convert engine_handlebars_tests.js to use tape
1 parent 1df0dca commit b552fbc

File tree

1 file changed

+142
-134
lines changed

1 file changed

+142
-134
lines changed

test/engine_handlebars_tests.js

Lines changed: 142 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
"use strict";
2+
/*eslint-disable no-shadow*/
23

4+
var test = require('tape');
35
var path = require('path');
46
var pa = require('../core/lib/pattern_assembler');
57
var Pattern = require('../core/lib/object_factory').Pattern;
68
var testPatternsPath = path.resolve(__dirname, 'files', '_handlebars-test-patterns');
79
var eol = require('os').EOL;
810

11+
// don't run these tests unless handlebars is installed
12+
var engineLoader = require('../core/lib/pattern_engines');
13+
if (!engineLoader.handlebars) {
14+
test.only('Handlebars engine not installed, skipping tests.', function (test) {
15+
test.end();
16+
});
17+
};
18+
919
// fake pattern lab constructor:
1020
// sets up a fake patternlab object, which is needed by the pattern processing
1121
// apparatus.
@@ -34,7 +44,7 @@ function fakePatternLab() {
3444

3545
// function for testing sets of partials
3646
function testFindPartials(test, partialTests) {
37-
test.expect(partialTests.length + 1);
47+
test.plan(partialTests.length + 1);
3848

3949
// setup current pattern from what we would have during execution
4050
// docs on partial syntax are here:
@@ -56,138 +66,136 @@ function testFindPartials(test, partialTests) {
5666
test.equals(results[index], testString);
5767
});
5868

59-
test.done();
69+
test.end();
6070
}
6171

62-
exports['engine_handlebars'] = {
63-
'hello world handlebars pattern renders': function (test) {
64-
test.expect(1);
65-
66-
var patternPath = path.join('00-atoms', '00-global', '00-helloworld.hbs');
67-
68-
// do all the normal processing of the pattern
69-
var patternlab = new fakePatternLab();
70-
var assembler = new pa();
71-
var helloWorldPattern = assembler.process_pattern_iterative(patternPath, patternlab);
72-
assembler.process_pattern_recursive(patternPath, patternlab);
73-
74-
test.equals(helloWorldPattern.render(), 'Hello world!' + eol);
75-
test.done();
76-
},
77-
'hello worlds handlebars pattern can see the atoms-helloworld partial and renders it twice': function (test) {
78-
test.expect(1);
79-
80-
// pattern paths
81-
var pattern1Path = path.join('00-atoms', '00-global', '00-helloworld.hbs');
82-
var pattern2Path = path.join('00-molecules', '00-global', '00-helloworlds.hbs');
83-
84-
// set up environment
85-
var patternlab = new fakePatternLab(); // environment
86-
var assembler = new pa();
87-
88-
// do all the normal processing of the pattern
89-
assembler.process_pattern_iterative(pattern1Path, patternlab);
90-
var helloWorldsPattern = assembler.process_pattern_iterative(pattern2Path, patternlab);
91-
assembler.process_pattern_recursive(pattern1Path, patternlab);
92-
assembler.process_pattern_recursive(pattern2Path, patternlab);
93-
94-
// test
95-
test.equals(helloWorldsPattern.render(), 'Hello world!' + eol + ' and Hello world!' + eol + eol);
96-
test.done();
97-
},
98-
'handlebars partials can render JSON values': function (test) {
99-
test.expect(1);
100-
101-
// pattern paths
102-
var pattern1Path = path.join('00-atoms', '00-global', '00-helloworld-withdata.hbs');
103-
104-
// set up environment
105-
var patternlab = new fakePatternLab(); // environment
106-
var assembler = new pa();
107-
108-
// do all the normal processing of the pattern
109-
var helloWorldWithData = assembler.process_pattern_iterative(pattern1Path, patternlab);
110-
assembler.process_pattern_recursive(pattern1Path, patternlab);
111-
112-
// test
113-
test.equals(helloWorldWithData.render(), 'Hello world!' + eol + 'Yeah, we got the subtitle from the JSON.' + eol);
114-
test.done();
115-
},
116-
'handlebars partials use the JSON environment from the calling pattern and can accept passed parameters': function (test) {
117-
test.expect(1);
118-
119-
// pattern paths
120-
var atomPath = path.join('00-atoms', '00-global', '00-helloworld-withdata.hbs');
121-
var molPath = path.join('00-molecules', '00-global', '00-call-atom-with-molecule-data.hbs');
122-
123-
// set up environment
124-
var patternlab = new fakePatternLab(); // environment
125-
var assembler = new pa();
126-
127-
// do all the normal processing of the pattern
128-
assembler.process_pattern_iterative(atomPath, patternlab);
129-
var mol = assembler.process_pattern_iterative(molPath, patternlab);
130-
assembler.process_pattern_recursive(atomPath, patternlab);
131-
assembler.process_pattern_recursive(molPath, patternlab);
132-
133-
// test
134-
test.equals(mol.render(), '<h2>Call with default JSON environment:</h2>' + eol + 'This is Hello world!' + eol + 'from the default JSON.' + eol + eol + eol +'<h2>Call with passed parameter:</h2>' + eol + 'However, this is Hello world!' + eol + 'from a totally different blob.' + eol + eol);
135-
test.done();
136-
},
137-
'find_pattern_partials finds partials': function (test) {
138-
testFindPartials(test, [
139-
"{{> molecules-comment-header}}",
140-
"{{> molecules-comment-header}}",
141-
"{{> " + eol + " molecules-comment-header" + eol + "}}",
142-
"{{> molecules-weird-spacing }}",
143-
"{{> molecules-ba_d-cha*rs }}"
144-
]);
145-
},
146-
'find_pattern_partials finds verbose partials': function (test) {
147-
testFindPartials(test, [
148-
'{{> 01-molecules/06-components/03-comment-header.hbs }}',
149-
"{{> 01-molecules/06-components/02-single-comment.hbs(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}",
150-
'{{> molecules-single-comment:foo }}',
151-
"{{>atoms-error(message: 'That\'s no moon...')}}",
152-
"{{> atoms-error(message: 'That\'s no moon...') }}",
153-
'{{> 00-atoms/00-global/06-test }}'
154-
]);
155-
},
156-
'find_pattern_partials finds simple partials with parameters': function (test) {
157-
testFindPartials(test, [
158-
"{{> molecules-single-comment(description: 'A life isn\'t like a garden. Perfect moments can be had, but not preserved, except in memory.') }}",
159-
'{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
160-
]);
161-
},
162-
'find_pattern_partials finds simple partials with style modifiers': function (test) {
163-
testFindPartials(test, [
164-
'{{> molecules-single-comment:foo }}'
165-
]);
166-
},
167-
'find_pattern_partials finds partials with handlebars parameters': function (test) {
168-
testFindPartials(test, [
169-
'{{> atoms-title title="bravo" headingLevel="2" headingSize="bravo" position="left"}}',
170-
'{{> atoms-title title="bravo"' + eol + ' headingLevel="2"' + eol + ' headingSize="bravo"' + eol + ' position="left"}}',
171-
'{{> atoms-title title="color &nbsp;<span style=\'font-weight:normal\'>midnight blue</span>" headingSize="charlie"}}',
172-
'{{> atoms-input label="city" required=true}}',
173-
'{{> organisms-product-filter filterData}}',
174-
'{{> atoms-input email required=true}}',
175-
'{{> molecules-storycard variants.flex }}',
176-
'{{> myPartial name=../name }}'
177-
]);
178-
},
179-
180-
'find_pattern_partials finds handlebars block partials': function (test) {
181-
testFindPartials(test, [
182-
'{{#> myPartial }}'
183-
]);
184-
}
185-
};
186-
187-
188-
// don't run these tests unless handlebars is installed
189-
var engineLoader = require('../core/lib/pattern_engines');
190-
if (!engineLoader.handlebars) {
191-
console.log("Handlebars engine not installed, skipping tests.");
192-
delete exports.engine_handlebars;
193-
}
72+
test('hello world handlebars pattern renders', function (test) {
73+
test.plan(1);
74+
75+
var patternPath = path.join('00-atoms', '00-global', '00-helloworld.hbs');
76+
77+
// do all the normal processing of the pattern
78+
var patternlab = new fakePatternLab();
79+
var assembler = new pa();
80+
var helloWorldPattern = assembler.process_pattern_iterative(patternPath, patternlab);
81+
assembler.process_pattern_recursive(patternPath, patternlab);
82+
83+
test.equals(helloWorldPattern.render(), 'Hello world!' + eol);
84+
test.end();
85+
});
86+
87+
test('hello worlds handlebars pattern can see the atoms-helloworld partial and renders it twice', function (test) {
88+
test.plan(1);
89+
90+
// pattern paths
91+
var pattern1Path = path.join('00-atoms', '00-global', '00-helloworld.hbs');
92+
var pattern2Path = path.join('00-molecules', '00-global', '00-helloworlds.hbs');
93+
94+
// set up environment
95+
var patternlab = new fakePatternLab(); // environment
96+
var assembler = new pa();
97+
98+
// do all the normal processing of the pattern
99+
assembler.process_pattern_iterative(pattern1Path, patternlab);
100+
var helloWorldsPattern = assembler.process_pattern_iterative(pattern2Path, patternlab);
101+
assembler.process_pattern_recursive(pattern1Path, patternlab);
102+
assembler.process_pattern_recursive(pattern2Path, patternlab);
103+
104+
// test
105+
test.equals(helloWorldsPattern.render(), 'Hello world!' + eol + ' and Hello world!' + eol + eol);
106+
test.end();
107+
});
108+
109+
test('handlebars partials can render JSON values', function (test) {
110+
test.plan(1);
111+
112+
// pattern paths
113+
var pattern1Path = path.join('00-atoms', '00-global', '00-helloworld-withdata.hbs');
114+
115+
// set up environment
116+
var patternlab = new fakePatternLab(); // environment
117+
var assembler = new pa();
118+
119+
// do all the normal processing of the pattern
120+
var helloWorldWithData = assembler.process_pattern_iterative(pattern1Path, patternlab);
121+
assembler.process_pattern_recursive(pattern1Path, patternlab);
122+
123+
// test
124+
test.equals(helloWorldWithData.render(), 'Hello world!' + eol + 'Yeah, we got the subtitle from the JSON.' + eol);
125+
test.end();
126+
});
127+
128+
test('handlebars partials use the JSON environment from the calling pattern and can accept passed parameters', function (test) {
129+
test.plan(1);
130+
131+
// pattern paths
132+
var atomPath = path.join('00-atoms', '00-global', '00-helloworld-withdata.hbs');
133+
var molPath = path.join('00-molecules', '00-global', '00-call-atom-with-molecule-data.hbs');
134+
135+
// set up environment
136+
var patternlab = new fakePatternLab(); // environment
137+
var assembler = new pa();
138+
139+
// do all the normal processing of the pattern
140+
assembler.process_pattern_iterative(atomPath, patternlab);
141+
var mol = assembler.process_pattern_iterative(molPath, patternlab);
142+
assembler.process_pattern_recursive(atomPath, patternlab);
143+
assembler.process_pattern_recursive(molPath, patternlab);
144+
145+
// test
146+
test.equals(mol.render(), '<h2>Call with default JSON environment:</h2>' + eol + 'This is Hello world!' + eol + 'from the default JSON.' + eol + eol + eol +'<h2>Call with passed parameter:</h2>' + eol + 'However, this is Hello world!' + eol + 'from a totally different blob.' + eol + eol);
147+
test.end();
148+
});
149+
150+
test('find_pattern_partials finds partials', function (test) {
151+
testFindPartials(test, [
152+
"{{> molecules-comment-header}}",
153+
"{{> molecules-comment-header}}",
154+
"{{> " + eol + " molecules-comment-header" + eol + "}}",
155+
"{{> molecules-weird-spacing }}",
156+
"{{> molecules-ba_d-cha*rs }}"
157+
]);
158+
});
159+
160+
test('find_pattern_partials finds verbose partials', function (test) {
161+
testFindPartials(test, [
162+
'{{> 01-molecules/06-components/03-comment-header.hbs }}',
163+
"{{> 01-molecules/06-components/02-single-comment.hbs(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}",
164+
'{{> molecules-single-comment:foo }}',
165+
"{{>atoms-error(message: 'That\'s no moon...')}}",
166+
"{{> atoms-error(message: 'That\'s no moon...') }}",
167+
'{{> 00-atoms/00-global/06-test }}'
168+
]);
169+
});
170+
171+
test('find_pattern_partials finds simple partials with parameters', function (test) {
172+
testFindPartials(test, [
173+
"{{> molecules-single-comment(description: 'A life isn\'t like a garden. Perfect moments can be had, but not preserved, except in memory.') }}",
174+
'{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
175+
]);
176+
});
177+
178+
test('find_pattern_partials finds simple partials with style modifiers', function (test) {
179+
testFindPartials(test, [
180+
'{{> molecules-single-comment:foo }}'
181+
]);
182+
});
183+
184+
test('find_pattern_partials finds partials with handlebars parameters', function (test) {
185+
testFindPartials(test, [
186+
'{{> atoms-title title="bravo" headingLevel="2" headingSize="bravo" position="left"}}',
187+
'{{> atoms-title title="bravo"' + eol + ' headingLevel="2"' + eol + ' headingSize="bravo"' + eol + ' position="left"}}',
188+
'{{> atoms-title title="color &nbsp;<span style=\'font-weight:normal\'>midnight blue</span>" headingSize="charlie"}}',
189+
'{{> atoms-input label="city" required=true}}',
190+
'{{> organisms-product-filter filterData}}',
191+
'{{> atoms-input email required=true}}',
192+
'{{> molecules-storycard variants.flex }}',
193+
'{{> myPartial name=../name }}'
194+
]);
195+
});
196+
197+
test('find_pattern_partials finds handlebars block partials', function (test) {
198+
testFindPartials(test, [
199+
'{{#> myPartial }}'
200+
]);
201+
});

0 commit comments

Comments
 (0)