11import { describe , expect , it , jest } from '@jest/globals' ;
22import prompts from 'prompts' ;
3- import { _getQuestionsForPackage } from '../../changefile/promptForChange ' ;
4- import { ChangeFilePromptOptions } from '../../types/ChangeFilePrompt' ;
3+ import { getQuestionsForPackage } from '../../changefile/getQuestionsForPackage ' ;
4+ import { ChangeFilePromptOptions , ChangeTypeDescriptions } from '../../types/ChangeFilePrompt' ;
55import { initMockLogs } from '../../__fixtures__/mockLogs' ;
66import { makePackageInfos } from '../../__fixtures__/packageInfos' ;
77
8- /**
9- * This covers the first part of `promptForChange`: determining what questions to ask for each package.
10- */
11- describe ( 'promptForChange _getQuestionsForPackage' , ( ) => {
8+ describe ( 'getQuestionsForPackage' , ( ) => {
129 /** Package name used in the tests */
1310 const pkg = 'foo' ;
1411
15- /** Basic params for `_getQuestionsForPackage `, for a package named `foo` */
16- const defaultQuestionsParams : Parameters < typeof _getQuestionsForPackage > [ 0 ] = {
12+ /** Basic params for `getQuestionsForPackage `, for a package named `foo` */
13+ const defaultQuestionsParams : Parameters < typeof getQuestionsForPackage > [ 0 ] = {
1714 pkg,
1815 packageInfos : makePackageInfos ( { [ pkg ] : { } } ) ,
1916 packageGroups : { } ,
@@ -24,14 +21,14 @@ describe('promptForChange _getQuestionsForPackage', () => {
2421 const logs = initMockLogs ( ) ;
2522
2623 it ( 'works in basic case' , ( ) => {
27- const questions = _getQuestionsForPackage ( defaultQuestionsParams ) ;
24+ const questions = getQuestionsForPackage ( defaultQuestionsParams ) ;
2825 expect ( questions ) . toEqual ( [
2926 {
3027 choices : [
31- { title : expect . stringContaining ( 'Patch' ) , value : 'patch' } ,
32- { title : expect . stringContaining ( 'Minor' ) , value : 'minor' } ,
33- { title : expect . stringContaining ( 'None' ) , value : 'none' } ,
34- { title : expect . stringContaining ( 'Major' ) , value : 'major' } ,
28+ { title : ' [1mPatch[22m - bug fixes; no API changes' , value : 'patch' } ,
29+ { title : ' [1mMinor[22m - new feature; backwards-compatible API changes' , value : 'minor' } ,
30+ { title : ' [1mNone[22m - this change does not affect the published package in any way' , value : 'none' } ,
31+ { title : ' [1mMajor[22m - breaking changes; major feature' , value : 'major' } ,
3532 ] ,
3633 message : 'Change type' ,
3734 name : 'type' ,
@@ -48,9 +45,29 @@ describe('promptForChange _getQuestionsForPackage', () => {
4845 ] ) ;
4946 } ) ;
5047
48+ it ( 'uses different descriptions for v0 package' , ( ) => {
49+ const questions = getQuestionsForPackage ( {
50+ ...defaultQuestionsParams ,
51+ packageInfos : makePackageInfos ( { [ pkg ] : { version : '0.1.0' } } ) ,
52+ } ) ;
53+ expect ( questions ! [ 0 ] . choices ) . toEqual ( [
54+ {
55+ title :
56+ ' [1mPatch[22m - bug fixes; new features; backwards-compatible API changes (ok in patches for v0.x packages)' ,
57+ value : 'patch' ,
58+ } ,
59+ {
60+ title : ' [1mMinor[22m - breaking changes; major feature (ok in minor versions for v0.x packages)' ,
61+ value : 'minor' ,
62+ } ,
63+ { title : ' [1mNone[22m - this change does not affect the published package in any way' , value : 'none' } ,
64+ { title : ' [1mMajor[22m - official release' , value : 'major' } ,
65+ ] ) ;
66+ } ) ;
67+
5168 // it's somewhat debatable if this is correct (maybe --type should be the override for disallowedChangeTypes?)
5269 it ( 'errors if options.type is disallowed' , ( ) => {
53- const questions = _getQuestionsForPackage ( {
70+ const questions = getQuestionsForPackage ( {
5471 ...defaultQuestionsParams ,
5572 packageInfos : makePackageInfos ( { [ pkg ] : { combinedOptions : { disallowedChangeTypes : [ 'major' ] } } } ) ,
5673 options : { type : 'major' , message : '' } ,
@@ -60,7 +77,7 @@ describe('promptForChange _getQuestionsForPackage', () => {
6077 } ) ;
6178
6279 it ( 'errors if there are no valid change types for package' , ( ) => {
63- const questions = _getQuestionsForPackage ( {
80+ const questions = getQuestionsForPackage ( {
6481 ...defaultQuestionsParams ,
6582 packageInfos : makePackageInfos ( {
6683 [ pkg ] : { combinedOptions : { disallowedChangeTypes : [ 'major' , 'minor' , 'patch' , 'none' ] } } ,
@@ -71,7 +88,7 @@ describe('promptForChange _getQuestionsForPackage', () => {
7188 } ) ;
7289
7390 it ( 'respects disallowedChangeTypes' , ( ) => {
74- const questions = _getQuestionsForPackage ( {
91+ const questions = getQuestionsForPackage ( {
7592 ...defaultQuestionsParams ,
7693 packageInfos : makePackageInfos ( { [ pkg ] : { combinedOptions : { disallowedChangeTypes : [ 'major' ] } } } ) ,
7794 } ) ;
@@ -80,7 +97,7 @@ describe('promptForChange _getQuestionsForPackage', () => {
8097 } ) ;
8198
8299 it ( 'allows prerelease change for package with prerelease version' , ( ) => {
83- const questions = _getQuestionsForPackage ( {
100+ const questions = getQuestionsForPackage ( {
84101 ...defaultQuestionsParams ,
85102 packageInfos : makePackageInfos ( { [ pkg ] : { version : '1.0.0-beta.1' } } ) ,
86103 } ) ;
@@ -90,7 +107,7 @@ describe('promptForChange _getQuestionsForPackage', () => {
90107
91108 // this is a bit weird as well, but documenting current behavior
92109 it ( 'excludes prerelease if disallowed' , ( ) => {
93- const questions = _getQuestionsForPackage ( {
110+ const questions = getQuestionsForPackage ( {
94111 ...defaultQuestionsParams ,
95112 packageInfos : makePackageInfos ( {
96113 [ pkg ] : { version : '1.0.0-beta.1' , combinedOptions : { disallowedChangeTypes : [ 'prerelease' ] } } ,
@@ -101,7 +118,7 @@ describe('promptForChange _getQuestionsForPackage', () => {
101118 } ) ;
102119
103120 it ( 'excludes the change type question when options.type is specified' , ( ) => {
104- const questions = _getQuestionsForPackage ( {
121+ const questions = getQuestionsForPackage ( {
105122 ...defaultQuestionsParams ,
106123 options : { type : 'patch' , message : '' } ,
107124 } ) ;
@@ -110,7 +127,7 @@ describe('promptForChange _getQuestionsForPackage', () => {
110127 } ) ;
111128
112129 it ( 'excludes the change type question with only one valid option' , ( ) => {
113- const questions = _getQuestionsForPackage ( {
130+ const questions = getQuestionsForPackage ( {
114131 ...defaultQuestionsParams ,
115132 packageInfos : makePackageInfos ( {
116133 [ pkg ] : { combinedOptions : { disallowedChangeTypes : [ 'major' , 'minor' , 'none' ] } } ,
@@ -121,7 +138,7 @@ describe('promptForChange _getQuestionsForPackage', () => {
121138 } ) ;
122139
123140 it ( 'excludes the change type question when prerelease is implicitly the only valid option' , ( ) => {
124- const questions = _getQuestionsForPackage ( {
141+ const questions = getQuestionsForPackage ( {
125142 ...defaultQuestionsParams ,
126143 packageInfos : makePackageInfos ( {
127144 [ pkg ] : {
@@ -135,7 +152,7 @@ describe('promptForChange _getQuestionsForPackage', () => {
135152 } ) ;
136153
137154 it ( 'excludes the comment question when options.message is set' , ( ) => {
138- const questions = _getQuestionsForPackage ( {
155+ const questions = getQuestionsForPackage ( {
139156 ...defaultQuestionsParams ,
140157 options : { message : 'message' } ,
141158 } ) ;
@@ -147,7 +164,7 @@ describe('promptForChange _getQuestionsForPackage', () => {
147164 const customQuestions : prompts . PromptObject [ ] = [ { name : 'custom' , message : 'custom prompt' , type : 'text' } ] ;
148165 const changePrompt : ChangeFilePromptOptions [ 'changePrompt' ] = jest . fn ( ( ) => customQuestions ) ;
149166
150- const questions = _getQuestionsForPackage ( {
167+ const questions = getQuestionsForPackage ( {
151168 ...defaultQuestionsParams ,
152169 packageInfos : makePackageInfos ( { [ pkg ] : { combinedOptions : { changeFilePrompt : { changePrompt } } } } ) ,
153170 } ) ;
@@ -163,10 +180,50 @@ describe('promptForChange _getQuestionsForPackage', () => {
163180 ) ;
164181 } ) ;
165182
183+ it ( 'uses options.changeTypeDescriptions if set' , ( ) => {
184+ const changeTypeDescriptions : ChangeTypeDescriptions = {
185+ major : 'exciting' ,
186+ minor : { v0 : 'exciting v0!' , general : 'boring' } ,
187+ premajor : 'almost exciting' ,
188+ } ;
189+ const questions = getQuestionsForPackage ( {
190+ ...defaultQuestionsParams ,
191+ packageInfos : makePackageInfos ( {
192+ [ pkg ] : { version : '1.0.0' , combinedOptions : { changeFilePrompt : { changeTypeDescriptions } } } ,
193+ } ) ,
194+ } ) ;
195+
196+ expect ( questions ! [ 0 ] . choices ) . toEqual ( [
197+ { title : ' [1mMajor[22m - exciting' , value : 'major' } ,
198+ { title : ' [1mMinor[22m - boring' , value : 'minor' } ,
199+ { title : ' [1mPremajor[22m - almost exciting' , value : 'premajor' } ,
200+ ] ) ;
201+ } ) ;
202+
203+ it ( 'uses v0-specific options.changeTypeDescriptions if set' , ( ) => {
204+ const changeTypeDescriptions : ChangeTypeDescriptions = {
205+ major : 'exciting' ,
206+ minor : { v0 : 'exciting v0!' , general : 'boring' } ,
207+ premajor : 'almost exciting' ,
208+ } ;
209+ const questions = getQuestionsForPackage ( {
210+ ...defaultQuestionsParams ,
211+ packageInfos : makePackageInfos ( {
212+ [ pkg ] : { version : '0.1.0' , combinedOptions : { changeFilePrompt : { changeTypeDescriptions } } } ,
213+ } ) ,
214+ } ) ;
215+
216+ expect ( questions ! [ 0 ] . choices ) . toEqual ( [
217+ { title : ' [1mMajor[22m - exciting' , value : 'major' } ,
218+ { title : ' [1mMinor[22m - exciting v0!' , value : 'minor' } ,
219+ { title : ' [1mPremajor[22m - almost exciting' , value : 'premajor' } ,
220+ ] ) ;
221+ } ) ;
222+
166223 it ( 'does case-insensitive filtering on description suggestions' , async ( ) => {
167224 const recentMessages = [ 'Foo' , 'Bar' , 'Baz' ] ;
168225 const recentMessageChoices = [ { title : 'Foo' } , { title : 'Bar' } , { title : 'Baz' } ] ;
169- const questions = _getQuestionsForPackage ( { ...defaultQuestionsParams , recentMessages } ) ;
226+ const questions = getQuestionsForPackage ( { ...defaultQuestionsParams , recentMessages } ) ;
170227 expect ( questions ) . toEqual ( [
171228 expect . anything ( ) ,
172229 expect . objectContaining ( {
0 commit comments