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 1
1
import test from 'ava' ;
2
2
import SemanticReleaseError from '../index' ;
3
+ import throwError from './helpers/throw-error' ;
3
4
4
5
test ( 'Instanciates error' , t => {
5
6
const error = new SemanticReleaseError ( ) ;
@@ -14,11 +15,17 @@ test('Sets message', t => {
14
15
t . is ( error . message , message ) ;
15
16
} ) ;
16
17
17
- test ( 'Sets message and code' , function ( t ) {
18
+ test ( 'Sets message and code' , t => {
18
19
const code = 'ENOFOO' ;
19
20
const message = 'bar' ;
20
21
const error = new SemanticReleaseError ( message , code ) ;
21
22
22
23
t . is ( error . code , code ) ;
23
24
t . is ( error . message , message ) ;
24
25
} ) ;
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