File tree Expand file tree Collapse file tree 3 files changed +21
-11
lines changed
Expand file tree Collapse file tree 3 files changed +21
-11
lines changed Original file line number Diff line number Diff line change 1- module . exports = SemanticReleaseError ;
2-
3- SemanticReleaseError . prototype = new Error ( ) ;
4-
5- function SemanticReleaseError ( message , code ) {
6- Error . captureStackTrace ( this , this . constructor ) ;
7- this . name = this . constructor . name ;
8- this . message = message ;
9- this . code = code ;
10- }
1+ module . exports = class SemanticReleaseError extends Error {
2+ constructor ( message , code ) {
3+ super ( message ) ;
4+ Error . captureStackTrace ( this , this . constructor ) ;
5+ this . name = this . constructor . name ;
6+ this . code = code ;
7+ }
8+ } ;
Original file line number Diff line number Diff line change 1+ import SemanticReleaseError from '../../index' ;
2+
3+ export default ( ) => {
4+ throw new SemanticReleaseError ( 'message' , 'code' ) ;
5+ } ;
Original file line number Diff line number Diff line change 11import test from 'ava' ;
22import SemanticReleaseError from '../index' ;
3+ import throwError from './helpers/throw-error' ;
34
45test ( 'Instanciates error' , t => {
56 const error = new SemanticReleaseError ( ) ;
@@ -14,11 +15,17 @@ test('Sets message', t => {
1415 t . is ( error . message , message ) ;
1516} ) ;
1617
17- test ( 'Sets message and code' , function ( t ) {
18+ test ( 'Sets message and code' , t => {
1819 const code = 'ENOFOO' ;
1920 const message = 'bar' ;
2021 const error = new SemanticReleaseError ( message , code ) ;
2122
2223 t . is ( error . code , code ) ;
2324 t . is ( error . message , message ) ;
2425} ) ;
26+
27+ test ( 'Include the stacktrace and name' , async t => {
28+ const error = await t . throws ( ( ) => throwError ( ) ) ;
29+ t . regex ( error . stack , / h e l p e r s \/ t h r o w - e r r o r / ) ;
30+ t . is ( error . name , 'SemanticReleaseError' ) ;
31+ } ) ;
You can’t perform that action at this time.
0 commit comments