1
- var version = require ( ' ../' ) ,
2
- assert = require ( ' assert' ) ,
3
- fs = require ( 'fs' ) ,
4
- vinylFs = require ( ' vinyl-fs' ) ,
5
- path = require ( ' path' ) ,
6
- cp = require ( ' child_process' ) ,
7
- File = require ( ' vinyl' ) ,
8
- through = require ( ' through2' ) ,
9
- fUtil = require ( ' ../lib/files' ) ,
10
- git = require ( ' ../lib/git' ) ;
11
-
12
- describe ( ' git' , function ( ) {
13
- var filename = ' package.json' ;
14
- var expectedPath = path . join ( __dirname , ' ./fixtures/' , filename ) ;
1
+ var version = require ( " ../" ) ,
2
+ assert = require ( " assert" ) ,
3
+ fs = require ( "fs" ) ,
4
+ vinylFs = require ( " vinyl-fs" ) ,
5
+ path = require ( " path" ) ,
6
+ cp = require ( " child_process" ) ,
7
+ File = require ( " vinyl" ) ,
8
+ through = require ( " through2" ) ,
9
+ fUtil = require ( " ../lib/files" ) ,
10
+ git = require ( " ../lib/git" ) ;
11
+
12
+ describe ( " git" , function ( ) {
13
+ var filename = " package.json" ;
14
+ var expectedPath = path . join ( __dirname , " ./fixtures/" , filename ) ;
15
15
var expectedContent = fs . readFileSync ( expectedPath ) ;
16
16
17
17
var original = fUtil . loadFiles ;
@@ -21,19 +21,19 @@ describe('git', function () {
21
21
var originalCommit = git . commit ;
22
22
var originalCheckout = git . checkout ;
23
23
24
- before ( function ( ) {
24
+ before ( function ( ) {
25
25
vinylFs . dest = function ( ) {
26
26
return through . obj ( function ( file , enc , next ) {
27
27
this . push ( file ) ;
28
28
next ( ) ;
29
29
} ) ;
30
- }
30
+ } ;
31
31
32
32
var expectedFile = new File ( {
33
33
base : __dirname ,
34
34
cwd : __dirname ,
35
35
path : expectedPath ,
36
- contents : expectedContent
36
+ contents : expectedContent ,
37
37
} ) ;
38
38
39
39
fUtil . loadFiles = function ( ) {
@@ -57,130 +57,162 @@ describe('git', function () {
57
57
cp . exec = exec ;
58
58
} ) ;
59
59
60
- describe ( ' #Update()' , function ( ) {
61
- it ( ' should return error on unclean git repository when commit is given' , function ( done ) {
60
+ describe ( " #Update()" , function ( ) {
61
+ it ( " should return error on unclean git repository when commit is given" , function ( done ) {
62
62
git . isRepositoryClean = function ( cb ) {
63
- return cb ( new Error ( ' Not clean' ) ) ;
63
+ return cb ( new Error ( " Not clean" ) ) ;
64
64
} ;
65
65
66
- version . update ( {
67
- version : '1.0.0' ,
68
- commitMessage : 'Message'
69
- } , function ( err , data ) {
70
- assert . ok ( err ) ;
71
- assert . equal ( err . message , 'Not clean' , 'Error message should be set by isRepositoryClean' ) ;
66
+ version . update (
67
+ {
68
+ version : "1.0.0" ,
69
+ commitMessage : "Message" ,
70
+ } ,
71
+ function ( err , data ) {
72
+ assert . ok ( err ) ;
73
+ assert . equal (
74
+ err . message ,
75
+ "Not clean" ,
76
+ "Error message should be set by isRepositoryClean"
77
+ ) ;
78
+
79
+ done ( ) ;
80
+ }
81
+ ) ;
82
+ } ) ;
72
83
84
+ it ( "should return NOT error on unclean git repository when no commit message is given" , function ( done ) {
85
+ git . isRepositoryClean = function ( cb ) {
86
+ return cb ( new Error ( "Not clean" ) ) ;
87
+ } ;
88
+
89
+ version . update ( "1.0.0" , function ( err , data ) {
90
+ assert . ifError ( err ) ;
73
91
done ( ) ;
74
92
} ) ;
75
93
} ) ;
76
94
77
- it ( ' should return NOT error on unclean git repository when no commit message is given' , function ( done ) {
95
+ it ( " should sanitize commit message" , function ( done ) {
78
96
git . isRepositoryClean = function ( cb ) {
79
- return cb ( new Error ( 'Not clean' ) ) ;
97
+ return cb ( null ) ;
80
98
} ;
81
99
82
- version . update ( '1.0.0' , function ( err , data ) {
83
- assert . ifError ( err ) ;
100
+ cp . exec = function ( cmd , extra , cb ) {
101
+ if ( cmd . indexOf ( "-a" ) === - 1 ) return cb ( null ) ;
102
+ assert . equal ( 'git tag -a v1.0.0 -m "Message \\`touch file\\`"' , cmd ) ;
84
103
done ( ) ;
104
+ } ;
105
+
106
+ version . update ( {
107
+ version : "1.0.0" ,
108
+ commitMessage : "Message `touch file`" ,
85
109
} ) ;
86
110
} ) ;
87
111
88
- it ( ' should get updated version sent to commit when commit message is given' , function ( done ) {
112
+ it ( " should get updated version sent to commit when commit message is given" , function ( done ) {
89
113
git . isRepositoryClean = function ( cb ) {
90
114
return cb ( null ) ;
91
115
} ;
92
116
93
117
git . commit = function ( files , message , newVer , tagName , callback ) {
94
- assert . equal ( message , ' Message' ) ;
95
- assert . equal ( newVer , ' 1.0.0' ) ;
118
+ assert . equal ( message , " Message" ) ;
119
+ assert . equal ( newVer , " 1.0.0" ) ;
96
120
assert . equal ( files [ 0 ] , expectedPath ) ;
97
- assert . equal ( tagName , ' v1.0.0' ) ;
121
+ assert . equal ( tagName , " v1.0.0" ) ;
98
122
return callback ( null ) ;
99
123
} ;
100
124
101
- version . update ( {
102
- version : '1.0.0' ,
103
- commitMessage : 'Message'
104
- } , function ( err , data ) {
105
- assert . ifError ( err ) ;
106
- done ( ) ;
107
- } ) ;
125
+ version . update (
126
+ {
127
+ version : "1.0.0" ,
128
+ commitMessage : "Message" ,
129
+ } ,
130
+ function ( err , data ) {
131
+ assert . ifError ( err ) ;
132
+ done ( ) ;
133
+ }
134
+ ) ;
108
135
} ) ;
109
136
110
- it ( ' should be able to override tagName' , function ( done ) {
137
+ it ( " should be able to override tagName" , function ( done ) {
111
138
git . isRepositoryClean = function ( cb ) {
112
139
return cb ( null ) ;
113
140
} ;
114
141
115
142
git . commit = function ( files , message , newVer , tagName , callback ) {
116
- assert . equal ( tagName , ' v1.0.0-src' ) ;
143
+ assert . equal ( tagName , " v1.0.0-src" ) ;
117
144
return callback ( null ) ;
118
145
} ;
119
146
120
- version . update ( {
121
- version : '1.0.0' ,
122
- commitMessage : 'Message' ,
123
- tagName : 'v%s-src'
124
- } , function ( err , data ) {
125
- assert . ifError ( err ) ;
126
- done ( ) ;
127
- } ) ;
147
+ version . update (
148
+ {
149
+ version : "1.0.0" ,
150
+ commitMessage : "Message" ,
151
+ tagName : "v%s-src" ,
152
+ } ,
153
+ function ( err , data ) {
154
+ assert . ifError ( err ) ;
155
+ done ( ) ;
156
+ }
157
+ ) ;
128
158
} ) ;
129
159
130
- it ( ' should get flag defining if v-prefix should be used or not' , function ( done ) {
160
+ it ( " should get flag defining if v-prefix should be used or not" , function ( done ) {
131
161
git . isRepositoryClean = function ( cb ) {
132
162
return cb ( null ) ;
133
163
} ;
134
164
135
165
git . commit = function ( files , message , newVer , noPrefix , callback ) {
136
- assert . ok ( noPrefix , ' No prefix should be true' ) ;
166
+ assert . ok ( noPrefix , " No prefix should be true" ) ;
137
167
return callback ( null ) ;
138
168
} ;
139
169
140
- version . update ( {
141
- version : '1.0.0' ,
142
- commitMessage : 'Message' ,
143
- noPrefix : true
144
- } , function ( err , data ) {
145
- assert . ifError ( err ) ;
146
- done ( ) ;
147
- } ) ;
170
+ version . update (
171
+ {
172
+ version : "1.0.0" ,
173
+ commitMessage : "Message" ,
174
+ noPrefix : true ,
175
+ } ,
176
+ function ( err , data ) {
177
+ assert . ifError ( err ) ;
178
+ done ( ) ;
179
+ }
180
+ ) ;
148
181
} ) ;
149
182
150
- it ( ' should make tag with v-prefix per default' , function ( done ) {
183
+ it ( " should make tag with v-prefix per default" , function ( done ) {
151
184
git . isRepositoryClean = function ( cb ) {
152
185
return cb ( null ) ;
153
186
} ;
154
187
155
188
cp . exec = function ( cmd , extra , cb ) {
156
- if ( cmd . indexOf ( '-a' ) === - 1 ) return cb ( null ) ;
189
+ if ( cmd . indexOf ( "-a" ) === - 1 ) return cb ( null ) ;
157
190
assert . equal ( 'git tag -a v1.0.0 -m "Message"' , cmd ) ;
158
191
done ( ) ;
159
192
} ;
160
193
161
194
version . update ( {
162
- version : ' 1.0.0' ,
163
- commitMessage : ' Message'
195
+ version : " 1.0.0" ,
196
+ commitMessage : " Message" ,
164
197
} ) ;
165
198
} ) ;
166
199
167
- it ( ' should make tag without v-prefix if specified' , function ( done ) {
200
+ it ( " should make tag without v-prefix if specified" , function ( done ) {
168
201
git . isRepositoryClean = function ( cb ) {
169
202
return cb ( null ) ;
170
203
} ;
171
204
172
205
cp . exec = function ( cmd , extra , cb ) {
173
- if ( cmd . indexOf ( '-a' ) === - 1 ) return cb ( null ) ;
206
+ if ( cmd . indexOf ( "-a" ) === - 1 ) return cb ( null ) ;
174
207
assert . equal ( 'git tag -a 1.0.0 -m "Message"' , cmd ) ;
175
208
done ( ) ;
176
209
} ;
177
210
178
211
version . update ( {
179
- version : ' 1.0.0' ,
180
- commitMessage : ' Message' ,
181
- noPrefix : true
212
+ version : " 1.0.0" ,
213
+ commitMessage : " Message" ,
214
+ noPrefix : true ,
182
215
} ) ;
183
216
} ) ;
184
217
} ) ;
185
-
186
- } ) ;
218
+ } ) ;
0 commit comments