@@ -158,6 +158,139 @@ describe('init', function () {
158158 expect ( semver . inc ( range , 'major' ) ) . not . to . equal ( null ) ;
159159
160160 } ) ;
161+
162+ it ( 'installs an adapter with --yarn' , function ( ) {
163+
164+ this . timeout ( config . maxTimeout ) ; // this could take a while
165+
166+ // SETUP
167+
168+ // Install an adapter
169+ commitizenInit ( sh , config . paths . endUserRepo , 'cz-conventional-changelog' , { yarn : true } ) ;
170+
171+ // TEST
172+
173+ // Check resulting json
174+ let packageJson = util . getParsedPackageJsonFromPath ( config . paths . endUserRepo ) ;
175+ expect ( packageJson ) . to . have . deep . property ( 'dependencies.cz-conventional-changelog' ) ;
176+
177+ } ) ;
178+
179+
180+ it ( 'installs an adapter with --yarn --dev' , function ( ) {
181+
182+ this . timeout ( config . maxTimeout ) ; // this could take a while
183+
184+ // SETUP
185+
186+ // Install an adapter
187+ commitizenInit ( sh , config . paths . endUserRepo , 'cz-conventional-changelog' , { yarn : true , dev : true } ) ;
188+
189+ // TEST
190+
191+ // Check resulting json
192+ let packageJson = util . getParsedPackageJsonFromPath ( config . paths . endUserRepo ) ;
193+ expect ( packageJson ) . to . have . deep . property ( 'devDependencies.cz-conventional-changelog' ) ;
194+
195+ } ) ;
196+
197+ it ( 'errors (with --yarn) on previously installed adapter' , function ( ) {
198+
199+ this . timeout ( config . maxTimeout ) ; // this could take a while
200+
201+ // SETUP
202+
203+ // Add a first adapter
204+ sh . cd ( config . paths . endUserRepo ) ;
205+ commitizenInit ( sh , config . paths . endUserRepo , 'cz-conventional-changelog' , { yarn : true , dev : true } ) ;
206+
207+ // TEST
208+ sh . cd ( config . paths . endUserRepo ) ;
209+ // Adding a second adapter
210+ expect ( function ( ) {
211+ commitizenInit ( sh , config . paths . endUserRepo , 'cz-jira-smart-commit' , { yarn : true , dev : true } ) ;
212+ } ) . to . throw ( / a l r e a d y c o n f i g u r e d / ) ;
213+
214+ // Check resulting json
215+ let packageJson = util . getParsedPackageJsonFromPath ( config . paths . endUserRepo ) ;
216+ expect ( packageJson ) . not . to . have . deep . property ( 'devDependencies' , 'cz-jira-smart-commit' ) ;
217+ expect ( packageJson ) . to . have . deep . property ( 'config.commitizen.path' , './node_modules/cz-conventional-changelog' ) ;
218+ // TODO: Eventually may need to offer both path and package keys. package = npm package name
219+ // Path for local development
220+ } ) ;
221+
222+ it ( 'succeeds (with --yarn) if force is true' , function ( ) {
223+
224+ this . timeout ( config . maxTimeout ) ; // this could take a while
225+
226+ // SETUP
227+
228+ // Add a first adapter
229+ sh . cd ( config . paths . endUserRepo ) ;
230+ commitizenInit ( sh , config . paths . endUserRepo , 'cz-conventional-changelog' , { yarn : true , dev : true } ) ;
231+
232+ // TEST
233+
234+ // Adding a second adapter
235+ expect ( function ( ) {
236+ commitizenInit ( sh , config . paths . endUserRepo , 'cz-jira-smart-commit' , { yarn : true , dev : true , force : true } ) ;
237+ } ) . to . not . throw ( ) ;
238+
239+ let packageJson = util . getParsedPackageJsonFromPath ( config . paths . endUserRepo ) ;
240+ expect ( packageJson . devDependencies ) . to . have . property ( 'cz-jira-smart-commit' ) ;
241+ expect ( packageJson ) . to . have . deep . property ( 'config.commitizen.path' , './node_modules/cz-jira-smart-commit' ) ;
242+
243+ } ) ;
244+
245+ it ( 'installs (with --yarn) an adapter without --save-exact' , function ( ) {
246+
247+ this . timeout ( config . maxTimeout ) ; // this could take a while
248+
249+ // SETUP
250+
251+ // Add a first adapter
252+ sh . cd ( config . paths . endUserRepo ) ;
253+ commitizenInit ( sh , config . paths . endUserRepo , 'cz-conventional-changelog' , { yarn : true , dev : true } ) ;
254+ let packageJson = util . getParsedPackageJsonFromPath ( config . paths . endUserRepo ) ;
255+
256+ // TEST
257+ expect ( packageJson . devDependencies ) . to . have . property ( 'cz-conventional-changelog' ) ;
258+ let range = packageJson . devDependencies [ 'cz-conventional-changelog' ] ;
259+
260+ // It should satisfy the requirements of a range
261+ expect ( semver . validRange ( range ) ) . to . not . equal ( null ) ;
262+
263+ // // But you CAN NOT increment a range
264+ // expect(semver.inc(range, 'major')).to.equal(null);
265+ // TODO: We need to figure out how to check if the repo has save exact set
266+ // in the config before we can re-enable this. The --save-exact setting
267+ // in our package.json breaks this test
268+
269+ } ) ;
270+
271+ it ( 'installs an adapter with --yarn --exact' , function ( ) {
272+
273+ this . timeout ( config . maxTimeout ) ; // this could take a while
274+
275+ // SETUP
276+
277+ // Add a first adapter
278+ sh . cd ( config . paths . endUserRepo ) ;
279+ commitizenInit ( sh , config . paths . endUserRepo , 'cz-conventional-changelog' , { yarn : true , dev : true , exact : true } ) ;
280+ let packageJson = util . getParsedPackageJsonFromPath ( config . paths . endUserRepo ) ;
281+
282+ // TEST
283+ expect ( packageJson . devDependencies ) . to . have . property ( 'cz-conventional-changelog' ) ;
284+ let range = packageJson . devDependencies [ 'cz-conventional-changelog' ] ;
285+
286+ // It should satisfy the requirements of a range
287+ expect ( semver . validRange ( range ) ) . to . not . equal ( null ) ;
288+
289+ // But you CAN increment a single version
290+ expect ( semver . inc ( range , 'major' ) ) . not . to . equal ( null ) ;
291+
292+ } ) ;
293+
161294} ) ;
162295
163296afterEach ( function ( ) {
0 commit comments