@@ -29,15 +29,46 @@ module.exports = {
29
29
const message = 'This test case is identical to another case.' ;
30
30
const sourceCode = context . getSourceCode ( ) ;
31
31
32
+ // ----------------------------------------------------------------------
33
+ // Helpers
34
+ // ----------------------------------------------------------------------
35
+ /**
36
+ *compare two test cases depite of properties order.
37
+ *@returns {boolean } if eq, return true, else return false.
38
+ */
39
+ function eq ( ta , tb ) {
40
+ const pa = ta . properties || [ ] ;
41
+ const pb = tb . properties || [ ] ;
42
+
43
+ // if properties length not eq; return false;
44
+ if ( pa . length !== pb . length ) {
45
+ return false ;
46
+ }
47
+
48
+ // convert array to object
49
+ const paObj = pa . reduce ( ( result , item ) => {
50
+ const code = sourceCode . getText ( item ) ;
51
+ result [ code ] = true ;
52
+ return result ;
53
+ } , { } ) ;
54
+
55
+ for ( let i = 0 ; i < pb . length ; i ++ ) {
56
+ const code = sourceCode . getText ( pb [ i ] ) ;
57
+ if ( ! ( code in paObj ) ) {
58
+ return false ;
59
+ }
60
+ }
61
+ return true ;
62
+ }
63
+
32
64
return {
33
65
Program ( ast ) {
34
66
utils . getTestInfo ( context , ast ) . forEach ( testRun => {
35
67
[ testRun . valid , testRun . invalid ] . forEach ( tests => {
36
- const cache = Object . create ( null ) ;
68
+ const cache = [ ] ;
37
69
// to avoid tests being null
38
70
( tests || [ ] ) . forEach ( test => {
39
- const testCode = sourceCode . getText ( test ) ;
40
- if ( cache [ testCode ] ) {
71
+ if ( cache . some ( item => eq ( item , test ) ) ) {
41
72
context . report ( {
42
73
node : test ,
43
74
message,
@@ -50,7 +81,7 @@ module.exports = {
50
81
} ,
51
82
} ) ;
52
83
} else {
53
- cache [ testCode ] = true ;
84
+ cache . push ( test ) ;
54
85
}
55
86
} ) ;
56
87
} ) ;
0 commit comments