Skip to content

Commit b00a264

Browse files
author
Thomas Watson
authored
[@kbn/handlebars] Code cleanup (#147425)
1 parent 794e721 commit b00a264

15 files changed

Lines changed: 437 additions & 431 deletions

packages/kbn-handlebars/.patches/blocks.patch

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,30 +429,34 @@
429429
> beforeEach(() => {
430430
> global.kbnHandlebarsEnv = Handlebars.create();
431431
> });
432-
410c319,323
432+
410c319,327
433433
< handlebarsEnv.registerDecorator('foo', function() {
434434
---
435+
> afterEach(() => {
436+
> global.kbnHandlebarsEnv = null;
437+
> });
438+
>
435439
> it('unregisters', () => {
436440
> // @ts-expect-error: Cannot assign to 'decorators' because it is a read-only property.
437441
> kbnHandlebarsEnv!.decorators = {};
438442
>
439443
> kbnHandlebarsEnv!.registerDecorator('foo', function () {
440-
414,416c327,329
444+
414,416c331,333
441445
< equals(!!handlebarsEnv.decorators.foo, true);
442446
< handlebarsEnv.unregisterDecorator('foo');
443447
< equals(handlebarsEnv.decorators.foo, undefined);
444448
---
445449
> expect(!!kbnHandlebarsEnv!.decorators.foo).toEqual(true);
446450
> kbnHandlebarsEnv!.unregisterDecorator('foo');
447451
> expect(kbnHandlebarsEnv!.decorators.foo).toBeUndefined();
448-
419,420c332,334
452+
419,420c336,338
449453
< it('allows multiple globals', function() {
450454
< handlebarsEnv.decorators = {};
451455
---
452456
> it('allows multiple globals', () => {
453457
> // @ts-expect-error: Cannot assign to 'decorators' because it is a read-only property.
454458
> kbnHandlebarsEnv!.decorators = {};
455-
422,424c336,339
459+
422,424c340,343
456460
< handlebarsEnv.registerDecorator({
457461
< foo: function() {},
458462
< bar: function() {}
@@ -461,7 +465,7 @@
461465
> kbnHandlebarsEnv!.registerDecorator({
462466
> foo() {},
463467
> bar() {},
464-
427,432c342,347
468+
427,432c346,351
465469
< equals(!!handlebarsEnv.decorators.foo, true);
466470
< equals(!!handlebarsEnv.decorators.bar, true);
467471
< handlebarsEnv.unregisterDecorator('foo');
@@ -475,7 +479,7 @@
475479
> kbnHandlebarsEnv!.unregisterDecorator('bar');
476480
> expect(kbnHandlebarsEnv!.decorators.foo).toBeUndefined();
477481
> expect(kbnHandlebarsEnv!.decorators.bar).toBeUndefined();
478-
435,445c350,356
482+
435,445c354,360
479483
< it('fails with multiple and args', function() {
480484
< shouldThrow(
481485
< function() {
@@ -495,7 +499,7 @@
495499
> {
496500
> world() {
497501
> return 'world!';
498-
447,452c358,364
502+
447,452c362,368
499503
< {}
500504
< );
501505
< },

packages/kbn-handlebars/.patches/builtins.patch

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,10 @@
668668
---
669669
>
670670
> afterEach(function () {
671-
578,580c481,484
671+
575a479,480
672+
>
673+
> global.kbnHandlebarsEnv = null;
674+
578,580c483,486
672675
< it('should call logger at default level', function() {
673676
< var levelArg, logArg;
674677
< handlebarsEnv.log = function(level, arg) {
@@ -677,7 +680,7 @@
677680
> let levelArg;
678681
> let logArg;
679682
> kbnHandlebarsEnv!.log = function (level, arg) {
680-
585,590c489,491
683+
585,590c491,493
681684
< expectTemplate('{{log blah}}')
682685
< .withInput({ blah: 'whee' })
683686
< .withMessage('log should not display')
@@ -688,7 +691,7 @@
688691
> expectTemplate('{{log blah}}').withInput({ blah: 'whee' }).toCompileTo('');
689692
> expect(1).toEqual(levelArg);
690693
> expect('whee').toEqual(logArg);
691-
593,595c494,497
694+
593,595c496,499
692695
< it('should call logger at data level', function() {
693696
< var levelArg, logArg;
694697
< handlebarsEnv.log = function(level, arg) {
@@ -697,20 +700,20 @@
697700
> let levelArg;
698701
> let logArg;
699702
> kbnHandlebarsEnv!.log = function (level, arg) {
700-
605,606c507,508
703+
605,606c509,510
701704
< equals('03', levelArg);
702705
< equals('whee', logArg);
703706
---
704707
> expect('03').toEqual(levelArg);
705708
> expect('whee').toEqual(logArg);
706-
609,610c511,513
709+
609,610c513,515
707710
< it('should output to info', function() {
708711
< var called;
709712
---
710713
> it('should output to info', function () {
711714
> let calls = 0;
712715
> const callsExpected = process.env.AST || process.env.EVAL ? 1 : 2;
713-
612,616c515,521
716+
612,616c517,523
714717
< console.info = function(info) {
715718
< equals('whee', info);
716719
< called = true;
@@ -724,7 +727,7 @@
724727
> console.info = $info;
725728
> console.log = $log;
726729
> }
727-
618,622c523,529
730+
618,622c525,531
728731
< console.log = function(log) {
729732
< equals('whee', log);
730733
< called = true;
@@ -738,22 +741,22 @@
738741
> console.info = $info;
739742
> console.log = $log;
740743
> }
741-
625,628c532,533
744+
625,628c534,535
742745
< expectTemplate('{{log blah}}')
743746
< .withInput({ blah: 'whee' })
744747
< .toCompileTo('');
745748
< equals(true, called);
746749
---
747750
> expectTemplate('{{log blah}}').withInput({ blah: 'whee' }).toCompileTo('');
748751
> expect(calls).toEqual(callsExpected);
749-
631,632c536,538
752+
631,632c538,540
750753
< it('should log at data level', function() {
751754
< var called;
752755
---
753756
> it('should log at data level', function () {
754757
> let calls = 0;
755758
> const callsExpected = process.env.AST || process.env.EVAL ? 1 : 2;
756-
634,637c540,543
759+
634,637c542,545
757760
< console.error = function(log) {
758761
< equals('whee', log);
759762
< called = true;
@@ -763,20 +766,20 @@
763766
> expect('whee').toEqual(log);
764767
> calls++;
765768
> if (calls === callsExpected) console.error = $error;
766-
645c551
769+
645c553
767770
< equals(true, called);
768771
---
769772
> expect(calls).toEqual(callsExpected);
770-
648,649c554,556
773+
648,649c556,558
771774
< it('should handle missing logger', function() {
772775
< var called = false;
773776
---
774777
> it('should handle missing logger', function () {
775778
> let calls = 0;
776779
> const callsExpected = process.env.AST || process.env.EVAL ? 1 : 2;
777-
650a558
780+
650a560
778781
> // @ts-expect-error
779-
652,655c560,563
782+
652,655c562,565
780783
< console.log = function(log) {
781784
< equals('whee', log);
782785
< called = true;
@@ -786,67 +789,67 @@
786789
> expect('whee').toEqual(log);
787790
> calls++;
788791
> if (calls === callsExpected) console.log = $log;
789-
663c571
792+
663c573
790793
< equals(true, called);
791794
---
792795
> expect(calls).toEqual(callsExpected);
793-
666,667c574,576
796+
666,667c576,578
794797
< it('should handle string log levels', function() {
795798
< var called;
796799
---
797800
> it('should handle string log levels', function () {
798801
> let calls = 0;
799802
> const callsExpected = process.env.AST || process.env.EVAL ? 1 : 2;
800-
669,671c578,580
803+
669,671c580,582
801804
< console.error = function(log) {
802805
< equals('whee', log);
803806
< called = true;
804807
---
805808
> console.error = function (log) {
806809
> expect('whee').toEqual(log);
807810
> calls++;
808-
679c588
811+
679c590
809812
< equals(true, called);
810813
---
811814
> expect(calls).toEqual(callsExpected);
812-
681c590
815+
681c592
813816
< called = false;
814817
---
815818
> calls = 0;
816-
688c597
819+
688c599
817820
< equals(true, called);
818821
---
819822
> expect(calls).toEqual(callsExpected);
820-
691,692c600,602
823+
691,692c602,604
821824
< it('should handle hash log levels', function() {
822825
< var called;
823826
---
824827
> it('should handle hash log levels [1]', function () {
825828
> let calls = 0;
826829
> const callsExpected = process.env.AST || process.env.EVAL ? 1 : 2;
827-
694,696c604,606
830+
694,696c606,608
828831
< console.error = function(log) {
829832
< equals('whee', log);
830833
< called = true;
831834
---
832835
> console.error = function (log) {
833836
> expect('whee').toEqual(log);
834837
> calls++;
835-
699,702c609,610
838+
699,702c611,612
836839
< expectTemplate('{{log blah level="error"}}')
837840
< .withInput({ blah: 'whee' })
838841
< .toCompileTo('');
839842
< equals(true, called);
840843
---
841844
> expectTemplate('{{log blah level="error"}}').withInput({ blah: 'whee' }).toCompileTo('');
842845
> expect(calls).toEqual(callsExpected);
843-
705,706c613,614
846+
705,706c615,616
844847
< it('should handle hash log levels', function() {
845848
< var called = false;
846849
---
847850
> it('should handle hash log levels [2]', function () {
848851
> let called = false;
849-
708,711c616,623
852+
708,711c618,625
850853
< console.info = console.log = console.error = console.debug = function() {
851854
< called = true;
852855
< console.info = console.log = console.error = console.debug = $log;
@@ -860,22 +863,22 @@
860863
> called = true;
861864
> console.info = console.log = console.error = console.debug = $log;
862865
> };
863-
713,716c625,626
866+
713,716c627,628
864867
< expectTemplate('{{log blah level="debug"}}')
865868
< .withInput({ blah: 'whee' })
866869
< .toCompileTo('');
867870
< equals(false, called);
868871
---
869872
> expectTemplate('{{log blah level="debug"}}').withInput({ blah: 'whee' }).toCompileTo('');
870873
> expect(false).toEqual(called);
871-
719,720c629,631
874+
719,720c631,633
872875
< it('should pass multiple log arguments', function() {
873876
< var called;
874877
---
875878
> it('should pass multiple log arguments', function () {
876879
> let calls = 0;
877880
> const callsExpected = process.env.AST || process.env.EVAL ? 1 : 2;
878-
722,727c633,638
881+
722,727c635,640
879882
< console.info = console.log = function(log1, log2, log3) {
880883
< equals('whee', log1);
881884
< equals('foo', log2);
@@ -889,22 +892,22 @@
889892
> expect(1).toEqual(log3);
890893
> calls++;
891894
> if (calls === callsExpected) console.log = $log;
892-
730,733c641,642
895+
730,733c643,644
893896
< expectTemplate('{{log blah "foo" 1}}')
894897
< .withInput({ blah: 'whee' })
895898
< .toCompileTo('');
896899
< equals(true, called);
897900
---
898901
> expectTemplate('{{log blah "foo" 1}}').withInput({ blah: 'whee' }).toCompileTo('');
899902
> expect(calls).toEqual(callsExpected);
900-
736,737c645,647
903+
736,737c647,649
901904
< it('should pass zero log arguments', function() {
902905
< var called;
903906
---
904907
> it('should pass zero log arguments', function () {
905908
> let calls = 0;
906909
> const callsExpected = process.env.AST || process.env.EVAL ? 1 : 2;
907-
739,742c649,652
910+
739,742c651,654
908911
< console.info = console.log = function() {
909912
< expect(arguments.length).to.equal(0);
910913
< called = true;
@@ -914,21 +917,21 @@
914917
> expect(arguments.length).toEqual(0);
915918
> calls++;
916919
> if (calls === callsExpected) console.log = $log;
917-
745,748c655,656
920+
745,748c657,658
918921
< expectTemplate('{{log}}')
919922
< .withInput({ blah: 'whee' })
920923
< .toCompileTo('');
921924
< expect(called).to.be.true();
922925
---
923926
> expectTemplate('{{log}}').withInput({ blah: 'whee' }).toCompileTo('');
924927
> expect(calls).toEqual(callsExpected);
925-
753,754c661,662
928+
753,754c663,664
926929
< describe('#lookup', function() {
927930
< it('should lookup arbitrary content', function() {
928931
---
929932
> describe('#lookup', () => {
930933
> it('should lookup arbitrary content', () => {
931-
760c668
934+
760c670
932935
< it('should not fail on undefined value', function() {
933936
---
934937
> it('should not fail on undefined value', () => {

0 commit comments

Comments
 (0)