@@ -6,10 +6,13 @@ var extend = Object.assign || require('util')._extend
6
6
var shell = require ( 'shelljs' )
7
7
var fs = require ( 'fs' )
8
8
var path = require ( 'path' )
9
+ var stream = require ( 'stream' )
9
10
var mockGit = require ( 'mock-git' )
10
- var cliPath = path . resolve ( __dirname , './cli.js' )
11
+ var mockery = require ( 'mockery' )
12
+
13
+ var should = require ( 'chai' ) . should ( )
11
14
12
- require ( 'chai' ) . should ( )
15
+ var cliPath = path . resolve ( __dirname , './cli.js' )
13
16
14
17
function commit ( msg ) {
15
18
shell . exec ( 'git commit --allow-empty -m"' + msg + '"' )
@@ -214,3 +217,80 @@ describe('cli', function () {
214
217
result . stdout . should . not . match ( / n p m p u b l i s h / )
215
218
} )
216
219
} )
220
+
221
+ describe ( 'standard-version' , function ( ) {
222
+ beforeEach ( initInTempFolder )
223
+ afterEach ( finishTemp )
224
+
225
+ describe ( 'with mocked conventionalRecommendedBump' , function ( ) {
226
+ beforeEach ( function ( ) {
227
+ mockery . enable ( { warnOnUnregistered : false , useCleanCache : true } )
228
+ mockery . registerMock ( 'conventional-recommended-bump' , function ( _ , cb ) {
229
+ cb ( new Error ( 'bump err' ) )
230
+ } )
231
+ } )
232
+
233
+ afterEach ( function ( ) {
234
+ mockery . deregisterMock ( 'conventional-recommended-bump' )
235
+ mockery . disable ( )
236
+ } )
237
+
238
+ it ( 'should exit on bump error' , function ( done ) {
239
+ commit ( 'feat: first commit' )
240
+ shell . exec ( 'git tag -a v1.0.0 -m "my awesome first release"' )
241
+ commit ( 'feat: new feature!' )
242
+
243
+ require ( './index' ) ( { silent : true } , function ( err ) {
244
+ should . exist ( err )
245
+ err . message . should . match ( / b u m p e r r / )
246
+ done ( )
247
+ } )
248
+ } )
249
+ } )
250
+
251
+ describe ( 'with mocked conventionalChangelog' , function ( ) {
252
+ beforeEach ( function ( ) {
253
+ mockery . enable ( { warnOnUnregistered : false , useCleanCache : true } )
254
+ mockery . registerMock ( 'conventional-changelog' , function ( ) {
255
+ var readable = new stream . Readable ( { objectMode : true } )
256
+ readable . _read = function ( ) {
257
+ }
258
+ setImmediate ( readable . emit . bind ( readable ) , 'error' , new Error ( 'changelog err' ) )
259
+ return readable
260
+ } )
261
+ } )
262
+
263
+ afterEach ( function ( ) {
264
+ mockery . deregisterMock ( 'conventional-changelog' )
265
+ mockery . disable ( )
266
+ } )
267
+
268
+ it ( 'should exit on changelog error' , function ( done ) {
269
+ commit ( 'feat: first commit' )
270
+ shell . exec ( 'git tag -a v1.0.0 -m "my awesome first release"' )
271
+ commit ( 'feat: new feature!' )
272
+
273
+ require ( './index' ) ( { silent : true } , function ( err ) {
274
+ should . exist ( err )
275
+ err . message . should . match ( / c h a n g e l o g e r r / )
276
+ done ( )
277
+ } )
278
+ } )
279
+ } )
280
+
281
+ it ( 'formats the commit and tag messages appropriately' , function ( done ) {
282
+ commit ( 'feat: first commit' )
283
+ shell . exec ( 'git tag -a v1.0.0 -m "my awesome first release"' )
284
+ commit ( 'feat: new feature!' )
285
+
286
+ require ( './index' ) ( { silent : true } , function ( err ) {
287
+ should . not . exist ( err )
288
+
289
+ // check last commit message
290
+ shell . exec ( 'git log --oneline -n1' ) . stdout . should . match ( / c h o r e \( r e l e a s e \) : 1 \. 1 \. 0 / )
291
+ // check annotated tag message
292
+ shell . exec ( 'git tag -l -n1 v1.1.0' ) . stdout . should . match ( / c h o r e \( r e l e a s e \) : 1 \. 1 \. 0 / )
293
+ done ( )
294
+ } )
295
+ } )
296
+ } )
0 commit comments