@@ -7,22 +7,213 @@ const chai = require('chai');
7
7
chai . use ( require ( 'chai-diff' ) ) ;
8
8
const expect = chai . expect ;
9
9
10
- module . exports = function ( grunt ) {
11
- grunt . registerTask ( 'test:bin' , function ( ) {
12
- const stdout = executeBinHandlebars (
10
+ const testCases = [
11
+ {
12
+ binInputParameters : [ '-a' , 'spec/artifacts/empty.handlebars' ] ,
13
+ outputLocation : 'stdout' ,
14
+ expectedOutputSpec : './spec/expected/empty.amd.js'
15
+ } ,
16
+ {
17
+ binInputParameters : [
13
18
'-a' ,
19
+ '-f' ,
20
+ 'TEST_OUTPUT' ,
14
21
'spec/artifacts/empty.handlebars'
15
- ) ;
22
+ ] ,
23
+ outputLocation : 'TEST_OUTPUT' ,
24
+ expectedOutputSpec : './spec/expected/empty.amd.js'
25
+ } ,
26
+ {
27
+ binInputParameters : [
28
+ '-a' ,
29
+ '-n' ,
30
+ 'CustomNamespace.templates' ,
31
+ 'spec/artifacts/empty.handlebars'
32
+ ] ,
33
+ outputLocation : 'stdout' ,
34
+ expectedOutputSpec : './spec/expected/empty.amd.namespace.js'
35
+ } ,
36
+ {
37
+ binInputParameters : [
38
+ '-a' ,
39
+ '--namespace' ,
40
+ 'CustomNamespace.templates' ,
41
+ 'spec/artifacts/empty.handlebars'
42
+ ] ,
43
+ outputLocation : 'stdout' ,
44
+ expectedOutputSpec : './spec/expected/empty.amd.namespace.js'
45
+ } ,
46
+ {
47
+ binInputParameters : [ '-a' , '-s' , 'spec/artifacts/empty.handlebars' ] ,
48
+ outputLocation : 'stdout' ,
49
+ expectedOutputSpec : './spec/expected/empty.amd.simple.js'
50
+ } ,
51
+ {
52
+ binInputParameters : [ '-a' , '-m' , 'spec/artifacts/empty.handlebars' ] ,
53
+ outputLocation : 'stdout' ,
54
+ expectedOutputSpec : './spec/expected/empty.amd.min.js'
55
+ } ,
56
+ {
57
+ binInputParameters : [
58
+ 'spec/artifacts/known.helpers.handlebars' ,
59
+ '-a' ,
60
+ '-k' ,
61
+ 'someHelper' ,
62
+ '-k' ,
63
+ 'anotherHelper' ,
64
+ '-o'
65
+ ] ,
66
+ outputLocation : 'stdout' ,
67
+ expectedOutputSpec : './spec/expected/non.empty.amd.known.helper.js'
68
+ } ,
69
+ {
70
+ binInputParameters : [ '--help' ] ,
71
+ outputLocation : 'stdout' ,
72
+ expectedOutputSpec : './spec/expected/help.menu.txt'
73
+ } ,
74
+ {
75
+ binInputParameters : [ '-v' ] ,
76
+ outputLocation : 'stdout' ,
77
+ expectedOutput : require ( '../package.json' ) . version
78
+ } ,
79
+ {
80
+ binInputParameters : [
81
+ '-a' ,
82
+ '-e' ,
83
+ 'hbs' ,
84
+ './spec/artifacts/non.default.extension.hbs'
85
+ ] ,
86
+ outputLocation : 'stdout' ,
87
+ expectedOutputSpec : './spec/expected/non.default.extension.amd.js'
88
+ } ,
89
+ {
90
+ binInputParameters : [
91
+ '-a' ,
92
+ '-p' ,
93
+ './spec/artifacts/partial.template.handlebars'
94
+ ] ,
95
+ outputLocation : 'stdout' ,
96
+ expectedOutputSpec : './spec/expected/partial.template.js'
97
+ } ,
98
+ {
99
+ binInputParameters : [ 'spec/artifacts/empty.handlebars' , '-c' ] ,
100
+ outputLocation : 'stdout' ,
101
+ expectedOutputSpec : './spec/expected/empty.common.js'
102
+ } ,
103
+ {
104
+ binInputParameters : [
105
+ 'spec/artifacts/empty.handlebars' ,
106
+ 'spec/artifacts/empty.handlebars' ,
107
+ '-a' ,
108
+ '-n' ,
109
+ 'someNameSpace'
110
+ ] ,
111
+ outputLocation : 'stdout' ,
112
+ expectedOutputSpec : './spec/expected/namespace.amd.js'
113
+ } ,
114
+ {
115
+ binInputParameters : [
116
+ 'spec/artifacts/empty.handlebars' ,
117
+ '-h' ,
118
+ 'some-path/' ,
119
+ '-a'
120
+ ] ,
121
+ outputLocation : 'stdout' ,
122
+ expectedOutputSpec : './spec/expected/handlebar.path.amd.js'
123
+ } ,
124
+ {
125
+ binInputParameters : [
126
+ 'spec/artifacts/partial.template.handlebars' ,
127
+ '-r' ,
128
+ 'spec' ,
129
+ '-a'
130
+ ] ,
131
+ outputLocation : 'stdout' ,
132
+ expectedOutputSpec : './spec/expected/empty.root.amd.js'
133
+ } ,
134
+ {
135
+ binInputParameters : [
136
+ '-i' ,
137
+ '<div>1</div>' ,
138
+ '-i' ,
139
+ '<div>2</div>' ,
140
+ '-N' ,
141
+ 'firstTemplate' ,
142
+ '-N' ,
143
+ 'secondTemplate' ,
144
+ '-a'
145
+ ] ,
146
+ outputLocation : 'stdout' ,
147
+ expectedOutputSpec : './spec/expected/empty.name.amd.js'
148
+ } ,
149
+ {
150
+ binInputParameters : [
151
+ '-i' ,
152
+ '<div>1</div>' ,
153
+ '-a' ,
154
+ '-m' ,
155
+ '-N' ,
156
+ 'test' ,
157
+ '--map' ,
158
+ './spec/artifacts/source.map.amd.txt'
159
+ ] ,
160
+ outputLocation : 'stdout' ,
161
+ expectedOutputSpec : './spec/expected/source.map.amd.js'
162
+ } ,
163
+ {
164
+ binInputParameters : [
165
+ '-i' ,
166
+ '<div>1</div>' ,
167
+ '-a' ,
168
+ '-m' ,
169
+ '-N' ,
170
+ 'test' ,
171
+ '--map' ,
172
+ './spec/artifacts/source.map.amd.txt'
173
+ ] ,
174
+ outputLocation : 'stdout' ,
175
+ expectedOutputSpec : './spec/expected/source.map.amd.js'
176
+ } ,
177
+ {
178
+ binInputParameters : [ './spec/artifacts/bom.handlebars' , '-b' , '-a' ] ,
179
+ outputLocation : 'stdout' ,
180
+ expectedOutputSpec : './spec/expected/bom.amd.js'
181
+ }
182
+ ] ;
16
183
17
- const expectedOutput = fs . readFileSync (
18
- './spec/expected/empty.amd.js' ,
19
- 'utf-8'
20
- ) ;
184
+ module . exports = function ( grunt ) {
185
+ grunt . registerTask ( 'test:bin' , function ( ) {
186
+ testCases . forEach (
187
+ ( {
188
+ binInputParameters,
189
+ outputLocation,
190
+ expectedOutputSpec,
191
+ expectedOutput
192
+ } ) => {
193
+ const stdout = executeBinHandlebars ( ...binInputParameters ) ;
194
+
195
+ if ( ! expectedOutput && expectedOutputSpec ) {
196
+ expectedOutput = fs . readFileSync ( expectedOutputSpec , 'utf-8' ) ;
197
+ }
21
198
22
- const normalizedOutput = normalizeCrlf ( stdout ) ;
23
- const normalizedExpectedOutput = normalizeCrlf ( expectedOutput ) ;
199
+ const useStdout = outputLocation === 'stdout' ;
200
+ const normalizedOutput = normalizeCrlf (
201
+ useStdout ? stdout : fs . readFileSync ( outputLocation , 'utf-8' )
202
+ ) ;
203
+ const normalizedExpectedOutput = normalizeCrlf ( expectedOutput ) ;
24
204
25
- expect ( normalizedOutput ) . not . to . be . differentFrom ( normalizedExpectedOutput ) ;
205
+ if ( ! useStdout ) {
206
+ fs . unlinkSync ( outputLocation ) ;
207
+ }
208
+
209
+ expect ( normalizedOutput ) . not . to . be . differentFrom (
210
+ normalizedExpectedOutput ,
211
+ {
212
+ relaxedSpace : true
213
+ }
214
+ ) ;
215
+ }
216
+ ) ;
26
217
} ) ;
27
218
} ;
28
219
0 commit comments