@@ -14,34 +14,22 @@ const fail = proxyquire('../lib/fail', {
1414 './get-client' : proxyquire ( '../lib/get-client' , { './definitions/rate-limit' : rateLimit } ) ,
1515} ) ;
1616
17- // Save the current process.env
18- const envBackup = Object . assign ( { } , process . env ) ;
19-
2017test . beforeEach ( t => {
21- // Delete env variables in case they are on the machine running the tests
22- delete process . env . GH_TOKEN ;
23- delete process . env . GITHUB_TOKEN ;
24- delete process . env . GH_URL ;
25- delete process . env . GITHUB_URL ;
26- delete process . env . GH_PREFIX ;
27- delete process . env . GITHUB_PREFIX ;
2818 // Mock logger
2919 t . context . log = stub ( ) ;
3020 t . context . error = stub ( ) ;
3121 t . context . logger = { log : t . context . log , error : t . context . error } ;
3222} ) ;
3323
3424test . afterEach . always ( ( ) => {
35- // Restore process.env
36- process . env = envBackup ;
3725 // Clear nock
3826 nock . cleanAll ( ) ;
3927} ) ;
4028
4129test . serial ( 'Open a new issue with the list of errors' , async t => {
4230 const owner = 'test_user' ;
4331 const repo = 'test_repo' ;
44- process . env . GITHUB_TOKEN = 'github_token' ;
32+ const env = { GITHUB_TOKEN : 'github_token' } ;
4533 const failTitle = 'The automated release is failing 🚨' ;
4634 const pluginConfig = { failTitle} ;
4735 const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
@@ -50,7 +38,7 @@ test.serial('Open a new issue with the list of errors', async t => {
5038 new SemanticReleaseError ( 'Error message 2' , 'ERR2' , 'Error 2 details' ) ,
5139 new SemanticReleaseError ( 'Error message 3' , 'ERR3' , 'Error 3 details' ) ,
5240 ] ;
53- const github = authenticate ( )
41+ const github = authenticate ( env )
5442 . get (
5543 `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
5644 'state:open'
@@ -64,7 +52,7 @@ test.serial('Open a new issue with the list of errors', async t => {
6452 } )
6553 . reply ( 200 , { html_url : 'https://github.com/issues/1' , number : 1 } ) ;
6654
67- await fail ( pluginConfig , { options, errors, logger : t . context . logger } ) ;
55+ await fail ( pluginConfig , { env , options, errors, logger : t . context . logger } ) ;
6856
6957 t . true ( t . context . log . calledWith ( 'Created issue #%d: %s.' , 1 , 'https://github.com/issues/1' ) ) ;
7058 t . true ( github . isDone ( ) ) ;
@@ -73,7 +61,7 @@ test.serial('Open a new issue with the list of errors', async t => {
7361test . serial ( 'Open a new issue with the list of errors, retrying 4 times' , async t => {
7462 const owner = 'test_user' ;
7563 const repo = 'test_repo' ;
76- process . env . GITHUB_TOKEN = 'github_token' ;
64+ const env = { GITHUB_TOKEN : 'github_token' } ;
7765 const failTitle = 'The automated release is failing 🚨' ;
7866 const pluginConfig = { failTitle} ;
7967 const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
@@ -82,7 +70,7 @@ test.serial('Open a new issue with the list of errors, retrying 4 times', async
8270 new SemanticReleaseError ( 'Error message 2' , 'ERR2' , 'Error 2 details' ) ,
8371 new SemanticReleaseError ( 'Error message 3' , 'ERR3' , 'Error 3 details' ) ,
8472 ] ;
85- const github = authenticate ( )
73+ const github = authenticate ( env )
8674 . get (
8775 `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
8876 'state:open'
@@ -110,7 +98,7 @@ test.serial('Open a new issue with the list of errors, retrying 4 times', async
11098 } )
11199 . reply ( 200 , { html_url : 'https://github.com/issues/1' , number : 1 } ) ;
112100
113- await fail ( pluginConfig , { options, errors, logger : t . context . logger } ) ;
101+ await fail ( pluginConfig , { env , options, errors, logger : t . context . logger } ) ;
114102
115103 t . true ( t . context . log . calledWith ( 'Created issue #%d: %s.' , 1 , 'https://github.com/issues/1' ) ) ;
116104 t . true ( github . isDone ( ) ) ;
@@ -119,7 +107,7 @@ test.serial('Open a new issue with the list of errors, retrying 4 times', async
119107test . serial ( 'Open a new issue with the list of errors and custom title and comment' , async t => {
120108 const owner = 'test_user' ;
121109 const repo = 'test_repo' ;
122- process . env . GITHUB_TOKEN = 'github_token' ;
110+ const env = { GITHUB_TOKEN : 'github_token' } ;
123111 const failTitle = 'Custom title' ;
124112 const failComment = `branch \${branch} \${errors[0].message} \${errors[1].message} \${errors[2].message}` ;
125113 const pluginConfig = { failTitle, failComment} ;
@@ -129,7 +117,7 @@ test.serial('Open a new issue with the list of errors and custom title and comme
129117 new SemanticReleaseError ( 'Error message 2' , 'ERR2' , 'Error 2 details' ) ,
130118 new SemanticReleaseError ( 'Error message 3' , 'ERR3' , 'Error 3 details' ) ,
131119 ] ;
132- const github = authenticate ( )
120+ const github = authenticate ( env )
133121 . get (
134122 `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
135123 'state:open'
@@ -143,7 +131,7 @@ test.serial('Open a new issue with the list of errors and custom title and comme
143131 } )
144132 . reply ( 200 , { html_url : 'https://github.com/issues/1' , number : 1 } ) ;
145133
146- await fail ( pluginConfig , { options, errors, logger : t . context . logger } ) ;
134+ await fail ( pluginConfig , { env , options, errors, logger : t . context . logger } ) ;
147135
148136 t . true ( t . context . log . calledWith ( 'Created issue #%d: %s.' , 1 , 'https://github.com/issues/1' ) ) ;
149137 t . true ( github . isDone ( ) ) ;
@@ -152,7 +140,7 @@ test.serial('Open a new issue with the list of errors and custom title and comme
152140test . serial ( 'Open a new issue with assignees and the list of errors' , async t => {
153141 const owner = 'test_user' ;
154142 const repo = 'test_repo' ;
155- process . env . GITHUB_TOKEN = 'github_token' ;
143+ const env = { GITHUB_TOKEN : 'github_token' } ;
156144 const failTitle = 'The automated release is failing 🚨' ;
157145 const assignees = [ 'user1' , 'user2' ] ;
158146 const pluginConfig = { failTitle, assignees} ;
@@ -161,7 +149,7 @@ test.serial('Open a new issue with assignees and the list of errors', async t =>
161149 new SemanticReleaseError ( 'Error message 1' , 'ERR1' , 'Error 1 details' ) ,
162150 new SemanticReleaseError ( 'Error message 2' , 'ERR2' , 'Error 2 details' ) ,
163151 ] ;
164- const github = authenticate ( )
152+ const github = authenticate ( env )
165153 . get (
166154 `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
167155 'state:open'
@@ -176,7 +164,7 @@ test.serial('Open a new issue with assignees and the list of errors', async t =>
176164 } )
177165 . reply ( 200 , { html_url : 'https://github.com/issues/1' , number : 1 } ) ;
178166
179- await fail ( pluginConfig , { options, errors, logger : t . context . logger } ) ;
167+ await fail ( pluginConfig , { env , options, errors, logger : t . context . logger } ) ;
180168
181169 t . true ( t . context . log . calledWith ( 'Created issue #%d: %s.' , 1 , 'https://github.com/issues/1' ) ) ;
182170 t . true ( github . isDone ( ) ) ;
@@ -185,7 +173,7 @@ test.serial('Open a new issue with assignees and the list of errors', async t =>
185173test . serial ( 'Open a new issue without labels and the list of errors' , async t => {
186174 const owner = 'test_user' ;
187175 const repo = 'test_repo' ;
188- process . env . GITHUB_TOKEN = 'github_token' ;
176+ const env = { GITHUB_TOKEN : 'github_token' } ;
189177 const failTitle = 'The automated release is failing 🚨' ;
190178 const labels = false ;
191179 const pluginConfig = { failTitle, labels} ;
@@ -194,7 +182,7 @@ test.serial('Open a new issue without labels and the list of errors', async t =>
194182 new SemanticReleaseError ( 'Error message 1' , 'ERR1' , 'Error 1 details' ) ,
195183 new SemanticReleaseError ( 'Error message 2' , 'ERR2' , 'Error 2 details' ) ,
196184 ] ;
197- const github = authenticate ( )
185+ const github = authenticate ( env )
198186 . get (
199187 `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
200188 'state:open'
@@ -208,7 +196,7 @@ test.serial('Open a new issue without labels and the list of errors', async t =>
208196 } )
209197 . reply ( 200 , { html_url : 'https://github.com/issues/1' , number : 1 } ) ;
210198
211- await fail ( pluginConfig , { options, errors, logger : t . context . logger } ) ;
199+ await fail ( pluginConfig , { env , options, errors, logger : t . context . logger } ) ;
212200
213201 t . true ( t . context . log . calledWith ( 'Created issue #%d: %s.' , 1 , 'https://github.com/issues/1' ) ) ;
214202 t . true ( github . isDone ( ) ) ;
@@ -217,7 +205,7 @@ test.serial('Open a new issue without labels and the list of errors', async t =>
217205test . serial ( 'Update the first existing issue with the list of errors' , async t => {
218206 const owner = 'test_user' ;
219207 const repo = 'test_repo' ;
220- process . env . GITHUB_TOKEN = 'github_token' ;
208+ const env = { GITHUB_TOKEN : 'github_token' } ;
221209 const failTitle = 'The automated release is failing 🚨' ;
222210 const pluginConfig = { failTitle} ;
223211 const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
@@ -231,7 +219,7 @@ test.serial('Update the first existing issue with the list of errors', async t =
231219 { number : 2 , body : `Issue 2 body\n\n${ ISSUE_ID } ` , title : failTitle } ,
232220 { number : 3 , body : `Issue 3 body\n\n${ ISSUE_ID } ` , title : failTitle } ,
233221 ] ;
234- const github = authenticate ( )
222+ const github = authenticate ( env )
235223 . get (
236224 `/search/issues?q=${ escape ( 'in:title' ) } +${ escape ( `repo:${ owner } /${ repo } ` ) } +${ escape ( 'type:issue' ) } +${ escape (
237225 'state:open'
@@ -243,7 +231,7 @@ test.serial('Update the first existing issue with the list of errors', async t =
243231 } )
244232 . reply ( 200 , { html_url : 'https://github.com/issues/2' , number : 2 } ) ;
245233
246- await fail ( pluginConfig , { options, errors, logger : t . context . logger } ) ;
234+ await fail ( pluginConfig , { env , options, errors, logger : t . context . logger } ) ;
247235
248236 t . true ( t . context . log . calledWith ( 'Found existing semantic-release issue #%d.' , 2 ) ) ;
249237 t . true ( t . context . log . calledWith ( 'Added comment to issue #%d: %s.' , 2 , 'https://github.com/issues/2' ) ) ;
0 commit comments