@@ -12,6 +12,11 @@ const nock = require('nock');
12
12
13
13
process . env . NODE_TLS_REJECT_UNAUTHORIZED = '0' ;
14
14
15
+ function shouldIncludeStackWithThisFile ( err ) {
16
+ err . stack . should . match ( / t e s t \/ s u p e r t e s t .j s : / ) ;
17
+ err . stack . should . startWith ( err . name + ':' ) ;
18
+ }
19
+
15
20
describe ( 'request(url)' , function ( ) {
16
21
it ( 'should be supported' , function ( done ) {
17
22
const app = express ( ) ;
@@ -359,7 +364,7 @@ describe('request(app)', function () {
359
364
. expect ( 404 )
360
365
. end ( function ( err , res ) {
361
366
err . message . should . equal ( 'expected 404 "Not Found", got 200 "OK"' ) ;
362
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
367
+ shouldIncludeStackWithThisFile ( err ) ;
363
368
done ( ) ;
364
369
} ) ;
365
370
} ) ;
@@ -420,7 +425,7 @@ describe('request(app)', function () {
420
425
. expect ( 200 , '' )
421
426
. end ( function ( err , res ) {
422
427
err . message . should . equal ( 'expected \'\' response body, got \'foo\'' ) ;
423
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
428
+ shouldIncludeStackWithThisFile ( err ) ;
424
429
done ( ) ;
425
430
} ) ;
426
431
} ) ;
@@ -442,7 +447,7 @@ describe('request(app)', function () {
442
447
. expect ( 'hey' )
443
448
. end ( function ( err , res ) {
444
449
err . message . should . equal ( 'expected \'hey\' response body, got \'{"foo":"bar"}\'' ) ;
445
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
450
+ shouldIncludeStackWithThisFile ( err ) ;
446
451
done ( ) ;
447
452
} ) ;
448
453
} ) ;
@@ -462,7 +467,7 @@ describe('request(app)', function () {
462
467
. expect ( 'hey' )
463
468
. end ( function ( err , res ) {
464
469
err . message . should . equal ( 'expected 200 "OK", got 500 "Internal Server Error"' ) ;
465
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
470
+ shouldIncludeStackWithThisFile ( err ) ;
466
471
done ( ) ;
467
472
} ) ;
468
473
} ) ;
@@ -495,7 +500,7 @@ describe('request(app)', function () {
495
500
. expect ( { foo : 'baz' } )
496
501
. end ( function ( err , res ) {
497
502
err . message . should . equal ( 'expected { foo: \'baz\' } response body, got { foo: \'bar\' }' ) ;
498
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
503
+ shouldIncludeStackWithThisFile ( err ) ;
499
504
500
505
request ( app )
501
506
. get ( '/' )
@@ -527,7 +532,7 @@ describe('request(app)', function () {
527
532
. expect ( { stringValue : 'foo' , numberValue : 3 , nestedObject : { innerString : 5 } } )
528
533
. end ( function ( err , res ) {
529
534
err . message . should . equal ( 'expected {\n stringValue: \'foo\',\n numberValue: 3,\n nestedObject: { innerString: 5 }\n} response body, got {\n stringValue: \'foo\',\n numberValue: 3,\n nestedObject: { innerString: \'5\' }\n}' ) ; // eslint-disable-line max-len
530
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
535
+ shouldIncludeStackWithThisFile ( err ) ;
531
536
532
537
request ( app )
533
538
. get ( '/' )
@@ -548,7 +553,7 @@ describe('request(app)', function () {
548
553
. expect ( / ^ b a r / )
549
554
. end ( function ( err , res ) {
550
555
err . message . should . equal ( 'expected body \'foobar\' to match /^bar/' ) ;
551
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
556
+ shouldIncludeStackWithThisFile ( err ) ;
552
557
done ( ) ;
553
558
} ) ;
554
559
} ) ;
@@ -567,7 +572,7 @@ describe('request(app)', function () {
567
572
. expect ( 'hey tj' )
568
573
. end ( function ( err , res ) {
569
574
err . message . should . equal ( "expected 'hey' response body, got 'hey tj'" ) ;
570
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
575
+ shouldIncludeStackWithThisFile ( err ) ;
571
576
done ( ) ;
572
577
} ) ;
573
578
} ) ;
@@ -600,7 +605,7 @@ describe('request(app)', function () {
600
605
. expect ( 'Content-Foo' , 'bar' )
601
606
. end ( function ( err , res ) {
602
607
err . message . should . equal ( 'expected "Content-Foo" header field' ) ;
603
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
608
+ shouldIncludeStackWithThisFile ( err ) ;
604
609
done ( ) ;
605
610
} ) ;
606
611
} ) ;
@@ -618,7 +623,7 @@ describe('request(app)', function () {
618
623
. end ( function ( err , res ) {
619
624
err . message . should . equal ( 'expected "Content-Type" of "text/html", '
620
625
+ 'got "application/json; charset=utf-8"' ) ;
621
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
626
+ shouldIncludeStackWithThisFile ( err ) ;
622
627
done ( ) ;
623
628
} ) ;
624
629
} ) ;
@@ -650,7 +655,7 @@ describe('request(app)', function () {
650
655
. end ( function ( err ) {
651
656
err . message . should . equal ( 'expected "Content-Type" matching /^application/, '
652
657
+ 'got "text/html; charset=utf-8"' ) ;
653
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
658
+ shouldIncludeStackWithThisFile ( err ) ;
654
659
done ( ) ;
655
660
} ) ;
656
661
} ) ;
@@ -667,7 +672,7 @@ describe('request(app)', function () {
667
672
. expect ( 'Content-Length' , 4 )
668
673
. end ( function ( err ) {
669
674
err . message . should . equal ( 'expected "Content-Length" of "4", got "3"' ) ;
670
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
675
+ shouldIncludeStackWithThisFile ( err ) ;
671
676
done ( ) ;
672
677
} ) ;
673
678
} ) ;
@@ -694,7 +699,7 @@ describe('request(app)', function () {
694
699
} )
695
700
. end ( function ( err ) {
696
701
err . message . should . equal ( 'failed' ) ;
697
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
702
+ shouldIncludeStackWithThisFile ( err ) ;
698
703
done ( ) ;
699
704
} ) ;
700
705
} ) ;
@@ -720,7 +725,7 @@ describe('request(app)', function () {
720
725
} )
721
726
. end ( function ( err ) {
722
727
err . message . should . equal ( 'some descriptive error' ) ;
723
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
728
+ shouldIncludeStackWithThisFile ( err ) ;
724
729
( err instanceof Error ) . should . be . true ;
725
730
done ( ) ;
726
731
} ) ;
@@ -761,7 +766,7 @@ describe('request(app)', function () {
761
766
. expect ( 'Content-Type' , / j s o n / )
762
767
. end ( function ( err ) {
763
768
err . message . should . match ( / C o n t e n t - T y p e / ) ;
764
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
769
+ shouldIncludeStackWithThisFile ( err ) ;
765
770
done ( ) ;
766
771
} ) ;
767
772
} ) ;
@@ -805,7 +810,7 @@ describe('request(app)', function () {
805
810
. end ( function ( err ) {
806
811
err . message . should . equal ( 'expected "Content-Type" matching /bloop/, '
807
812
+ 'got "text/html; charset=utf-8"' ) ;
808
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
813
+ shouldIncludeStackWithThisFile ( err ) ;
809
814
done ( ) ;
810
815
} ) ;
811
816
} ) ;
@@ -824,7 +829,7 @@ describe('request(app)', function () {
824
829
. end ( function ( err ) {
825
830
err . message . should . equal ( 'expected "Content-Type" matching /bloop/, '
826
831
+ 'got "text/html; charset=utf-8"' ) ;
827
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
832
+ shouldIncludeStackWithThisFile ( err ) ;
828
833
done ( ) ;
829
834
} ) ;
830
835
} ) ;
@@ -843,7 +848,7 @@ describe('request(app)', function () {
843
848
. end ( function ( err ) {
844
849
err . message . should . equal ( 'expected "Content-Type" matching /bloop/, '
845
850
+ 'got "text/html; charset=utf-8"' ) ;
846
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
851
+ shouldIncludeStackWithThisFile ( err ) ;
847
852
done ( ) ;
848
853
} ) ;
849
854
} ) ;
@@ -1002,7 +1007,7 @@ describe('assert ordering by call order', function () {
1002
1007
. end ( function ( err , res ) {
1003
1008
err . message . should . equal ( 'expected \'hey\' response body, '
1004
1009
+ 'got \'{"message":"something went wrong"}\'' ) ;
1005
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
1010
+ shouldIncludeStackWithThisFile ( err ) ;
1006
1011
done ( ) ;
1007
1012
} ) ;
1008
1013
} ) ;
@@ -1022,7 +1027,7 @@ describe('assert ordering by call order', function () {
1022
1027
. expect ( 'hey' )
1023
1028
. end ( function ( err , res ) {
1024
1029
err . message . should . equal ( 'expected 200 "OK", got 500 "Internal Server Error"' ) ;
1025
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
1030
+ shouldIncludeStackWithThisFile ( err ) ;
1026
1031
done ( ) ;
1027
1032
} ) ;
1028
1033
} ) ;
@@ -1043,7 +1048,7 @@ describe('assert ordering by call order', function () {
1043
1048
. end ( function ( err , res ) {
1044
1049
err . message . should . equal ( 'expected "content-type" matching /html/, '
1045
1050
+ 'got "application/json; charset=utf-8"' ) ;
1046
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
1051
+ shouldIncludeStackWithThisFile ( err ) ;
1047
1052
done ( ) ;
1048
1053
} ) ;
1049
1054
} ) ;
@@ -1216,7 +1221,7 @@ describe('request.get(url).query(vals) works as expected', function () {
1216
1221
. end ( function ( err , res ) {
1217
1222
err . should . be . an . instanceof ( Error ) ;
1218
1223
err . message . should . match ( / N o c k : D i s a l l o w e d n e t c o n n e c t / ) ;
1219
- err . stack . should . match ( / t e s t \/ s u p e r t e s t . j s : / ) ;
1224
+ shouldIncludeStackWithThisFile ( err ) ;
1220
1225
done ( ) ;
1221
1226
} ) ;
1222
1227
0 commit comments