11import { escape } from 'querystring' ;
22import test from 'ava' ;
3+ import { stat } from 'fs-extra' ;
34import { stub , match } from 'sinon' ;
45import clearModule from 'clear-module' ;
56import SemanticReleaseError from '@semantic-release/error' ;
@@ -113,6 +114,8 @@ test.serial('Publish a release with an array of assets', async t => {
113114 const assetUrl = `https://github.com/${ owner } /${ repo } /releases/download/${ nextRelease . version } /upload.txt` ;
114115 const otherAssetUrl = `https://github.com/${ owner } /${ repo } /releases/download/${ nextRelease . version } /other_file.txt` ;
115116 const releaseId = 1 ;
117+ const uploadUri = `/api/uploads/repos/${ owner } /${ repo } /releases/${ releaseId } /assets` ;
118+ const uploadUrl = `https://github.com${ uploadUri } {?name,label}` ;
116119
117120 const github = authenticate ( { githubToken} )
118121 . get ( `/repos/${ owner } /${ repo } ` )
@@ -127,16 +130,22 @@ test.serial('Publish a release with an array of assets', async t => {
127130 name : nextRelease . gitTag ,
128131 body : nextRelease . notes ,
129132 } )
130- . reply ( 200 , { html_url : releaseUrl , id : releaseId } ) ;
131-
132- const githubUpload = upload ( { githubToken} )
133- . post ( `/repos/${ owner } /${ repo } /releases/${ releaseId } /assets?name=${ escape ( 'upload.txt' ) } ` )
134- . reply ( 200 , { browser_download_url : assetUrl } )
135- . post (
136- `/repos/${ owner } /${ repo } /releases/${ releaseId } /assets?name=${ escape ( 'other_file.txt' ) } &label=${ escape (
137- 'Other File'
138- ) } `
139- )
133+ . reply ( 200 , { upload_url : uploadUrl , html_url : releaseUrl } ) ;
134+
135+ const githubUpload1 = upload ( {
136+ githubToken,
137+ uploadUrl : 'https://github.com' ,
138+ contentLength : ( await stat ( 'test/fixtures/upload.txt' ) ) . size ,
139+ } )
140+ . post ( `${ uploadUri } ?name=${ escape ( 'upload.txt' ) } ` )
141+ . reply ( 200 , { browser_download_url : assetUrl } ) ;
142+
143+ const githubUpload2 = upload ( {
144+ githubToken,
145+ uploadUrl : 'https://github.com' ,
146+ contentLength : ( await stat ( 'test/fixtures/upload_other.txt' ) ) . size ,
147+ } )
148+ . post ( `${ uploadUri } ?name=${ escape ( 'other_file.txt' ) } &label=${ escape ( 'Other File' ) } ` )
140149 . reply ( 200 , { browser_download_url : otherAssetUrl } ) ;
141150
142151 await t . context . m . publish ( { githubToken, assets} , { nextRelease, options, logger : t . context . logger } ) ;
@@ -145,7 +154,8 @@ test.serial('Publish a release with an array of assets', async t => {
145154 t . true ( t . context . log . calledWith ( match . string , assetUrl ) ) ;
146155 t . true ( t . context . log . calledWith ( match . string , otherAssetUrl ) ) ;
147156 t . true ( github . isDone ( ) ) ;
148- t . true ( githubUpload . isDone ( ) ) ;
157+ t . true ( githubUpload1 . isDone ( ) ) ;
158+ t . true ( githubUpload2 . isDone ( ) ) ;
149159} ) ;
150160
151161test . serial ( 'Verify Github auth and release' , async t => {
@@ -166,6 +176,8 @@ test.serial('Verify Github auth and release', async t => {
166176 const assetUrl = `https://github.com/${ owner } /${ repo } /releases/download/${ nextRelease . version } /upload.txt` ;
167177 const otherAssetUrl = `https://github.com/${ owner } /${ repo } /releases/download/${ nextRelease . version } /other_file.txt` ;
168178 const releaseId = 1 ;
179+ const uploadUri = `/api/uploads/repos/${ owner } /${ repo } /releases/${ releaseId } /assets` ;
180+ const uploadUrl = `https://github.com${ uploadUri } {?name,label}` ;
169181
170182 const github = authenticate ( { githubToken : process . env . GH_TOKEN } )
171183 . get ( `/repos/${ owner } /${ repo } ` )
@@ -180,16 +192,22 @@ test.serial('Verify Github auth and release', async t => {
180192 name : nextRelease . gitTag ,
181193 body : nextRelease . notes ,
182194 } )
183- . reply ( 200 , { html_url : releaseUrl , id : releaseId } ) ;
184-
185- const githubUpload = upload ( { githubToken : process . env . GH_TOKEN } )
186- . post ( `/repos/${ owner } /${ repo } /releases/${ releaseId } /assets?name=${ escape ( 'upload.txt' ) } ` )
187- . reply ( 200 , { browser_download_url : assetUrl } )
188- . post (
189- `/repos/${ owner } /${ repo } /releases/${ releaseId } /assets?name=${ escape ( 'other_file.txt' ) } &label=${ escape (
190- 'Other File'
191- ) } `
192- )
195+ . reply ( 200 , { upload_url : uploadUrl , html_url : releaseUrl } ) ;
196+
197+ const githubUpload1 = upload ( {
198+ githubToken : process . env . GH_TOKEN ,
199+ uploadUrl : 'https://github.com' ,
200+ contentLength : ( await stat ( 'test/fixtures/upload.txt' ) ) . size ,
201+ } )
202+ . post ( `${ uploadUri } ?name=${ escape ( 'upload.txt' ) } ` )
203+ . reply ( 200 , { browser_download_url : assetUrl } ) ;
204+
205+ const githubUpload2 = upload ( {
206+ githubToken : process . env . GH_TOKEN ,
207+ uploadUrl : 'https://github.com' ,
208+ contentLength : ( await stat ( 'test/fixtures/upload_other.txt' ) ) . size ,
209+ } )
210+ . post ( `${ uploadUri } ?name=${ escape ( 'other_file.txt' ) } &label=${ escape ( 'Other File' ) } ` )
193211 . reply ( 200 , { browser_download_url : otherAssetUrl } ) ;
194212
195213 await t . notThrows ( t . context . m . verifyConditions ( { } , { options} ) ) ;
@@ -199,5 +217,6 @@ test.serial('Verify Github auth and release', async t => {
199217 t . true ( t . context . log . calledWith ( match . string , assetUrl ) ) ;
200218 t . true ( t . context . log . calledWith ( match . string , otherAssetUrl ) ) ;
201219 t . true ( github . isDone ( ) ) ;
202- t . true ( githubUpload . isDone ( ) ) ;
220+ t . true ( githubUpload1 . isDone ( ) ) ;
221+ t . true ( githubUpload2 . isDone ( ) ) ;
203222} ) ;
0 commit comments