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' , '_patterns' ) ;
7
9
var eol = require ( 'os' ) . EOL ;
8
10
11
+ // don't run these tests unless mustache is installed
12
+ var engineLoader = require ( '../core/lib/pattern_engines' ) ;
13
+ if ( ! engineLoader . mustache ) {
14
+ tap . test ( 'Mustache 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.
@@ -33,7 +44,7 @@ function fakePatternLab() {
33
44
34
45
// function for testing sets of partials
35
46
function testFindPartials ( test , partialTests ) {
36
- test . expect ( partialTests . length + 1 ) ;
47
+ test . plan ( partialTests . length + 1 ) ;
37
48
38
49
// setup current pattern from what we would have during execution
39
50
// docs on partial syntax are here:
@@ -55,11 +66,11 @@ function testFindPartials(test, partialTests) {
55
66
test . equals ( results [ index ] , testString ) ;
56
67
} ) ;
57
68
58
- test . done ( ) ;
69
+ test . end ( ) ;
59
70
}
60
71
61
72
function testFindPartialsWithStyleModifiers ( test , partialTests ) {
62
- test . expect ( partialTests . length + 1 ) ;
73
+ test . plan ( partialTests . length + 1 ) ;
63
74
64
75
// setup current pattern from what we would have during execution
65
76
// docs on partial syntax are here:
@@ -81,11 +92,11 @@ function testFindPartialsWithStyleModifiers(test, partialTests) {
81
92
test . equals ( results [ index ] , testString ) ;
82
93
} ) ;
83
94
84
- test . done ( ) ;
95
+ test . end ( ) ;
85
96
}
86
97
87
98
function testFindPartialsWithPatternParameters ( test , partialTests ) {
88
- test . expect ( partialTests . length + 1 ) ;
99
+ test . plan ( partialTests . length + 1 ) ;
89
100
90
101
// setup current pattern from what we would have during execution
91
102
// docs on partial syntax are here:
@@ -107,110 +118,106 @@ function testFindPartialsWithPatternParameters(test, partialTests) {
107
118
test . equals ( results [ index ] , testString ) ;
108
119
} ) ;
109
120
110
- test . done ( ) ;
121
+ test . end ( ) ;
111
122
}
112
123
113
- exports [ 'engine_mustache' ] = {
114
- 'find_pattern_partials finds one simple partial' : function ( test ) {
115
- testFindPartials ( test , [
116
- "{{> molecules-comment-header}}"
117
- ] ) ;
118
- } ,
119
-
120
- 'find_pattern_partials finds simple partials under stressed circumstances' : function ( test ) {
121
- testFindPartials ( test , [
122
- "{{>molecules-comment-header}}" ,
123
- "{{> " + eol + " molecules-comment-header" + eol + "}}" ,
124
- "{{> molecules-weird-spacing }}"
125
- ] ) ;
126
- } ,
127
-
128
- 'find_pattern_partials finds one simple verbose partial' : function ( test ) {
129
- testFindPartials ( test , [
130
- '{{> 00-atoms/00-global/06-test }}'
131
- ] ) ;
132
- } ,
133
-
134
- 'find_pattern_partials finds partials with parameters' : function ( test ) {
135
- testFindPartials ( test , [
136
- "{{> molecules-single-comment(description: true) }}" ,
137
- "{{> molecules-single-comment(description: 42) }}" ,
138
- "{{> molecules-single-comment(description: '42') }}" ,
139
- "{{> molecules-single-comment(description: \"42\") }}" ,
140
- "{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}" ,
141
- "{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}" ,
142
- '{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
143
- ] ) ;
144
- } ,
145
-
146
- 'find_pattern_partials finds simple partials with style modifiers' : function ( test ) {
147
- testFindPartials ( test , [
148
- '{{> molecules-single-comment:foo }}' ,
149
- '{{> molecules-single-comment:foo|bar }}'
150
- ] ) ;
151
- } ,
152
- 'find_pattern_partials finds mixed partials' : function ( test ) {
153
- testFindPartials ( test , [
154
- '{{> molecules-single-comment:foo(description: "test", anotherThing: true) }}' ,
155
- '{{> molecules-single-comment:foo|bar(description: true) }}'
156
- ] ) ;
157
- } ,
158
-
159
- 'find_pattern_partials finds one simple partial with styleModifier' : function ( test ) {
160
- testFindPartialsWithStyleModifiers ( test , [
161
- "{{> molecules-comment-header:test}}"
162
- ] ) ;
163
- } ,
164
- 'find_pattern_partials finds partial with many styleModifiers' : function ( test ) {
165
- testFindPartialsWithStyleModifiers ( test , [
166
- "{{> molecules-comment-header:test|test2|test3}}"
167
- ] ) ;
168
- } ,
169
- 'find_pattern_partials finds partials with differing styleModifiers' : function ( test ) {
170
- testFindPartialsWithStyleModifiers ( test , [
171
- "{{> molecules-comment-header:test|test2|test3}}" ,
172
- "{{> molecules-comment-header:foo-1}}" ,
173
- "{{> molecules-comment-header:bar_1}}"
174
- ] ) ;
175
- } ,
176
- 'find_pattern_partials finds partials with styleModifiers when parameters present' : function ( test ) {
177
- testFindPartialsWithStyleModifiers ( test , [
178
- "{{> molecules-comment-header:test|test2|test3(description: true)}}" ,
179
- "{{> molecules-comment-header:foo-1(description: 'foo')}}" ,
180
- "{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
181
- ] ) ;
182
- } ,
183
-
184
- 'find_pattern_partials_with_parameters finds one simple partial with parameters' : function ( test ) {
185
- testFindPartialsWithPatternParameters ( test , [
186
- "{{> molecules-comment-header(description: 'test')}}"
187
- ] ) ;
188
- } ,
189
- 'find_pattern_partials_with_parameters finds partials with parameters' : function ( test ) {
190
- testFindPartialsWithPatternParameters ( test , [
191
- "{{> molecules-single-comment(description: true) }}" ,
192
- "{{> molecules-single-comment(description: 42) }}" ,
193
- "{{> molecules-single-comment(description: '42') }}" ,
194
- "{{> molecules-single-comment(description: \"42\") }}" ,
195
- "{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}" ,
196
- "{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}" ,
197
- '{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
198
- ] ) ;
199
- } ,
200
- 'find_pattern_partials finds partials with parameters when styleModifiers present' : function ( test ) {
201
- testFindPartialsWithPatternParameters ( test , [
202
- "{{> molecules-comment-header:test|test2|test3(description: true)}}" ,
203
- "{{> molecules-comment-header:foo-1(description: 'foo')}}" ,
204
- "{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
205
- ] ) ;
206
- }
207
-
208
- } ;
209
124
210
-
211
- // don't run these tests unless mustache is installed
212
- var engineLoader = require ( '../core/lib/pattern_engines' ) ;
213
- if ( ! engineLoader . mustache ) {
214
- console . log ( "Mustache engine not installed, skipping tests." ) ;
215
- delete exports . engine_mustache ;
216
- }
125
+ tap . test ( 'find_pattern_partials finds one simple partial' , function ( test ) {
126
+ testFindPartials ( test , [
127
+ "{{> molecules-comment-header}}"
128
+ ] ) ;
129
+ } ) ;
130
+
131
+ tap . test ( 'find_pattern_partials finds simple partials under stressed circumstances' , function ( test ) {
132
+ testFindPartials ( test , [
133
+ "{{>molecules-comment-header}}" ,
134
+ "{{> " + eol + " molecules-comment-header" + eol + "}}" ,
135
+ "{{> molecules-weird-spacing }}"
136
+ ] ) ;
137
+ } ) ;
138
+
139
+ tap . test ( 'find_pattern_partials finds one simple verbose partial' , function ( test ) {
140
+ testFindPartials ( test , [
141
+ '{{> 00-atoms/00-global/06-test }}'
142
+ ] ) ;
143
+ } ) ;
144
+
145
+ tap . test ( 'find_pattern_partials finds partials with parameters' , function ( test ) {
146
+ testFindPartials ( test , [
147
+ "{{> molecules-single-comment(description: true) }}" ,
148
+ "{{> molecules-single-comment(description: 42) }}" ,
149
+ "{{> molecules-single-comment(description: '42') }}" ,
150
+ "{{> molecules-single-comment(description: \"42\") }}" ,
151
+ "{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}" ,
152
+ "{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}" ,
153
+ '{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
154
+ ] ) ;
155
+ } ) ;
156
+
157
+ tap . test ( 'find_pattern_partials finds simple partials with style modifiers' , function ( test ) {
158
+ testFindPartials ( test , [
159
+ '{{> molecules-single-comment:foo }}' ,
160
+ '{{> molecules-single-comment:foo|bar }}'
161
+ ] ) ;
162
+ } ) ;
163
+
164
+ tap . test ( 'find_pattern_partials finds mixed partials' , function ( test ) {
165
+ testFindPartials ( test , [
166
+ '{{> molecules-single-comment:foo(description: "test", anotherThing: true) }}' ,
167
+ '{{> molecules-single-comment:foo|bar(description: true) }}'
168
+ ] ) ;
169
+ } ) ;
170
+
171
+ tap . test ( 'find_pattern_partials finds one simple partial with styleModifier' , function ( test ) {
172
+ testFindPartialsWithStyleModifiers ( test , [
173
+ "{{> molecules-comment-header:test}}"
174
+ ] ) ;
175
+ } ) ;
176
+
177
+ tap . test ( 'find_pattern_partials finds partial with many styleModifiers' , function ( test ) {
178
+ testFindPartialsWithStyleModifiers ( test , [
179
+ "{{> molecules-comment-header:test|test2|test3}}"
180
+ ] ) ;
181
+ } ) ;
182
+
183
+ tap . test ( 'find_pattern_partials finds partials with differing styleModifiers' , function ( test ) {
184
+ testFindPartialsWithStyleModifiers ( test , [
185
+ "{{> molecules-comment-header:test|test2|test3}}" ,
186
+ "{{> molecules-comment-header:foo-1}}" ,
187
+ "{{> molecules-comment-header:bar_1}}"
188
+ ] ) ;
189
+ } ) ;
190
+
191
+ tap . test ( 'find_pattern_partials finds partials with styleModifiers when parameters present' , function ( test ) {
192
+ testFindPartialsWithStyleModifiers ( test , [
193
+ "{{> molecules-comment-header:test|test2|test3(description: true)}}" ,
194
+ "{{> molecules-comment-header:foo-1(description: 'foo')}}" ,
195
+ "{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
196
+ ] ) ;
197
+ } ) ;
198
+
199
+ tap . test ( 'find_pattern_partials_with_parameters finds one simple partial with parameters' , function ( test ) {
200
+ testFindPartialsWithPatternParameters ( test , [
201
+ "{{> molecules-comment-header(description: 'test')}}"
202
+ ] ) ;
203
+ } ) ;
204
+
205
+ tap . test ( 'find_pattern_partials_with_parameters finds partials with parameters' , function ( test ) {
206
+ testFindPartialsWithPatternParameters ( test , [
207
+ "{{> molecules-single-comment(description: true) }}" ,
208
+ "{{> molecules-single-comment(description: 42) }}" ,
209
+ "{{> molecules-single-comment(description: '42') }}" ,
210
+ "{{> molecules-single-comment(description: \"42\") }}" ,
211
+ "{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}" ,
212
+ "{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}" ,
213
+ '{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
214
+ ] ) ;
215
+ } ) ;
216
+
217
+ tap . test ( 'find_pattern_partials finds partials with parameters when styleModifiers present' , function ( test ) {
218
+ testFindPartialsWithPatternParameters ( test , [
219
+ "{{> molecules-comment-header:test|test2|test3(description: true)}}" ,
220
+ "{{> molecules-comment-header:foo-1(description: 'foo')}}" ,
221
+ "{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
222
+ ] ) ;
223
+ } ) ;
0 commit comments