@adaas/a-concept 0.3.8 → 0.3.9

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.
@@ -828,4 +828,192 @@ describe('A-Scope tests', () => {
828
828
  expect(scope.resolve(MyFragment)).toBe(fragmentA2);
829
829
  expect(fragmentA2.array.length).toBe(0);
830
830
  });
831
+
832
+ // =========================================================================
833
+ // --------------------Fingerprint Tests-------------------------------------
834
+ // =========================================================================
835
+
836
+ it('Should return a fingerprint string', async () => {
837
+ const scope = new A_Scope({ name: 'TestScope' });
838
+ expect(typeof scope.fingerprint).toBe('string');
839
+ expect(scope.fingerprint.length).toBeGreaterThan(0);
840
+ });
841
+
842
+ it('Should return the same fingerprint for two empty scopes', async () => {
843
+ const scope1 = new A_Scope({ name: 'Scope1' });
844
+ const scope2 = new A_Scope({ name: 'Scope2' });
845
+ expect(scope1.fingerprint).toBe(scope2.fingerprint);
846
+ });
847
+
848
+ it('Should return the same fingerprint for two scopes with identical components', async () => {
849
+ class MyComponentA extends A_Component { }
850
+ class MyComponentB extends A_Component { }
851
+
852
+ const scope1 = new A_Scope({ name: 'Scope1' });
853
+ scope1.register(MyComponentA);
854
+ scope1.register(MyComponentB);
855
+
856
+ const scope2 = new A_Scope({ name: 'Scope2' });
857
+ scope2.register(MyComponentA);
858
+ scope2.register(MyComponentB);
859
+
860
+ expect(scope1.fingerprint).toBe(scope2.fingerprint);
861
+ });
862
+
863
+ it('Should return the same fingerprint regardless of registration order', async () => {
864
+ class MyComponentA extends A_Component { }
865
+ class MyComponentB extends A_Component { }
866
+
867
+ const scope1 = new A_Scope({ name: 'Scope1' });
868
+ scope1.register(MyComponentA);
869
+ scope1.register(MyComponentB);
870
+
871
+ const scope2 = new A_Scope({ name: 'Scope2' });
872
+ scope2.register(MyComponentB);
873
+ scope2.register(MyComponentA);
874
+
875
+ expect(scope1.fingerprint).toBe(scope2.fingerprint);
876
+ });
877
+
878
+ it('Should return different fingerprints for scopes with different components', async () => {
879
+ class MyComponentA extends A_Component { }
880
+ class MyComponentB extends A_Component { }
881
+
882
+ const scope1 = new A_Scope({ name: 'Scope1' });
883
+ scope1.register(MyComponentA);
884
+
885
+ const scope2 = new A_Scope({ name: 'Scope2' });
886
+ scope2.register(MyComponentB);
887
+
888
+ expect(scope1.fingerprint).not.toBe(scope2.fingerprint);
889
+ });
890
+
891
+ it('Should change fingerprint when a component is registered', async () => {
892
+ class MyComponentA extends A_Component { }
893
+
894
+ const scope = new A_Scope({ name: 'TestScope' });
895
+ const before = scope.fingerprint;
896
+
897
+ scope.register(MyComponentA);
898
+ const after = scope.fingerprint;
899
+
900
+ expect(before).not.toBe(after);
901
+ });
902
+
903
+ it('Should change fingerprint when a component is deregistered', async () => {
904
+ class MyComponentA extends A_Component { }
905
+
906
+ const scope = new A_Scope({ name: 'TestScope' });
907
+ scope.register(MyComponentA);
908
+ const before = scope.fingerprint;
909
+
910
+ scope.deregister(MyComponentA);
911
+ const after = scope.fingerprint;
912
+
913
+ expect(before).not.toBe(after);
914
+ });
915
+
916
+ it('Should return original fingerprint after register then deregister', async () => {
917
+ class MyComponentA extends A_Component { }
918
+
919
+ const scope = new A_Scope({ name: 'TestScope' });
920
+ const original = scope.fingerprint;
921
+
922
+ scope.register(MyComponentA);
923
+ expect(scope.fingerprint).not.toBe(original);
924
+
925
+ scope.deregister(MyComponentA);
926
+ expect(scope.fingerprint).toBe(original);
927
+ });
928
+
929
+ it('Should change fingerprint when an entity is registered', async () => {
930
+ class MyEntity extends A_Entity { }
931
+
932
+ const scope = new A_Scope({ name: 'TestScope' });
933
+ const before = scope.fingerprint;
934
+
935
+ scope.register(new MyEntity());
936
+ expect(scope.fingerprint).not.toBe(before);
937
+ });
938
+
939
+ it('Should change fingerprint when a fragment is registered', async () => {
940
+ class MyFragment extends A_Fragment { }
941
+
942
+ const scope = new A_Scope({ name: 'TestScope' });
943
+ const before = scope.fingerprint;
944
+
945
+ scope.register(new MyFragment());
946
+ expect(scope.fingerprint).not.toBe(before);
947
+ });
948
+
949
+ it('Should change fingerprint when an error is registered', async () => {
950
+ class MyError extends A_Error {
951
+ static code = 'MY_ERROR';
952
+ }
953
+
954
+ const scope = new A_Scope({ name: 'TestScope' });
955
+ const before = scope.fingerprint;
956
+
957
+ scope.register(MyError);
958
+ expect(scope.fingerprint).not.toBe(before);
959
+ });
960
+
961
+ it('Should return same fingerprint for two empty scopes inherited from the same parent', async () => {
962
+ const parent = new A_Scope({ name: 'Parent' });
963
+ parent.register(A_Component);
964
+
965
+ const child1 = new A_Scope({ name: 'Child1' }).inherit(parent);
966
+ const child2 = new A_Scope({ name: 'Child2' }).inherit(parent);
967
+
968
+ expect(child1.fingerprint).toBe(child2.fingerprint);
969
+ });
970
+
971
+ it('Should change fingerprint when parent scope content changes', async () => {
972
+ class MyComponentA extends A_Component { }
973
+
974
+ const parent = new A_Scope({ name: 'Parent' });
975
+ const child = new A_Scope({ name: 'Child' }).inherit(parent);
976
+
977
+ const before = child.fingerprint;
978
+
979
+ parent.register(MyComponentA);
980
+ expect(child.fingerprint).not.toBe(before);
981
+ });
982
+
983
+ it('Should change fingerprint when an import is added', async () => {
984
+ class MyComponentA extends A_Component { }
985
+
986
+ const importedScope = new A_Scope({ name: 'Imported' });
987
+ importedScope.register(MyComponentA);
988
+
989
+ const scope = new A_Scope({ name: 'TestScope' });
990
+ const before = scope.fingerprint;
991
+
992
+ scope.import(importedScope);
993
+ expect(scope.fingerprint).not.toBe(before);
994
+ });
995
+
996
+ it('Should change fingerprint when imported scope content changes', async () => {
997
+ class MyComponentA extends A_Component { }
998
+
999
+ const importedScope = new A_Scope({ name: 'Imported' });
1000
+ const scope = new A_Scope({ name: 'TestScope' });
1001
+ scope.import(importedScope);
1002
+
1003
+ const before = scope.fingerprint;
1004
+
1005
+ importedScope.register(MyComponentA);
1006
+ expect(scope.fingerprint).not.toBe(before);
1007
+ });
1008
+
1009
+ it('Should cache fingerprint and return same value on repeated access', async () => {
1010
+ class MyComponentA extends A_Component { }
1011
+
1012
+ const scope = new A_Scope({ name: 'TestScope' });
1013
+ scope.register(MyComponentA);
1014
+
1015
+ const first = scope.fingerprint;
1016
+ const second = scope.fingerprint;
1017
+ expect(first).toBe(second);
1018
+ });
831
1019
  });
package/tsconfig.json CHANGED
@@ -48,6 +48,7 @@
48
48
 
49
49
  "include": [
50
50
  "src/**/*",
51
+ "dist/**/*",
51
52
  "tests/**/*",
52
53
  "benchmarks/**/*.ts",
53
54
  "examples/**/*.ts",