@parcel/codeframe 2.0.0-nightly.137 → 2.0.0-nightly.1370

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,6 @@
1
1
  import assert from 'assert';
2
+ import {readFileSync} from 'fs';
3
+ import {join as joinPath} from 'path';
2
4
 
3
5
  import codeframe from '../src/codeframe';
4
6
 
@@ -393,7 +395,7 @@ describe('codeframe', () => {
393
395
  assert.equal(lines[7], ' 9 | test');
394
396
  });
395
397
 
396
- it('should properly pad numbers', () => {
398
+ it('should properly pad numbers for large files', () => {
397
399
  let codeframeString = codeframe('test\n'.repeat(1000), [
398
400
  {
399
401
  start: {
@@ -415,17 +417,22 @@ describe('codeframe', () => {
415
417
  column: 2,
416
418
  line: 100,
417
419
  },
418
- message: 'test',
420
+ message: 'test 2',
419
421
  },
420
422
  ]);
421
423
 
422
424
  let lines = codeframeString.split(LINE_END);
423
425
  assert.equal(lines.length, 7);
424
- assert.equal(lines[0], ' 98 | test');
426
+ assert.equal(lines[0], ' 98 | test');
427
+ assert.equal(lines[1], '> 99 | test');
428
+ assert.equal(lines[2], '> | ^ test');
429
+ assert.equal(lines[3], '> 100 | test');
430
+ assert.equal(lines[4], '> | ^ test 2');
431
+ assert.equal(lines[5], ' 101 | test');
425
432
  assert.equal(lines[6], ' 102 | test');
426
433
  });
427
434
 
428
- it('should properly pad numbers', () => {
435
+ it('should properly pad numbers for short files', () => {
429
436
  let codeframeString = codeframe('test\n'.repeat(1000), [
430
437
  {
431
438
  start: {
@@ -453,13 +460,17 @@ describe('codeframe', () => {
453
460
 
454
461
  let lines = codeframeString.split(LINE_END);
455
462
  assert.equal(lines.length, 11);
456
- assert.equal(lines[0], ' 6 | test');
463
+ assert.equal(lines[0], ' 6 | test');
464
+ assert.equal(lines[4], ' 9 | test');
465
+ assert.equal(lines[5], ' 10 | test');
466
+ assert.equal(lines[6], ' 11 | test');
457
467
  assert.equal(lines[10], ' 14 | test');
458
468
  });
459
469
 
460
470
  it('should properly use maxLines', () => {
471
+ let line = 'test '.repeat(100);
461
472
  let codeframeString = codeframe(
462
- 'test\n'.repeat(100),
473
+ `${line}\n`.repeat(100),
463
474
  [
464
475
  {
465
476
  start: {
@@ -487,14 +498,16 @@ describe('codeframe', () => {
487
498
  {
488
499
  useColor: false,
489
500
  maxLines: 10,
501
+ terminalWidth: 5,
490
502
  },
491
503
  );
492
504
 
493
505
  let lines = codeframeString.split(LINE_END);
494
506
  assert.equal(lines.length, 13);
495
- assert.equal(lines[0], ' 4 | test');
496
- assert.equal(lines[11], '> 13 | test');
497
- assert.equal(lines[12], '> | ^^^^');
507
+ assert.equal(lines[0], ' 4 | test test ');
508
+ assert.equal(lines[7], ' 10 | test test ');
509
+ assert.equal(lines[11], '> 13 | test test ');
510
+ assert.equal(lines[12], '> | ^^^^^^^^^^');
498
511
  });
499
512
 
500
513
  it('should be able to handle tabs', () => {
@@ -507,7 +520,7 @@ describe('codeframe', () => {
507
520
  line: 1,
508
521
  },
509
522
  end: {
510
- column: 7,
523
+ column: 8,
511
524
  line: 1,
512
525
  },
513
526
  message: 'test',
@@ -518,7 +531,7 @@ describe('codeframe', () => {
518
531
 
519
532
  let lines = codeframeString.split(LINE_END);
520
533
  assert.equal(lines[0], '> 1 | hel lo wor ld');
521
- assert.equal(lines[1], '> | ^^^ test');
534
+ assert.equal(lines[1], '> | ^^^^ test');
522
535
  assert.equal(lines[2], ' 2 | Enjoy thi s nice cod eframe');
523
536
  });
524
537
 
@@ -585,4 +598,202 @@ describe('codeframe', () => {
585
598
  assert.equal(lines[4], '> 3 | test');
586
599
  assert.equal(lines[5], '> | ^^ test');
587
600
  });
601
+
602
+ it('Should truncate long lines and print message', () => {
603
+ let originalLine = 'hello world '.repeat(1000);
604
+ let codeframeString = codeframe(
605
+ originalLine,
606
+ [
607
+ {
608
+ start: {
609
+ column: 1000,
610
+ line: 1,
611
+ },
612
+ end: {
613
+ column: 1200,
614
+ line: 1,
615
+ },
616
+ message: 'This is a message',
617
+ },
618
+ ],
619
+ {useColor: false, terminalWidth: 25},
620
+ );
621
+
622
+ let lines = codeframeString.split(LINE_END);
623
+ assert.equal(lines.length, 2);
624
+ assert.equal(lines[0], '> 1 | d hello world hello');
625
+ assert.equal(lines[1], '> | ^^^^^^^^^^^^^^ This is a message');
626
+ });
627
+
628
+ it('Truncation across multiple lines', () => {
629
+ let originalLine =
630
+ 'hello world '.repeat(100) + '\n' + 'new line '.repeat(100);
631
+ let codeframeString = codeframe(
632
+ originalLine,
633
+ [
634
+ {
635
+ start: {
636
+ column: 15,
637
+ line: 1,
638
+ },
639
+ end: {
640
+ column: 400,
641
+ line: 1,
642
+ },
643
+ message: 'This is the first line',
644
+ },
645
+ {
646
+ start: {
647
+ column: 2,
648
+ line: 2,
649
+ },
650
+ end: {
651
+ column: 100,
652
+ line: 2,
653
+ },
654
+ message: 'This is the second line',
655
+ },
656
+ ],
657
+ {useColor: false, terminalWidth: 25},
658
+ );
659
+
660
+ let lines = codeframeString.split(LINE_END);
661
+ assert.equal(lines.length, 4);
662
+ assert.equal(lines[0], '> 1 | ld hello world hell');
663
+ assert.equal(lines[1], '> | ^^^^^^^^^^^^^^ This is the first line');
664
+ assert.equal(lines[2], '> 2 | new line new line n');
665
+ assert.equal(lines[3], '> | ^^^^^^^^^^^^^^^^^^ This is the second line');
666
+ });
667
+
668
+ it('Truncation across various types and positions of highlights', () => {
669
+ let originalLine =
670
+ 'hello world '.repeat(100) + '\n' + 'new line '.repeat(100);
671
+ let codeframeString = codeframe(
672
+ originalLine,
673
+ [
674
+ {
675
+ start: {
676
+ column: 2,
677
+ line: 1,
678
+ },
679
+ end: {
680
+ column: 5,
681
+ line: 1,
682
+ },
683
+ },
684
+ {
685
+ start: {
686
+ column: 6,
687
+ line: 1,
688
+ },
689
+ end: {
690
+ column: 10,
691
+ line: 1,
692
+ },
693
+ message: 'I have a message',
694
+ },
695
+ {
696
+ start: {
697
+ column: 15,
698
+ line: 1,
699
+ },
700
+ end: {
701
+ column: 25,
702
+ line: 1,
703
+ },
704
+ message: 'I also have a message',
705
+ },
706
+ {
707
+ start: {
708
+ column: 2,
709
+ line: 2,
710
+ },
711
+ end: {
712
+ column: 5,
713
+ line: 2,
714
+ },
715
+ message: 'This is the second line',
716
+ },
717
+ ],
718
+ {useColor: false, terminalWidth: 25},
719
+ );
720
+
721
+ let lines = codeframeString.split(LINE_END);
722
+ assert.equal(lines.length, 4);
723
+ assert.equal(lines[0], '> 1 | hello world hello w');
724
+ assert.equal(lines[1], '> | ^^^^^^^^^ ^^^^^ I also have a message');
725
+ assert.equal(lines[2], '> 2 | new line new line n');
726
+ assert.equal(lines[3], '> | ^^^^ This is the second line');
727
+ });
728
+
729
+ it('Multi-line highlight w/ truncation', () => {
730
+ let originalLine =
731
+ 'hello world '.repeat(100) + '\n' + 'new line '.repeat(100);
732
+ let codeframeString = codeframe(
733
+ originalLine,
734
+ [
735
+ {
736
+ start: {
737
+ column: 2,
738
+ line: 1,
739
+ },
740
+ end: {
741
+ column: 151,
742
+ line: 2,
743
+ },
744
+ message: 'I have a message',
745
+ },
746
+ ],
747
+ {useColor: false, terminalWidth: 25},
748
+ );
749
+
750
+ let lines = codeframeString.split(LINE_END);
751
+ assert.equal(lines.length, 4);
752
+ assert.equal(lines[0], '> 1 | hello world hello w');
753
+ assert.equal(lines[1], '> | ^^^^^^^^^^^^^^^^^^');
754
+ assert.equal(lines[2], '> 2 | ew line new line ne');
755
+ assert.equal(lines[3], '> | ^^^^^^ I have a message');
756
+ });
757
+
758
+ it('Should pad properly, T-650', () => {
759
+ let fileContent = readFileSync(
760
+ joinPath(__dirname, './fixtures/a.js'),
761
+ 'utf8',
762
+ );
763
+ let codeframeString = codeframe(
764
+ fileContent,
765
+ [
766
+ {
767
+ start: {
768
+ line: 8,
769
+ column: 10,
770
+ },
771
+ end: {
772
+ line: 8,
773
+ column: 48,
774
+ },
775
+ },
776
+ ],
777
+ {
778
+ useColor: false,
779
+ syntaxHighlighting: false,
780
+ language: 'js',
781
+ terminalWidth: 100,
782
+ },
783
+ );
784
+
785
+ let lines = codeframeString.split(LINE_END);
786
+ assert.equal(lines.length, 5);
787
+ assert.equal(lines[0], ` 7 | import Tooltip from '../tooltip';`);
788
+ assert.equal(
789
+ lines[1],
790
+ `> 8 | import VisuallyHidden from '../visually-hidden';`,
791
+ );
792
+ assert.equal(
793
+ lines[2],
794
+ '> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^',
795
+ );
796
+ assert.equal(lines[3], ' 9 | ');
797
+ assert.equal(lines[4], ' 10 | /**');
798
+ });
588
799
  });
@@ -0,0 +1,13 @@
1
+ import test from 'test';
2
+ import component from './component';
3
+
4
+ /**
5
+ * This is a comment
6
+ */
7
+ import Tooltip from '../tooltip';
8
+ import VisuallyHidden from '../visually-hidden';
9
+
10
+ /**
11
+ * This is another comment
12
+ */
13
+ import {Label} from './label';