1
1
import test from 'ava' ;
2
2
import nock from 'nock' ;
3
3
import { stub } from 'sinon' ;
4
- import SemanticReleaseError from '@semantic-release/error' ;
5
4
import verify from '../lib/verify' ;
6
5
import { authenticate } from './helpers/mock-github' ;
7
6
@@ -147,29 +146,29 @@ test.serial('Throw SemanticReleaseError if "assets" option is not a String or an
147
146
process . env . GITHUB_TOKEN = 'github_token' ;
148
147
const assets = 42 ;
149
148
150
- const error = await t . throws (
149
+ const [ error ] = await t . throws (
151
150
verify (
152
151
{ assets} ,
153
152
{ options : { repositoryUrl : 'https://github.com/semantic-release/github.git' } , logger : t . context . logger }
154
153
)
155
154
) ;
156
155
157
- t . true ( error instanceof SemanticReleaseError ) ;
156
+ t . is ( error . name , ' SemanticReleaseError' ) ;
158
157
t . is ( error . code , 'EINVALIDASSETS' ) ;
159
158
} ) ;
160
159
161
160
test . serial ( 'Throw SemanticReleaseError if "assets" option is an Array with invalid elements' , async t => {
162
161
process . env . GITHUB_TOKEN = 'github_token' ;
163
162
const assets = [ 'file.js' , 42 ] ;
164
163
165
- const error = await t . throws (
164
+ const [ error ] = await t . throws (
166
165
verify (
167
166
{ assets} ,
168
167
{ options : { repositoryUrl : 'https://github.com/semantic-release/github.git' } , logger : t . context . logger }
169
168
)
170
169
) ;
171
170
172
- t . true ( error instanceof SemanticReleaseError ) ;
171
+ t . is ( error . name , ' SemanticReleaseError' ) ;
173
172
t . is ( error . code , 'EINVALIDASSETS' ) ;
174
173
} ) ;
175
174
@@ -257,14 +256,14 @@ test.serial('Throw SemanticReleaseError if "assets" option is an Object missing
257
256
process . env . GITHUB_TOKEN = 'github_token' ;
258
257
const assets = { name : 'file.js' } ;
259
258
260
- const error = await t . throws (
259
+ const [ error ] = await t . throws (
261
260
verify (
262
261
{ assets} ,
263
262
{ options : { repositoryUrl : 'https://github.com/semantic-release/github.git' } , logger : t . context . logger }
264
263
)
265
264
) ;
266
265
267
- t . true ( error instanceof SemanticReleaseError ) ;
266
+ t . is ( error . name , ' SemanticReleaseError' ) ;
268
267
t . is ( error . code , 'EINVALIDASSETS' ) ;
269
268
} ) ;
270
269
@@ -274,24 +273,24 @@ test.serial(
274
273
process . env . GITHUB_TOKEN = 'github_token' ;
275
274
const assets = [ { path : 'lib/file.js' } , { name : 'file.js' } ] ;
276
275
277
- const error = await t . throws (
276
+ const [ error ] = await t . throws (
278
277
verify (
279
278
{ assets} ,
280
279
{ options : { repositoryUrl : 'https://github.com/semantic-release/github.git' } , logger : t . context . logger }
281
280
)
282
281
) ;
283
282
284
- t . true ( error instanceof SemanticReleaseError ) ;
283
+ t . is ( error . name , ' SemanticReleaseError' ) ;
285
284
t . is ( error . code , 'EINVALIDASSETS' ) ;
286
285
}
287
286
) ;
288
287
289
288
test . serial ( 'Throw SemanticReleaseError for missing github token' , async t => {
290
- const error = await t . throws (
289
+ const [ error ] = await t . throws (
291
290
verify ( { } , { options : { repositoryUrl : 'https://github.com/semantic-release/github.git' } , logger : t . context . logger } )
292
291
) ;
293
292
294
- t . true ( error instanceof SemanticReleaseError ) ;
293
+ t . is ( error . name , ' SemanticReleaseError' ) ;
295
294
t . is ( error . code , 'ENOGHTOKEN' ) ;
296
295
} ) ;
297
296
@@ -303,21 +302,21 @@ test.serial('Throw SemanticReleaseError for invalid token', async t => {
303
302
. get ( `/repos/${ owner } /${ repo } ` )
304
303
. reply ( 401 ) ;
305
304
306
- const error = await t . throws (
305
+ const [ error ] = await t . throws (
307
306
verify ( { } , { options : { repositoryUrl : `https://github.com:${ owner } /${ repo } .git` } , logger : t . context . logger } )
308
307
) ;
309
308
310
- t . true ( error instanceof SemanticReleaseError ) ;
309
+ t . is ( error . name , ' SemanticReleaseError' ) ;
311
310
t . is ( error . code , 'EINVALIDGHTOKEN' ) ;
312
311
t . true ( github . isDone ( ) ) ;
313
312
} ) ;
314
313
315
314
test . serial ( 'Throw SemanticReleaseError for invalid repositoryUrl' , async t => {
316
315
process . env . GITHUB_TOKEN = 'github_token' ;
317
316
318
- const error = await t . throws ( verify ( { } , { options : { repositoryUrl : 'invalid_url' } , logger : t . context . logger } ) ) ;
317
+ const [ error ] = await t . throws ( verify ( { } , { options : { repositoryUrl : 'invalid_url' } , logger : t . context . logger } ) ) ;
319
318
320
- t . true ( error instanceof SemanticReleaseError ) ;
319
+ t . is ( error . name , ' SemanticReleaseError' ) ;
321
320
t . is ( error . code , 'EINVALIDGITURL' ) ;
322
321
} ) ;
323
322
@@ -329,11 +328,11 @@ test.serial("Throw SemanticReleaseError if token doesn't have the push permissio
329
328
. get ( `/repos/${ owner } /${ repo } ` )
330
329
. reply ( 200 , { permissions : { push : false } } ) ;
331
330
332
- const error = await t . throws (
331
+ const [ error ] = await t . throws (
333
332
verify ( { } , { options : { repositoryUrl : `https://github.com:${ owner } /${ repo } .git` } , logger : t . context . logger } )
334
333
) ;
335
334
336
- t . true ( error instanceof SemanticReleaseError ) ;
335
+ t . is ( error . name , ' SemanticReleaseError' ) ;
337
336
t . is ( error . code , 'EGHNOPERMISSION' ) ;
338
337
t . true ( github . isDone ( ) ) ;
339
338
} ) ;
@@ -346,11 +345,11 @@ test.serial("Throw SemanticReleaseError if the repository doesn't exist", async
346
345
. get ( `/repos/${ owner } /${ repo } ` )
347
346
. reply ( 404 ) ;
348
347
349
- const error = await t . throws (
348
+ const [ error ] = await t . throws (
350
349
verify ( { } , { options : { repositoryUrl : `https://github.com:${ owner } /${ repo } .git` } , logger : t . context . logger } )
351
350
) ;
352
351
353
- t . true ( error instanceof SemanticReleaseError ) ;
352
+ t . is ( error . name , ' SemanticReleaseError' ) ;
354
353
t . is ( error . code , 'EMISSINGREPO' ) ;
355
354
t . true ( github . isDone ( ) ) ;
356
355
} ) ;
@@ -372,9 +371,8 @@ test.serial('Throw error if github return any other errors', async t => {
372
371
} ) ;
373
372
374
373
test ( 'Throw SemanticReleaseError if "successComment" option is not a String' , async t => {
375
- process . env . GITHUB_TOKEN = 'github_token' ;
376
374
const successComment = 42 ;
377
- const error = await t . throws (
375
+ const [ error ] = await t . throws (
378
376
verify (
379
377
{ successComment} ,
380
378
{ options : { repositoryUrl : 'https://github.com/semantic-release/github.git' } , logger : t . context . logger }
@@ -386,9 +384,8 @@ test('Throw SemanticReleaseError if "successComment" option is not a String', as
386
384
} ) ;
387
385
388
386
test ( 'Throw SemanticReleaseError if "successComment" option is an empty String' , async t => {
389
- process . env . GITHUB_TOKEN = 'github_token' ;
390
387
const successComment = '' ;
391
- const error = await t . throws (
388
+ const [ error ] = await t . throws (
392
389
verify (
393
390
{ successComment} ,
394
391
{ options : { repositoryUrl : 'https://github.com/semantic-release/github.git' } , logger : t . context . logger }
@@ -400,9 +397,8 @@ test('Throw SemanticReleaseError if "successComment" option is an empty String',
400
397
} ) ;
401
398
402
399
test ( 'Throw SemanticReleaseError if "successComment" option is a whitespace String' , async t => {
403
- process . env . GITHUB_TOKEN = 'github_token' ;
404
400
const successComment = ' \n \r ' ;
405
- const error = await t . throws (
401
+ const [ error ] = await t . throws (
406
402
verify (
407
403
{ successComment} ,
408
404
{ options : { repositoryUrl : 'https://github.com/semantic-release/github.git' } , logger : t . context . logger }
0 commit comments