File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports [` test hash object > hash object 1` ] = ` "c710e218177ae3b76ac1b058d43fbd56c3dc71b48709dc15326862a75b0beec2"` ;
Original file line number Diff line number Diff line change 1
1
import {
2
2
findClosestConfigFile ,
3
3
findClosestPackageRoot ,
4
+ hashObject ,
4
5
normalizeAlias ,
5
6
normalizePatterns ,
6
7
sortPaths ,
@@ -380,3 +381,57 @@ describe("test normalize alias", () => {
380
381
expect ( normalizedAlias ) . toBeUndefined ( ) ;
381
382
} ) ;
382
383
} ) ;
384
+
385
+ describe ( "test hash object" , ( ) => {
386
+ it ( "hash object" , ( ) => {
387
+ const obj = {
388
+ a : 1 ,
389
+ b : "string" ,
390
+ c : [ 1 , 2 , 3 ] ,
391
+ d : { e : "f" } ,
392
+ } ;
393
+
394
+ const hash = hashObject ( obj ) ;
395
+ expect ( hash ) . toMatchSnapshot ( ) ;
396
+ } ) ;
397
+
398
+ it ( "hash object with different order" , ( ) => {
399
+ const obj1 = {
400
+ a : 1 ,
401
+ b : "string" ,
402
+ c : [ 1 , 2 , 3 ] ,
403
+ d : { e : "f" } ,
404
+ } ;
405
+
406
+ const obj2 = {
407
+ b : "string" ,
408
+ a : 1 ,
409
+ d : { e : "f" } ,
410
+ c : [ 1 , 2 , 3 ] ,
411
+ } ;
412
+
413
+ const hash1 = hashObject ( obj1 ) ;
414
+ const hash2 = hashObject ( obj2 ) ;
415
+ expect ( hash1 ) . toBe ( hash2 ) ;
416
+ } ) ;
417
+
418
+ it ( "hash object with different values" , ( ) => {
419
+ const obj1 = {
420
+ a : 1 ,
421
+ b : "string" ,
422
+ c : [ 1 , 2 , 3 ] ,
423
+ d : { e : "f" } ,
424
+ } ;
425
+
426
+ const obj2 = {
427
+ a : 2 ,
428
+ b : "string" ,
429
+ c : [ 1 , 2 , 3 ] ,
430
+ d : { e : "f" } ,
431
+ } ;
432
+
433
+ const hash1 = hashObject ( obj1 ) ;
434
+ const hash2 = hashObject ( obj2 ) ;
435
+ expect ( hash1 ) . not . toBe ( hash2 ) ;
436
+ } ) ;
437
+ } ) ;
You can’t perform that action at this time.
0 commit comments