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