11"use strict" ;
22
3- const { check, files, fixtures, bump } = require ( "../utils" ) ;
3+ const { check, info , files, fixtures, bump } = require ( "../utils" ) ;
44const { expect } = require ( "chai" ) ;
55
6- describe . skip ( "bump [files...]" , ( ) => {
6+ describe ( "bump [files...]" , ( ) => {
77
88 it ( "should update the package.json and package-lock.json by default" , ( ) => {
99 files . create ( "package.json" , { version : "1.2.3" } ) ;
@@ -19,26 +19,61 @@ describe.skip("bump [files...]", () => {
1919 `${ check } Updated package-lock.json to 2.0.0\n`
2020 ) ;
2121
22- expect ( files . json ( "package.json" ) . version ) . to . equal ( "2.0.0" ) ;
23- expect ( files . json ( "package-lock.json" ) . version ) . to . equal ( "2.0.0" ) ;
22+ expect ( files . json ( "package.json" ) ) . to . deep . equal ( { version : "2.0.0" } ) ;
23+ expect ( files . json ( "package-lock.json" ) ) . to . deep . equal ( { version : "2.0.0" } ) ;
24+ } ) ;
25+
26+ it ( "should not update package-lock.json if package.json is explicitly specified" , ( ) => {
27+ files . create ( "package.json" , { version : "1.2.3" } ) ;
28+ files . create ( "package-lock.json" , { version : "1.2.3" } ) ;
29+
30+ let cli = bump ( "major package.json" ) ;
31+
32+ expect ( cli ) . to . have . stderr ( "" ) ;
33+ expect ( cli ) . to . have . exitCode ( 0 ) ;
34+
35+ expect ( cli ) . to . have . stdout (
36+ `${ check } Updated package.json to 2.0.0\n`
37+ ) ;
38+
39+ expect ( files . json ( "package.json" ) ) . to . deep . equal ( { version : "2.0.0" } ) ;
40+ expect ( files . json ( "package-lock.json" ) ) . to . deep . equal ( { version : "1.2.3" } ) ;
2441 } ) ;
2542
2643 it ( "should not update package.json if package-lock.json is explicitly specified" , ( ) => {
2744 files . create ( "package.json" , { version : "1.2.3" } ) ;
2845 files . create ( "package-lock.json" , { version : "1.2.3" } ) ;
2946
30- let cli = bump ( "major" ) ;
47+ let cli = bump ( "major package-lock.json " ) ;
3148
3249 expect ( cli ) . to . have . stderr ( "" ) ;
3350 expect ( cli ) . to . have . exitCode ( 0 ) ;
3451
3552 expect ( cli ) . to . have . stdout (
36- `${ check } Updated package.json to 2.0.0\n` +
3753 `${ check } Updated package-lock.json to 2.0.0\n`
3854 ) ;
3955
40- expect ( files . json ( "package.json" ) . version ) . to . equal ( "2.0.0" ) ;
41- expect ( files . json ( "package-lock.json" ) . version ) . to . equal ( "2.0.0" ) ;
56+ expect ( files . json ( "package.json" ) ) . to . deep . equal ( { version : "1.2.3" } ) ;
57+ expect ( files . json ( "package-lock.json" ) ) . to . deep . equal ( { version : "2.0.0" } ) ;
58+ } ) ;
59+
60+ it ( "should not update package.json or package-lock.json if another file is explicitly specified" , ( ) => {
61+ files . create ( "package.json" , { version : "1.2.3" } ) ;
62+ files . create ( "package-lock.json" , { version : "1.2.3" } ) ;
63+ files . create ( "bower.json" , { version : "1.2.3" } ) ;
64+
65+ let cli = bump ( "major bower.json" ) ;
66+
67+ expect ( cli ) . to . have . stderr ( "" ) ;
68+ expect ( cli ) . to . have . exitCode ( 0 ) ;
69+
70+ expect ( cli ) . to . have . stdout (
71+ `${ check } Updated bower.json to 2.0.0\n`
72+ ) ;
73+
74+ expect ( files . json ( "package.json" ) ) . to . deep . equal ( { version : "1.2.3" } ) ;
75+ expect ( files . json ( "package-lock.json" ) ) . to . deep . equal ( { version : "1.2.3" } ) ;
76+ expect ( files . json ( "bower.json" ) ) . to . deep . equal ( { version : "2.0.0" } ) ;
4277 } ) ;
4378
4479 it ( "should replace the version number in non-manifest files" , ( ) => {
@@ -58,15 +93,21 @@ describe.skip("bump [files...]", () => {
5893 expect ( cli ) . to . have . stdout (
5994 `${ check } Updated LICENSE to 2.0.0\n` +
6095 `${ check } Updated README.md to 2.0.0\n` +
61- `${ check } Updated script1.js to 2.0.0\n`
96+ `${ check } Updated script1.js to 2.0.0\n` +
97+ `${ info } script2.js did not need to be updated\n` +
98+ `${ check } Updated subdir/deep/script1.js to 2.0.0\n` +
99+ `${ info } subdir/deep/script2.js did not need to be updated\n`
62100 ) ;
63101
64- expect ( files . json ( "package.json" ) . version ) . to . equal ( "2.0.0" ) ;
102+ expect ( files . json ( "package.json" ) ) . to . deep . equal ( { version : "1.2.3" } ) ;
65103 expect ( files . text ( "LICENSE" ) ) . to . match ( / M y A p p v 2 .0 .0 C o p y r i g h t / ) ;
66104 expect ( files . text ( "README.md" ) ) . to . match ( / v e r s i o n 2 .0 .0 a n d v 2 .0 .0 s h o u l d b o t h g e t u p d a t e d / ) ;
67- expect ( files . text ( "script1.js" ) ) . to . match ( / m a k e s u r e v 2 .0 .0 g e t s r e p l a c e d c o r r e c t l y / ) ;
68- expect ( files . text ( "script1.js" ) ) . to . match ( / l e t v e r s i o n = " 2 .0 .0 " ; / ) ;
105+ expect ( files . text ( "script1.js" ) ) . to . match ( / m a k e s u r e v 2 .0 .0 g e t s r e p l a c e d / ) ;
69106 expect ( files . text ( "script1.js" ) ) . to . match ( / l e t v e r s i o n = " 2 .0 .0 " ; / ) ;
107+ expect ( files . text ( "script2.js" ) ) . to . match ( / v e r s i o n 3 .2 .1 a n d v 8 .9 .1 0 d o n ' t m a t c h t h e o l d v e r s i o n n u m b e r / ) ;
108+ expect ( files . text ( "subdir/deep/script1.js" ) ) . to . match ( / m a k e s u r e v 2 .0 .0 g e t s r e p l a c e d / ) ;
109+ expect ( files . text ( "subdir/deep/script1.js" ) ) . to . match ( / l e t v e r s i o n = " 2 .0 .0 " ; / ) ;
110+ expect ( files . text ( "subdir/deep/script2.js" ) ) . to . match ( / v e r s i o n 3 .2 .1 a n d v 8 .9 .1 0 d o n ' t m a t c h t h e o l d v e r s i o n n u m b e r / ) ;
70111 } ) ;
71112
72113 it ( "should not replace other version fields in manifest files" , ( ) => {
@@ -83,13 +124,12 @@ describe.skip("bump [files...]", () => {
83124 `${ check } Updated package-lock.json to 2.0.0\n`
84125 ) ;
85126
86- expect ( files . text ( "README.md ") ) . to . match ( / v e r s i o n 5 . 6 . 7 a n d v 8 . 9 . 1 0 s h o u l d n o t b e c h a n g e d / ) ;
87- expect ( files . text ( "script2.js ") ) . to . match ( / v e r s i o n 3 . 2 . 1 a n d v 8 . 9 . 1 0 d o n ' t m a t c h t h e o l d v e r s i o n n u m b e r / ) ;
127+ expect ( files . json ( "package.json ") ) . to . deep . equal ( { version : "2.0.0" , notTheVersion : "1.2.3" } ) ;
128+ expect ( files . json ( "package-lock.json ") ) . to . deep . equal ( { version : "2.0.0" , notTheVersion : "1.2.3" } ) ;
88129 } ) ;
89130
90131 it ( "should not replace other version numbers in non-manifest files" , ( ) => {
91132 files . create ( "package.json" , { version : "1.2.3" } ) ;
92- files . create ( "package-lock.json" , { version : "1.2.3" } ) ;
93133 files . create ( "LICENSE" , fixtures . license ) ;
94134 files . create ( "README.md" , fixtures . readme ) ;
95135 files . create ( "script1.js" , fixtures . script1 ) ;
@@ -101,12 +141,13 @@ describe.skip("bump [files...]", () => {
101141 expect ( cli ) . to . have . exitCode ( 0 ) ;
102142
103143 expect ( cli ) . to . have . stdout (
104- `${ check } Updated package.json to 2.0.0\n` +
144+ `${ check } Updated LICENSE to 2.0.0\n` +
105145 `${ check } Updated README.md to 2.0.0\n` +
106146 `${ check } Updated script1.js to 2.0.0\n` +
107- `${ check } Updated LICENSE to 2.0.0 \n`
147+ `${ info } script2.js did not need to be updated \n`
108148 ) ;
109149
150+ expect ( files . text ( "LICENSE" ) ) . to . match ( / M y A p p v 2 .0 .0 C o p y r i g h t / ) ;
110151 expect ( files . text ( "README.md" ) ) . to . match ( / v e r s i o n 5 .6 .7 a n d v 8 .9 .1 0 s h o u l d n o t b e c h a n g e d / ) ;
111152 expect ( files . text ( "script2.js" ) ) . to . match ( / v e r s i o n 3 .2 .1 a n d v 8 .9 .1 0 d o n ' t m a t c h t h e o l d v e r s i o n n u m b e r / ) ;
112153 } ) ;
@@ -124,61 +165,42 @@ describe.skip("bump [files...]", () => {
124165 expect ( cli ) . to . have . exitCode ( 0 ) ;
125166
126167 expect ( cli ) . to . have . stdout (
127- `${ check } Updated package.json to 5.0.0\n`
168+ `${ info } LICENSE did not need to be updated\n` +
169+ `${ info } README.md did not need to be updated\n` +
170+ `${ info } script1.js did not need to be updated\n` +
171+ `${ info } script2.js did not need to be updated\n`
128172 ) ;
129173
130- expect ( files . json ( "package.json" ) . version ) . to . equal ( "5.0.0" ) ;
174+ expect ( files . json ( "package.json" ) ) . to . deep . equal ( { version : "4.5.6" } ) ;
131175 expect ( files . text ( "LICENSE" ) ) . to . match ( / M y A p p v 1 .2 .3 C o p y r i g h t / ) ;
132176 expect ( files . text ( "README.md" ) ) . to . match ( / v e r s i o n 5 .6 .7 a n d v 8 .9 .1 0 s h o u l d n o t b e c h a n g e d / ) ;
133177 expect ( files . text ( "README.md" ) ) . to . match ( / v e r s i o n 1 .2 .3 a n d v 1 .2 .3 s h o u l d b o t h g e t u p d a t e d / ) ;
134- expect ( files . text ( "script1.js" ) ) . to . match ( / m a k e s u r e v 1 .2 .3 g e t s r e p l a c e d c o r r e c t l y / ) ;
178+ expect ( files . text ( "script1.js" ) ) . to . match ( / m a k e s u r e v 1 .2 .3 g e t s r e p l a c e d / ) ;
135179 expect ( files . text ( "script1.js" ) ) . to . match ( / l e t v e r s i o n = " 1 .2 .3 " ; / ) ;
136180 expect ( files . text ( "script1.js" ) ) . to . match ( / l e t v e r s i o n = " 1 .2 .3 " ; / ) ;
137181 expect ( files . text ( "script2.js" ) ) . to . match ( / v e r s i o n 3 .2 .1 a n d v 8 .9 .1 0 d o n ' t m a t c h t h e o l d v e r s i o n n u m b e r / ) ;
138182 } ) ;
139183
140184 it ( "should error if an explicitly-specified file doesn't exist" , ( ) => {
141- files . create ( "package.json" , { version : "4.5.6" } ) ;
142-
143- let cli = bump ( "major LICENSE README.* *.js" ) ;
185+ files . create ( "package.json" , { version : "1.2.3" } ) ;
144186
145- expect ( cli ) . to . have . stderr ( "" ) ;
146- expect ( cli ) . to . have . exitCode ( 0 ) ;
187+ let cli = bump ( "major README.md" ) ;
147188
148- expect ( cli ) . to . have . stdout (
149- `${ check } Updated package.json to 5.0.0\n`
150- ) ;
189+ expect ( cli ) . to . have . stderr ( "Could not find file: README.md.\n" ) ;
190+ expect ( cli ) . to . have . exitCode ( 1 ) ;
151191
152- expect ( files . json ( "package.json" ) . version ) . to . equal ( "5.0.0" ) ;
153- expect ( files . text ( "LICENSE" ) ) . to . match ( / M y A p p v 1 .2 .3 C o p y r i g h t / ) ;
154- expect ( files . text ( "README.md" ) ) . to . match ( / v e r s i o n 5 .6 .7 a n d v 8 .9 .1 0 s h o u l d n o t b e c h a n g e d / ) ;
155- expect ( files . text ( "README.md" ) ) . to . match ( / v e r s i o n 1 .2 .3 a n d v 1 .2 .3 s h o u l d b o t h g e t u p d a t e d / ) ;
156- expect ( files . text ( "script1.js" ) ) . to . match ( / m a k e s u r e v 1 .2 .3 g e t s r e p l a c e d c o r r e c t l y / ) ;
157- expect ( files . text ( "script1.js" ) ) . to . match ( / l e t v e r s i o n = " 1 .2 .3 " ; / ) ;
158- expect ( files . text ( "script1.js" ) ) . to . match ( / l e t v e r s i o n = " 1 .2 .3 " ; / ) ;
159- expect ( files . text ( "script2.js" ) ) . to . match ( / v e r s i o n 3 .2 .1 a n d v 8 .9 .1 0 d o n ' t m a t c h t h e o l d v e r s i o n n u m b e r / ) ;
192+ expect ( files . json ( "package.json" ) ) . to . deep . equal ( { version : "1.2.3" } ) ;
160193 } ) ;
161194
162195 it ( "should error if a glob pattern doesn't match any files" , ( ) => {
163- files . create ( "package.json" , { version : "4.5.6 " } ) ;
196+ files . create ( "package.json" , { version : "1.2.3 " } ) ;
164197
165- let cli = bump ( "major README.* *.js" ) ;
198+ let cli = bump ( "major **/ *.js" ) ;
166199
167- expect ( cli ) . to . have . stderr ( "" ) ;
168- expect ( cli ) . to . have . exitCode ( 0 ) ;
200+ expect ( cli ) . to . have . stderr ( 'Could not find any files matching "**/*.js".\n' ) ;
201+ expect ( cli ) . to . have . exitCode ( 1 ) ;
169202
170- expect ( cli ) . to . have . stdout (
171- `${ check } Updated package.json to 5.0.0\n`
172- ) ;
173-
174- expect ( files . json ( "package.json" ) . version ) . to . equal ( "5.0.0" ) ;
175- expect ( files . text ( "LICENSE" ) ) . to . match ( / M y A p p v 1 .2 .3 C o p y r i g h t / ) ;
176- expect ( files . text ( "README.md" ) ) . to . match ( / v e r s i o n 5 .6 .7 a n d v 8 .9 .1 0 s h o u l d n o t b e c h a n g e d / ) ;
177- expect ( files . text ( "README.md" ) ) . to . match ( / v e r s i o n 1 .2 .3 a n d v 1 .2 .3 s h o u l d b o t h g e t u p d a t e d / ) ;
178- expect ( files . text ( "script1.js" ) ) . to . match ( / m a k e s u r e v 1 .2 .3 g e t s r e p l a c e d c o r r e c t l y / ) ;
179- expect ( files . text ( "script1.js" ) ) . to . match ( / l e t v e r s i o n = " 1 .2 .3 " ; / ) ;
180- expect ( files . text ( "script1.js" ) ) . to . match ( / l e t v e r s i o n = " 1 .2 .3 " ; / ) ;
181- expect ( files . text ( "script2.js" ) ) . to . match ( / v e r s i o n 3 .2 .1 a n d v 8 .9 .1 0 d o n ' t m a t c h t h e o l d v e r s i o n n u m b e r / ) ;
203+ expect ( files . json ( "package.json" ) ) . to . deep . equal ( { version : "1.2.3" } ) ;
182204 } ) ;
183205
184206} ) ;
0 commit comments