1
1
'use strict' ;
2
- const path = require ( 'path' ) ;
3
2
const indentString = require ( 'indent-string' ) ;
4
3
const tempWrite = require ( 'temp-write' ) ;
5
4
const flatten = require ( 'arr-flatten' ) ;
@@ -35,6 +34,15 @@ function miniReporter(options) {
35
34
return reporter ;
36
35
}
37
36
37
+ function source ( file , line ) {
38
+ return {
39
+ file,
40
+ line : line || 1 ,
41
+ isWithinProject : true ,
42
+ isDependency : false
43
+ } ;
44
+ }
45
+
38
46
process . stderr . setMaxListeners ( 50 ) ;
39
47
40
48
test ( 'start' , t => {
@@ -354,7 +362,7 @@ test('results with errors', t => {
354
362
const err1 = new Error ( 'failure one' ) ;
355
363
err1 . stack = beautifyStack ( err1 . stack ) ;
356
364
const err1Path = tempWrite . sync ( 'a();' ) ;
357
- err1 . source = { file : path . basename ( err1Path ) , line : 1 } ;
365
+ err1 . source = source ( err1Path ) ;
358
366
err1 . showOutput = true ;
359
367
err1 . actual = JSON . stringify ( 'abc' ) ;
360
368
err1 . actualType = 'string' ;
@@ -364,14 +372,14 @@ test('results with errors', t => {
364
372
const err2 = new Error ( 'failure two' ) ;
365
373
err2 . stack = 'error message\nTest.fn (test.js:1:1)\n' ;
366
374
const err2Path = tempWrite . sync ( 'b();' ) ;
367
- err2 . source = { file : path . basename ( err2Path ) , line : 1 } ;
375
+ err2 . source = source ( err2Path ) ;
368
376
err2 . showOutput = true ;
369
377
err2 . actual = JSON . stringify ( [ 1 ] ) ;
370
378
err2 . actualType = 'array' ;
371
379
err2 . expected = JSON . stringify ( [ 2 ] ) ;
372
380
err2 . expectedType = 'array' ;
373
381
374
- const reporter = miniReporter ( { basePath : path . dirname ( err1Path ) } ) ;
382
+ const reporter = miniReporter ( ) ;
375
383
reporter . failCount = 1 ;
376
384
377
385
const runStatus = {
@@ -393,7 +401,7 @@ test('results with errors', t => {
393
401
' ' + chalk . bold . white ( 'failed one' ) ,
394
402
' ' + chalk . grey ( `${ err1 . source . file } :${ err1 . source . line } ` ) ,
395
403
'' ,
396
- indentString ( codeExcerpt ( err1Path , err1 . source . line ) , 2 ) . split ( '\n' ) ,
404
+ indentString ( codeExcerpt ( err1 . source ) , 2 ) . split ( '\n' ) ,
397
405
'' ,
398
406
indentString ( formatAssertError ( err1 ) , 2 ) . split ( '\n' ) ,
399
407
/ f a i l u r e o n e / ,
@@ -406,7 +414,7 @@ test('results with errors', t => {
406
414
' ' + chalk . bold . white ( 'failed two' ) ,
407
415
' ' + chalk . grey ( `${ err2 . source . file } :${ err2 . source . line } ` ) ,
408
416
'' ,
409
- indentString ( codeExcerpt ( err2Path , err2 . source . line ) , 2 ) . split ( '\n' ) ,
417
+ indentString ( codeExcerpt ( err2 . source ) , 2 ) . split ( '\n' ) ,
410
418
'' ,
411
419
indentString ( formatAssertError ( err2 ) , 2 ) . split ( '\n' ) ,
412
420
/ f a i l u r e t w o /
@@ -426,14 +434,14 @@ test('results with errors and disabled code excerpts', t => {
426
434
const err2 = new Error ( 'failure two' ) ;
427
435
err2 . stack = 'error message\nTest.fn (test.js:1:1)\n' ;
428
436
const err2Path = tempWrite . sync ( 'b();' ) ;
429
- err2 . source = { file : path . basename ( err2Path ) , line : 1 } ;
437
+ err2 . source = source ( err2Path ) ;
430
438
err2 . showOutput = true ;
431
439
err2 . actual = JSON . stringify ( [ 1 ] ) ;
432
440
err2 . actualType = 'array' ;
433
441
err2 . expected = JSON . stringify ( [ 2 ] ) ;
434
442
err2 . expectedType = 'array' ;
435
443
436
- const reporter = miniReporter ( { color : true , basePath : path . dirname ( err2Path ) } ) ;
444
+ const reporter = miniReporter ( { color : true } ) ;
437
445
reporter . failCount = 1 ;
438
446
439
447
const runStatus = {
@@ -465,7 +473,7 @@ test('results with errors and disabled code excerpts', t => {
465
473
' ' + chalk . bold . white ( 'failed two' ) ,
466
474
' ' + chalk . grey ( `${ err2 . source . file } :${ err2 . source . line } ` ) ,
467
475
'' ,
468
- indentString ( codeExcerpt ( err2Path , err2 . source . line ) , 2 ) . split ( '\n' ) ,
476
+ indentString ( codeExcerpt ( err2 . source ) , 2 ) . split ( '\n' ) ,
469
477
'' ,
470
478
indentString ( formatAssertError ( err2 ) , 2 ) . split ( '\n' ) ,
471
479
/ f a i l u r e t w o /
@@ -477,7 +485,7 @@ test('results with errors and broken code excerpts', t => {
477
485
const err1 = new Error ( 'failure one' ) ;
478
486
err1 . stack = beautifyStack ( err1 . stack ) ;
479
487
const err1Path = tempWrite . sync ( 'a();' ) ;
480
- err1 . source = { file : path . basename ( err1Path ) , line : 10 } ;
488
+ err1 . source = source ( err1Path , 10 ) ;
481
489
err1 . showOutput = true ;
482
490
err1 . actual = JSON . stringify ( 'abc' ) ;
483
491
err1 . actualType = 'string' ;
@@ -487,14 +495,14 @@ test('results with errors and broken code excerpts', t => {
487
495
const err2 = new Error ( 'failure two' ) ;
488
496
err2 . stack = 'error message\nTest.fn (test.js:1:1)\n' ;
489
497
const err2Path = tempWrite . sync ( 'b();' ) ;
490
- err2 . source = { file : path . basename ( err2Path ) , line : 1 } ;
498
+ err2 . source = source ( err2Path ) ;
491
499
err2 . showOutput = true ;
492
500
err2 . actual = JSON . stringify ( [ 1 ] ) ;
493
501
err2 . actualType = 'array' ;
494
502
err2 . expected = JSON . stringify ( [ 2 ] ) ;
495
503
err2 . expectedType = 'array' ;
496
504
497
- const reporter = miniReporter ( { color : true , basePath : path . dirname ( err2Path ) } ) ;
505
+ const reporter = miniReporter ( { color : true } ) ;
498
506
reporter . failCount = 1 ;
499
507
500
508
const runStatus = {
@@ -527,7 +535,7 @@ test('results with errors and broken code excerpts', t => {
527
535
' ' + chalk . bold . white ( 'failed two' ) ,
528
536
' ' + chalk . grey ( `${ err2 . source . file } :${ err2 . source . line } ` ) ,
529
537
'' ,
530
- indentString ( codeExcerpt ( err2Path , err2 . source . line ) , 2 ) . split ( '\n' ) ,
538
+ indentString ( codeExcerpt ( err2 . source ) , 2 ) . split ( '\n' ) ,
531
539
'' ,
532
540
indentString ( formatAssertError ( err2 ) , 2 ) . split ( '\n' ) ,
533
541
/ f a i l u r e t w o /
@@ -539,7 +547,7 @@ test('results with errors and disabled assert output', t => {
539
547
const err1 = new Error ( 'failure one' ) ;
540
548
err1 . stack = beautifyStack ( err1 . stack ) ;
541
549
const err1Path = tempWrite . sync ( 'a();' ) ;
542
- err1 . source = { file : path . basename ( err1Path ) , line : 1 } ;
550
+ err1 . source = source ( err1Path ) ;
543
551
err1 . showOutput = false ;
544
552
err1 . actual = JSON . stringify ( 'abc' ) ;
545
553
err1 . actualType = 'string' ;
@@ -549,14 +557,14 @@ test('results with errors and disabled assert output', t => {
549
557
const err2 = new Error ( 'failure two' ) ;
550
558
err2 . stack = 'error message\nTest.fn (test.js:1:1)\n' ;
551
559
const err2Path = tempWrite . sync ( 'b();' ) ;
552
- err2 . source = { file : path . basename ( err2Path ) , line : 1 } ;
560
+ err2 . source = source ( err2Path ) ;
553
561
err2 . showOutput = true ;
554
562
err2 . actual = JSON . stringify ( [ 1 ] ) ;
555
563
err2 . actualType = 'array' ;
556
564
err2 . expected = JSON . stringify ( [ 2 ] ) ;
557
565
err2 . expectedType = 'array' ;
558
566
559
- const reporter = miniReporter ( { color : true , basePath : path . dirname ( err1Path ) } ) ;
567
+ const reporter = miniReporter ( { color : true } ) ;
560
568
reporter . failCount = 1 ;
561
569
562
570
const runStatus = {
@@ -578,7 +586,7 @@ test('results with errors and disabled assert output', t => {
578
586
' ' + chalk . bold . white ( 'failed one' ) ,
579
587
' ' + chalk . grey ( `${ err1 . source . file } :${ err1 . source . line } ` ) ,
580
588
'' ,
581
- indentString ( codeExcerpt ( err1Path , err1 . source . line ) , 2 ) . split ( '\n' ) ,
589
+ indentString ( codeExcerpt ( err1 . source ) , 2 ) . split ( '\n' ) ,
582
590
'' ,
583
591
/ f a i l u r e o n e / ,
584
592
'' ,
@@ -590,7 +598,7 @@ test('results with errors and disabled assert output', t => {
590
598
' ' + chalk . bold . white ( 'failed two' ) ,
591
599
' ' + chalk . grey ( `${ err2 . source . file } :${ err2 . source . line } ` ) ,
592
600
'' ,
593
- indentString ( codeExcerpt ( err2Path , err2 . source . line ) , 2 ) . split ( '\n' ) ,
601
+ indentString ( codeExcerpt ( err2 . source ) , 2 ) . split ( '\n' ) ,
594
602
'' ,
595
603
indentString ( formatAssertError ( err2 ) , 2 ) . split ( '\n' ) ,
596
604
/ f a i l u r e t w o /
0 commit comments