1
1
"use strict" ;
2
+ /*eslint-disable no-shadow*/
2
3
4
+ var tap = require ( 'tap' ) ;
3
5
var path = require ( 'path' ) ;
4
6
var pa = require ( '../core/lib/pattern_assembler' ) ;
5
7
var Pattern = require ( '../core/lib/object_factory' ) . Pattern ;
6
8
var testPatternsPath = path . resolve ( __dirname , 'files' , '_handlebars-test-patterns' ) ;
7
9
var eol = require ( 'os' ) . EOL ;
8
10
11
+ // don't run these tests unless handlebars is installed
12
+ var engineLoader = require ( '../core/lib/pattern_engines' ) ;
13
+ if ( ! engineLoader . handlebars ) {
14
+ tap . test ( 'Handlebars engine not installed, skipping tests.' , function ( test ) {
15
+ test . end ( )
16
+ } )
17
+ return
18
+ }
19
+
9
20
// fake pattern lab constructor:
10
21
// sets up a fake patternlab object, which is needed by the pattern processing
11
22
// apparatus.
@@ -34,7 +45,7 @@ function fakePatternLab() {
34
45
35
46
// function for testing sets of partials
36
47
function testFindPartials ( test , partialTests ) {
37
- test . expect ( partialTests . length + 1 ) ;
48
+ test . plan ( partialTests . length + 1 ) ;
38
49
39
50
// setup current pattern from what we would have during execution
40
51
// docs on partial syntax are here:
@@ -56,158 +67,158 @@ function testFindPartials(test, partialTests) {
56
67
test . equals ( results [ index ] , testString ) ;
57
68
} ) ;
58
69
59
- test . done ( ) ;
70
+ test . end ( ) ;
60
71
}
61
72
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 <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
- 'hidden handlebars patterns can be called by their nice names' : function ( test ) {
186
- const util = require ( './util/test_utils.js' ) ;
187
-
188
- //arrange
189
- const testPatternsPath = path . resolve ( __dirname , 'files' , '_handlebars-test-patterns' ) ;
190
- const pl = util . fakePatternLab ( testPatternsPath ) ;
191
- var pattern_assembler = new pa ( ) ;
192
-
193
- var hiddenPatternPath = path . join ( '00-atoms' , '00-global' , '_00-hidden.hbs' ) ;
194
- var hiddenPattern = pattern_assembler . process_pattern_iterative ( hiddenPatternPath , pl ) ;
195
- pattern_assembler . process_pattern_recursive ( hiddenPatternPath , pl ) ;
196
-
197
- var testPatternPath = path . join ( '00-molecules' , '00-global' , '00-hidden-pattern-tester.hbs' ) ;
198
- var testPattern = pattern_assembler . process_pattern_iterative ( testPatternPath , pl ) ;
199
- pattern_assembler . process_pattern_recursive ( testPatternPath , pl ) ;
200
-
201
- //act
202
- test . equals ( testPattern . render ( ) , 'Here\'s the hidden atom: [I\'m the hidden atom\n]\n' ) ;
203
- test . done ( ) ;
204
- }
205
- } ;
206
73
207
-
208
- // don't run these tests unless handlebars is installed
209
- var engineLoader = require ( '../core/lib/pattern_engines' ) ;
210
- if ( ! engineLoader . handlebars ) {
211
- console . log ( "Handlebars engine not installed, skipping tests." ) ;
212
- delete exports . engine_handlebars ;
213
- }
74
+ tap . test ( 'hello world handlebars pattern renders' , function ( test ) {
75
+ test . plan ( 1 ) ;
76
+
77
+ var patternPath = path . join ( '00-atoms' , '00-global' , '00-helloworld.hbs' ) ;
78
+
79
+ // do all the normal processing of the pattern
80
+ var patternlab = new fakePatternLab ( ) ;
81
+ var assembler = new pa ( ) ;
82
+ var helloWorldPattern = assembler . process_pattern_iterative ( patternPath , patternlab ) ;
83
+ assembler . process_pattern_recursive ( patternPath , patternlab ) ;
84
+
85
+ test . equals ( helloWorldPattern . render ( ) , 'Hello world!' + eol ) ;
86
+ test . end ( ) ;
87
+ } ) ;
88
+
89
+ tap . test ( 'hello worlds handlebars pattern can see the atoms-helloworld partial and renders it twice' , function ( test ) {
90
+ test . plan ( 1 ) ;
91
+
92
+ // pattern paths
93
+ var pattern1Path = path . join ( '00-atoms' , '00-global' , '00-helloworld.hbs' ) ;
94
+ var pattern2Path = path . join ( '00-molecules' , '00-global' , '00-helloworlds.hbs' ) ;
95
+
96
+ // set up environment
97
+ var patternlab = new fakePatternLab ( ) ; // environment
98
+ var assembler = new pa ( ) ;
99
+
100
+ // do all the normal processing of the pattern
101
+ assembler . process_pattern_iterative ( pattern1Path , patternlab ) ;
102
+ var helloWorldsPattern = assembler . process_pattern_iterative ( pattern2Path , patternlab ) ;
103
+ assembler . process_pattern_recursive ( pattern1Path , patternlab ) ;
104
+ assembler . process_pattern_recursive ( pattern2Path , patternlab ) ;
105
+
106
+ // test
107
+ test . equals ( helloWorldsPattern . render ( ) , 'Hello world!' + eol + ' and Hello world!' + eol + eol ) ;
108
+ test . end ( ) ;
109
+ } ) ;
110
+
111
+ tap . test ( 'handlebars partials can render JSON values' , function ( test ) {
112
+ test . plan ( 1 ) ;
113
+
114
+ // pattern paths
115
+ var pattern1Path = path . join ( '00-atoms' , '00-global' , '00-helloworld-withdata.hbs' ) ;
116
+
117
+ // set up environment
118
+ var patternlab = new fakePatternLab ( ) ; // environment
119
+ var assembler = new pa ( ) ;
120
+
121
+ // do all the normal processing of the pattern
122
+ var helloWorldWithData = assembler . process_pattern_iterative ( pattern1Path , patternlab ) ;
123
+ assembler . process_pattern_recursive ( pattern1Path , patternlab ) ;
124
+
125
+ // test
126
+ test . equals ( helloWorldWithData . render ( ) , 'Hello world!' + eol + 'Yeah, we got the subtitle from the JSON.' + eol ) ;
127
+ test . end ( ) ;
128
+ } ) ;
129
+
130
+ tap . test ( 'handlebars partials use the JSON environment from the calling pattern and can accept passed parameters' , function ( test ) {
131
+ test . plan ( 1 ) ;
132
+
133
+ // pattern paths
134
+ var atomPath = path . join ( '00-atoms' , '00-global' , '00-helloworld-withdata.hbs' ) ;
135
+ var molPath = path . join ( '00-molecules' , '00-global' , '00-call-atom-with-molecule-data.hbs' ) ;
136
+
137
+ // set up environment
138
+ var patternlab = new fakePatternLab ( ) ; // environment
139
+ var assembler = new pa ( ) ;
140
+
141
+ // do all the normal processing of the pattern
142
+ assembler . process_pattern_iterative ( atomPath , patternlab ) ;
143
+ var mol = assembler . process_pattern_iterative ( molPath , patternlab ) ;
144
+ assembler . process_pattern_recursive ( atomPath , patternlab ) ;
145
+ assembler . process_pattern_recursive ( molPath , patternlab ) ;
146
+
147
+ // test
148
+ 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 ) ;
149
+ test . end ( ) ;
150
+ } ) ;
151
+
152
+ tap . test ( 'find_pattern_partials finds partials' , function ( test ) {
153
+ testFindPartials ( test , [
154
+ "{{> molecules-comment-header}}" ,
155
+ "{{> molecules-comment-header}}" ,
156
+ "{{> " + eol + " molecules-comment-header" + eol + "}}" ,
157
+ "{{> molecules-weird-spacing }}" ,
158
+ "{{> molecules-ba_d-cha*rs }}"
159
+ ] ) ;
160
+ } ) ;
161
+
162
+ tap . test ( 'find_pattern_partials finds verbose partials' , function ( test ) {
163
+ testFindPartials ( test , [
164
+ '{{> 01-molecules/06-components/03-comment-header.hbs }}' ,
165
+ "{{> 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.') }}" ,
166
+ '{{> molecules-single-comment:foo }}' ,
167
+ "{{>atoms-error(message: 'That\'s no moon...')}}" ,
168
+ "{{> atoms-error(message: 'That\'s no moon...') }}" ,
169
+ '{{> 00-atoms/00-global/06-test }}'
170
+ ] ) ;
171
+ } ) ;
172
+
173
+ tap . test ( 'find_pattern_partials finds simple partials with parameters' , function ( test ) {
174
+ testFindPartials ( test , [
175
+ "{{> molecules-single-comment(description: 'A life isn\'t like a garden. Perfect moments can be had, but not preserved, except in memory.') }}" ,
176
+ '{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
177
+ ] ) ;
178
+ } ) ;
179
+
180
+ tap . test ( 'find_pattern_partials finds simple partials with style modifiers' , function ( test ) {
181
+ testFindPartials ( test , [
182
+ '{{> molecules-single-comment:foo }}'
183
+ ] ) ;
184
+ } ) ;
185
+
186
+ tap . test ( 'find_pattern_partials finds partials with handlebars parameters' , function ( test ) {
187
+ testFindPartials ( test , [
188
+ '{{> atoms-title title="bravo" headingLevel="2" headingSize="bravo" position="left"}}' ,
189
+ '{{> atoms-title title="bravo"' + eol + ' headingLevel="2"' + eol + ' headingSize="bravo"' + eol + ' position="left"}}' ,
190
+ '{{> atoms-title title="color <span style=\'font-weight:normal\'>midnight blue</span>" headingSize="charlie"}}' ,
191
+ '{{> atoms-input label="city" required=true}}' ,
192
+ '{{> organisms-product-filter filterData}}' ,
193
+ '{{> atoms-input email required=true}}' ,
194
+ '{{> molecules-storycard variants.flex }}' ,
195
+ '{{> myPartial name=../name }}'
196
+ ] ) ;
197
+ } ) ;
198
+
199
+ tap . test ( 'find_pattern_partials finds handlebars block partials' , function ( test ) {
200
+ testFindPartials ( test , [
201
+ '{{#> myPartial }}'
202
+ ] ) ;
203
+ } ) ;
204
+
205
+ tap . test ( 'hidden handlebars patterns can be called by their nice names' , function ( test ) {
206
+ const util = require ( './util/test_utils.js' ) ;
207
+
208
+ //arrange
209
+ const testPatternsPath = path . resolve ( __dirname , 'files' , '_handlebars-test-patterns' ) ;
210
+ const pl = util . fakePatternLab ( testPatternsPath ) ;
211
+ var pattern_assembler = new pa ( ) ;
212
+
213
+ var hiddenPatternPath = path . join ( '00-atoms' , '00-global' , '_00-hidden.hbs' ) ;
214
+ var hiddenPattern = pattern_assembler . process_pattern_iterative ( hiddenPatternPath , pl ) ;
215
+ pattern_assembler . process_pattern_recursive ( hiddenPatternPath , pl ) ;
216
+
217
+ var testPatternPath = path . join ( '00-molecules' , '00-global' , '00-hidden-pattern-tester.hbs' ) ;
218
+ var testPattern = pattern_assembler . process_pattern_iterative ( testPatternPath , pl ) ;
219
+ pattern_assembler . process_pattern_recursive ( testPatternPath , pl ) ;
220
+
221
+ //act
222
+ test . equals ( util . sanitized ( testPattern . render ( ) ) , util . sanitized ( 'Here\'s the hidden atom: [I\'m the hidden atom\n]\n' ) ) ;
223
+ test . end ( ) ;
224
+ } ) ;
0 commit comments