@@ -18,25 +18,50 @@ vi.mock("@changesets/get-github-info", () => {
1818 pull : `[#${ data . pull } ](https://github.com/${ data . repo } /pull/${ data . pull } )` ,
1919 commit : `[\`${ data . commit } \`](https://github.com/${ data . repo } /commit/${ data . commit } )` ,
2020 } ;
21- return {
22- getInfo : vi . fn ( async ( { commit, repo } ) => {
23- expect ( commit ) . toBe ( data . commit ) ;
24- expect ( repo ) . toBe ( data . repo ) ;
21+
22+ const getInfoFn = vi . fn ( async ( { commit, repo } ) => {
23+ expect ( repo ) . toBe ( data . repo ) ;
24+ if ( commit === data . commit ) {
2525 return {
2626 pull : data . pull ,
2727 user : data . user ,
28- links,
28+ links : {
29+ user : links . user ,
30+ commit : links . commit ,
31+ pull : links . pull ,
32+ } ,
2933 } ;
30- } ) ,
31- getInfoFromPullRequest : vi . fn ( async ( { pull, repo } ) => {
32- expect ( pull ) . toBe ( data . pull ) ;
33- expect ( repo ) . toBe ( data . repo ) ;
34+ }
35+ return {
36+ pull : data . pull ,
37+ user : data . user ,
38+ links : {
39+ user : links . user ,
40+ commit : `[\`${ commit } \`](https://github.com/${ repo } /commit/${ commit } )` ,
41+ pull : links . pull ,
42+ } ,
43+ } ;
44+ } ) ;
45+
46+ const getInfoFromPullRequestFn = vi . fn ( async ( { pull, repo } ) => {
47+ expect ( repo ) . toBe ( data . repo ) ;
48+ if ( pull === data . pull ) {
3449 return {
3550 commit : data . commit ,
3651 user : data . user ,
37- links,
52+ links : {
53+ user : links . user ,
54+ commit : links . commit ,
55+ pull : links . pull ,
56+ } ,
3857 } ;
39- } ) ,
58+ }
59+ throw new Error ( `Unexpected pull request: ${ pull } ` ) ;
60+ } ) ;
61+
62+ return {
63+ getInfo : getInfoFn ,
64+ getInfoFromPullRequest : getInfoFromPullRequestFn ,
4065 } ;
4166} ) ;
4267
@@ -113,92 +138,30 @@ describe("Changeset formatter", () => {
113138 }
114139 ) ;
115140
116- describe . each ( [ "author" , "user" ] ) (
117- "override author with %s keyword" ,
118- ( keyword ) => {
119- it . each ( [
120- [ "with @" , `${ keyword } : @other` ] ,
121- [ "without @" , `${ keyword } : other` ] ,
122- ] ) ( "%s" , async ( name , content ) => {
123- const result = await getReleaseLine (
124- ...getChangeset ( content , data . commit , true )
125- ) ;
126- expect ( result ) . toEqual (
127- `- something ([#${ data . pull } ](https://github.com/${ data . repo } /pull/${ data . pull } ))\n\n**Credits**\nHuge thanks to @other for helping!`
128- ) ;
129- } ) ;
130- }
131- ) ;
132-
133- it ( "with multiple authors" , async ( ) => {
134- const result = await getReleaseLine (
135- ...getChangeset (
136- [ "author: @Gawdfrey" , "author: @thymas1" ] . join ( "\n" ) ,
137- data . commit ,
138- true
139- )
140- ) ;
141-
142- expect ( result ) . toEqual (
143- `- something ([#${ data . pull } ](https://github.com/${ data . repo } /pull/${ data . pull } ))\n\n**Credits**\nHuge thanks to @Gawdfrey and @thymas1 for helping!`
144- ) ;
145- } ) ;
146-
147141 describe ( "multiple changes" , ( ) => {
148142 it ( "should only show credits after last change" , async ( ) => {
149143 // First change
150144 const firstResult = await getReleaseLine (
151- ...getChangeset ( "author: @Gawdfrey " , data . commit , false , "first change" )
145+ ...getChangeset ( "" , data . commit , false , "first change" )
152146 ) ;
153147 expect ( firstResult ) . toEqual (
154148 `- first change ([#${ data . pull } ](https://github.com/${ data . repo } /pull/${ data . pull } ))`
155149 ) ;
156150
157151 // Second change
158152 const secondResult = await getReleaseLine (
159- ...getChangeset ( "author: @thymas1 " , data . commit , false , "second change" )
153+ ...getChangeset ( "" , data . commit , false , "second change" )
160154 ) ;
161155 expect ( secondResult ) . toEqual (
162156 `- second change ([#${ data . pull } ](https://github.com/${ data . repo } /pull/${ data . pull } ))`
163157 ) ;
164158
165159 // Last change
166160 const lastResult = await getReleaseLine (
167- ...getChangeset ( "author: @huozhi" , data . commit , true , "third change" )
168- ) ;
169- expect ( lastResult ) . toEqual (
170- `- third change ([#${ data . pull } ](https://github.com/${ data . repo } /pull/${ data . pull } ))\n\n**Credits**\nHuge thanks to @Gawdfrey, @huozhi, and @thymas1 for helping!`
171- ) ;
172- } ) ;
173-
174- it ( "should combine authors from all changes" , async ( ) => {
175- // First change with GitHub author
176- const firstResult = await getReleaseLine (
177- ...getChangeset ( "" , data . commit , false , "first change" )
178- ) ;
179- expect ( firstResult ) . toEqual (
180- `- first change ([#${ data . pull } ](https://github.com/${ data . repo } /pull/${ data . pull } ))`
181- ) ;
182-
183- // Second change with explicit author
184- const secondResult = await getReleaseLine (
185- ...getChangeset ( "author: @thymas1" , data . commit , false , "second change" )
186- ) ;
187- expect ( secondResult ) . toEqual (
188- `- second change ([#${ data . pull } ](https://github.com/${ data . repo } /pull/${ data . pull } ))`
189- ) ;
190-
191- // Last change with multiple authors
192- const lastResult = await getReleaseLine (
193- ...getChangeset (
194- [ "author: @huozhi" , "author: @ijjk" ] . join ( "\n" ) ,
195- data . commit ,
196- true ,
197- "third change"
198- )
161+ ...getChangeset ( "" , data . commit , true , "third change" )
199162 ) ;
200163 expect ( lastResult ) . toEqual (
201- `- third change ([#${ data . pull } ](https://github.com/${ data . repo } /pull/${ data . pull } ))\n\n**Credits**\nHuge thanks to @Gawdfrey, @huozhi, @ijjk, and @thymas1 for helping!`
164+ `- third change ([#${ data . pull } ](https://github.com/${ data . repo } /pull/${ data . pull } ))\n\n**Credits**\nHuge thanks to @Gawdfrey for helping!`
202165 ) ;
203166 } ) ;
204167 } ) ;
0 commit comments