@@ -377,6 +377,7 @@ function build (opts = {}) {
377
377
* @returns {Promise }
378
378
*/
379
379
async function exec ( name , actions , stats , junit ) {
380
+ // tap.comment(name)
380
381
for ( const action of actions ) {
381
382
if ( action . skip ) {
382
383
if ( shouldSkip ( esVersion , action . skip ) ) {
@@ -411,7 +412,8 @@ function build (opts = {}) {
411
412
key . split ( '.' ) [ 0 ] === '$body'
412
413
? action . match [ key ]
413
414
: fillStashedValues ( action . match ) [ key ] ,
414
- action . match
415
+ action . match ,
416
+ response
415
417
)
416
418
}
417
419
@@ -420,7 +422,8 @@ function build (opts = {}) {
420
422
const key = Object . keys ( action . lt ) [ 0 ]
421
423
lt (
422
424
delve ( response , fillStashedValues ( key ) ) ,
423
- fillStashedValues ( action . lt ) [ key ]
425
+ fillStashedValues ( action . lt ) [ key ] ,
426
+ response
424
427
)
425
428
}
426
429
@@ -429,7 +432,8 @@ function build (opts = {}) {
429
432
const key = Object . keys ( action . gt ) [ 0 ]
430
433
gt (
431
434
delve ( response , fillStashedValues ( key ) ) ,
432
- fillStashedValues ( action . gt ) [ key ]
435
+ fillStashedValues ( action . gt ) [ key ] ,
436
+ response
433
437
)
434
438
}
435
439
@@ -438,7 +442,8 @@ function build (opts = {}) {
438
442
const key = Object . keys ( action . lte ) [ 0 ]
439
443
lte (
440
444
delve ( response , fillStashedValues ( key ) ) ,
441
- fillStashedValues ( action . lte ) [ key ]
445
+ fillStashedValues ( action . lte ) [ key ] ,
446
+ response
442
447
)
443
448
}
444
449
@@ -447,7 +452,8 @@ function build (opts = {}) {
447
452
const key = Object . keys ( action . gte ) [ 0 ]
448
453
gte (
449
454
delve ( response , fillStashedValues ( key ) ) ,
450
- fillStashedValues ( action . gte ) [ key ]
455
+ fillStashedValues ( action . gte ) [ key ] ,
456
+ response
451
457
)
452
458
}
453
459
@@ -460,7 +466,8 @@ function build (opts = {}) {
460
466
: delve ( response , fillStashedValues ( key ) ) ,
461
467
key === '$body'
462
468
? action . length [ key ]
463
- : fillStashedValues ( action . length ) [ key ]
469
+ : fillStashedValues ( action . length ) [ key ] ,
470
+ response
464
471
)
465
472
}
466
473
@@ -469,7 +476,8 @@ function build (opts = {}) {
469
476
const isTrue = fillStashedValues ( action . is_true )
470
477
is_true (
471
478
delve ( response , isTrue ) ,
472
- isTrue
479
+ isTrue ,
480
+ response
473
481
)
474
482
}
475
483
@@ -478,7 +486,8 @@ function build (opts = {}) {
478
486
const isFalse = fillStashedValues ( action . is_false )
479
487
is_false (
480
488
delve ( response , isFalse ) ,
481
- isFalse
489
+ isFalse ,
490
+ response
482
491
)
483
492
}
484
493
}
@@ -491,48 +500,67 @@ function build (opts = {}) {
491
500
* Asserts that the given value is truthy
492
501
* @param {any } the value to check
493
502
* @param {string } an optional message
503
+ * @param {any } debugging metadata to attach to any assertion errors
494
504
* @returns {TestRunner }
495
505
*/
496
- function is_true ( val , msg ) {
497
- assert . ok ( val , `expect truthy value: ${ msg } - value: ${ JSON . stringify ( val ) } ` )
506
+ function is_true ( val , msg , response ) {
507
+ try {
508
+ assert . ok ( ( typeof val === 'string' && val . toLowerCase ( ) === 'true' ) || val , `expect truthy value: ${ msg } - value: ${ JSON . stringify ( val ) } ` )
509
+ } catch ( err ) {
510
+ err . response = JSON . stringify ( response )
511
+ throw err
512
+ }
498
513
}
499
514
500
515
/**
501
516
* Asserts that the given value is falsey
502
517
* @param {any } the value to check
503
518
* @param {string } an optional message
519
+ * @param {any } debugging metadata to attach to any assertion errors
504
520
* @returns {TestRunner }
505
521
*/
506
- function is_false ( val , msg ) {
507
- assert . ok ( ! val , `expect falsey value: ${ msg } - value: ${ JSON . stringify ( val ) } ` )
522
+ function is_false ( val , msg , response ) {
523
+ try {
524
+ assert . ok ( ( typeof val === 'string' && val . toLowerCase ( ) === 'false' ) || ! val , `expect falsey value: ${ msg } - value: ${ JSON . stringify ( val ) } ` )
525
+ } catch ( err ) {
526
+ err . response = JSON . stringify ( response )
527
+ throw err
528
+ }
508
529
}
509
530
510
531
/**
511
532
* Asserts that two values are the same
512
533
* @param {any } the first value
513
534
* @param {any } the second value
535
+ * @param {any } debugging metadata to attach to any assertion errors
514
536
* @returns {TestRunner }
515
537
*/
516
- function match ( val1 , val2 , action ) {
517
- // both values are objects
518
- if ( typeof val1 === 'object' && typeof val2 === 'object' ) {
519
- assert . deepEqual ( val1 , val2 , typeof action === 'object' ? JSON . stringify ( action ) : action )
520
- // the first value is the body as string and the second a pattern string
521
- } else if (
522
- typeof val1 === 'string' && typeof val2 === 'string' &&
523
- val2 . startsWith ( '/' ) && ( val2 . endsWith ( '/\n' ) || val2 . endsWith ( '/' ) )
524
- ) {
525
- const regStr = val2
526
- . replace ( / ( ^ | [ ^ \\ ] ) # .* / g, '$1' )
527
- . replace ( / ( ^ | [ ^ \\ ] ) \s + / g, '$1' )
528
- . slice ( 1 , - 1 )
529
- // 'm' adds the support for multiline regex
530
- assert . match ( val1 , new RegExp ( regStr , 'm' ) , `should match pattern provided: ${ val2 } , but got: ${ val1 } ` )
531
- // everything else
532
- } else if ( typeof val1 === 'string' && typeof val2 === 'string' ) {
533
- assert . include ( val1 , val2 , `should match pattern provided: ${ val2 } , but got: ${ val1 } ` )
534
- } else {
535
- assert . equal ( val1 , val2 , `should be equal: ${ val1 } - ${ val2 } , action: ${ JSON . stringify ( action ) } ` )
538
+ function match ( val1 , val2 , action , response ) {
539
+ try {
540
+ // both values are objects
541
+ if ( typeof val1 === 'object' && typeof val2 === 'object' ) {
542
+ assert . deepEqual ( val1 , val2 , typeof action === 'object' ? JSON . stringify ( action ) : action )
543
+ // the first value is the body as string and the second a pattern string
544
+ } else if (
545
+ typeof val1 === 'string' && typeof val2 === 'string' &&
546
+ val2 . startsWith ( '/' ) && ( val2 . endsWith ( '/\n' ) || val2 . endsWith ( '/' ) )
547
+ ) {
548
+ const regStr = val2
549
+ . replace ( / ( ^ | [ ^ \\ ] ) # .* / g, '$1' )
550
+ . replace ( / ( ^ | [ ^ \\ ] ) \s + / g, '$1' )
551
+ . slice ( 1 , - 1 )
552
+ // 'm' adds the support for multiline regex
553
+ assert . match ( val1 , new RegExp ( regStr , 'm' ) , `should match pattern provided: ${ val2 } , but got: ${ val1 } : ${ JSON . stringify ( action ) } ` )
554
+ } else if ( typeof val1 === 'string' && typeof val2 === 'string' ) {
555
+ // string comparison
556
+ assert . include ( val1 , val2 , `should include pattern provided: ${ val2 } , but got: ${ val1 } : ${ JSON . stringify ( action ) } ` )
557
+ } else {
558
+ // everything else
559
+ assert . equal ( val1 , val2 , `should be equal: ${ val1 } - ${ val2 } , action: ${ JSON . stringify ( action ) } ` )
560
+ }
561
+ } catch ( err ) {
562
+ err . response = JSON . stringify ( response )
563
+ throw err
536
564
}
537
565
}
538
566
@@ -541,62 +569,92 @@ function match (val1, val2, action) {
541
569
* It also verifies that the two values are numbers
542
570
* @param {any } the first value
543
571
* @param {any } the second value
572
+ * @param {any } debugging metadata to attach to any assertion errors
544
573
* @returns {TestRunner }
545
574
*/
546
- function lt ( val1 , val2 ) {
547
- ; [ val1 , val2 ] = getNumbers ( val1 , val2 )
548
- assert . ok ( val1 < val2 )
575
+ function lt ( val1 , val2 , response ) {
576
+ try {
577
+ ; [ val1 , val2 ] = getNumbers ( val1 , val2 )
578
+ assert . ok ( val1 < val2 )
579
+ } catch ( err ) {
580
+ err . response = JSON . stringify ( response )
581
+ throw err
582
+ }
549
583
}
550
584
551
585
/**
552
586
* Asserts that the first value is greater than the second
553
587
* It also verifies that the two values are numbers
554
588
* @param {any } the first value
555
589
* @param {any } the second value
590
+ * @param {any } debugging metadata to attach to any assertion errors
556
591
* @returns {TestRunner }
557
592
*/
558
- function gt ( val1 , val2 ) {
559
- ; [ val1 , val2 ] = getNumbers ( val1 , val2 )
560
- assert . ok ( val1 > val2 )
593
+ function gt ( val1 , val2 , response ) {
594
+ try {
595
+ ; [ val1 , val2 ] = getNumbers ( val1 , val2 )
596
+ assert . ok ( val1 > val2 )
597
+ } catch ( err ) {
598
+ err . response = JSON . stringify ( response )
599
+ throw err
600
+ }
561
601
}
562
602
563
603
/**
564
604
* Asserts that the first value is less than or equal the second
565
605
* It also verifies that the two values are numbers
566
606
* @param {any } the first value
567
607
* @param {any } the second value
608
+ * @param {any } debugging metadata to attach to any assertion errors
568
609
* @returns {TestRunner }
569
610
*/
570
- function lte ( val1 , val2 ) {
571
- ; [ val1 , val2 ] = getNumbers ( val1 , val2 )
572
- assert . ok ( val1 <= val2 )
611
+ function lte ( val1 , val2 , response ) {
612
+ try {
613
+ ; [ val1 , val2 ] = getNumbers ( val1 , val2 )
614
+ assert . ok ( val1 <= val2 )
615
+ } catch ( err ) {
616
+ err . response = JSON . stringify ( response )
617
+ throw err
618
+ }
573
619
}
574
620
575
621
/**
576
622
* Asserts that the first value is greater than or equal the second
577
623
* It also verifies that the two values are numbers
578
624
* @param {any } the first value
579
625
* @param {any } the second value
626
+ * @param {any } debugging metadata to attach to any assertion errors
580
627
* @returns {TestRunner }
581
628
*/
582
- function gte ( val1 , val2 ) {
583
- ; [ val1 , val2 ] = getNumbers ( val1 , val2 )
584
- assert . ok ( val1 >= val2 )
629
+ function gte ( val1 , val2 , response ) {
630
+ try {
631
+ ; [ val1 , val2 ] = getNumbers ( val1 , val2 )
632
+ assert . ok ( val1 >= val2 )
633
+ } catch ( err ) {
634
+ err . response = JSON . stringify ( response )
635
+ throw err
636
+ }
585
637
}
586
638
587
639
/**
588
640
* Asserts that the given value has the specified length
589
641
* @param {string|object|array } the object to check
590
642
* @param {number } the expected length
643
+ * @param {any } debugging metadata to attach to any assertion errors
591
644
* @returns {TestRunner }
592
645
*/
593
- function length ( val , len ) {
594
- if ( typeof val === 'string' || Array . isArray ( val ) ) {
595
- assert . equal ( val . length , len )
596
- } else if ( typeof val === 'object' && val !== null ) {
597
- assert . equal ( Object . keys ( val ) . length , len )
598
- } else {
599
- assert . fail ( `length: the given value is invalid: ${ val } ` )
646
+ function length ( val , len , response ) {
647
+ try {
648
+ if ( typeof val === 'string' || Array . isArray ( val ) ) {
649
+ assert . equal ( val . length , len )
650
+ } else if ( typeof val === 'object' && val !== null ) {
651
+ assert . equal ( Object . keys ( val ) . length , len )
652
+ } else {
653
+ assert . fail ( `length: the given value is invalid: ${ val } ` )
654
+ }
655
+ } catch ( err ) {
656
+ err . response = JSON . stringify ( response )
657
+ throw err
600
658
}
601
659
}
602
660
0 commit comments