1
- import { describe , it } from 'node:test' ;
2
- import { deepStrictEqual } from 'node:assert' ;
1
+ import { describe , it , mock } from 'node:test' ;
2
+ import { deepStrictEqual , strictEqual } from 'node:assert' ;
3
3
import { duplicateStabilityNodes } from '../../rules/duplicate-stability-nodes.mjs' ;
4
4
import { LINT_MESSAGES } from '../../constants.mjs' ;
5
5
@@ -44,18 +44,20 @@ const createContext = (nodes, path = 'file.md') => ({
44
44
children : nodes ,
45
45
} ,
46
46
path,
47
+ report : mock . fn ( ) ,
47
48
} ) ;
48
49
49
50
describe ( 'duplicateStabilityNodes' , ( ) => {
50
- it ( 'returns empty array when there are no stability nodes' , ( ) => {
51
+ it ( 'should not report when there are no stability nodes' , ( ) => {
51
52
const context = createContext ( [
52
53
createHeadingNode ( 1 , 1 ) ,
53
54
createHeadingNode ( 2 , 2 ) ,
54
55
] ) ;
55
- deepStrictEqual ( duplicateStabilityNodes ( context ) , [ ] ) ;
56
+ duplicateStabilityNodes ( context ) ;
57
+ strictEqual ( context . report . mock . callCount ( ) , 0 ) ;
56
58
} ) ;
57
59
58
- it ( 'returns empty array when there are no duplicate stability nodes' , ( ) => {
60
+ it ( 'should not report when there are no duplicate stability nodes' , ( ) => {
59
61
const context = createContext ( [
60
62
createHeadingNode ( 1 , 1 ) ,
61
63
createStabilityNode ( 0 , 2 ) ,
@@ -64,7 +66,8 @@ describe('duplicateStabilityNodes', () => {
64
66
createHeadingNode ( 3 , 5 ) ,
65
67
createStabilityNode ( 2 , 6 ) ,
66
68
] ) ;
67
- deepStrictEqual ( duplicateStabilityNodes ( context ) , [ ] ) ;
69
+ duplicateStabilityNodes ( context ) ;
70
+ strictEqual ( context . report . mock . callCount ( ) , 0 ) ;
68
71
} ) ;
69
72
70
73
it ( 'detects duplicate stability nodes within a chain' , ( ) => {
@@ -76,7 +79,13 @@ describe('duplicateStabilityNodes', () => {
76
79
duplicateNode , // Duplicate stability node
77
80
] ) ;
78
81
79
- deepStrictEqual ( duplicateStabilityNodes ( context ) , [
82
+ duplicateStabilityNodes ( context ) ;
83
+
84
+ strictEqual ( context . report . mock . callCount ( ) , 1 ) ;
85
+
86
+ const call = context . report . mock . calls [ 0 ] ;
87
+
88
+ deepStrictEqual ( call . arguments , [
80
89
{
81
90
level : 'warn' ,
82
91
message : LINT_MESSAGES . duplicateStabilityNode ,
@@ -99,7 +108,13 @@ describe('duplicateStabilityNodes', () => {
99
108
duplicateNode2 , // This should trigger another issue
100
109
] ) ;
101
110
102
- deepStrictEqual ( duplicateStabilityNodes ( context ) , [
111
+ duplicateStabilityNodes ( context ) ;
112
+
113
+ strictEqual ( context . report . mock . callCount ( ) , 2 ) ;
114
+
115
+ const calls = context . report . mock . calls . flatMap ( call => call . arguments ) ;
116
+
117
+ deepStrictEqual ( calls , [
103
118
{
104
119
level : 'warn' ,
105
120
message : LINT_MESSAGES . duplicateStabilityNode ,
@@ -133,7 +148,13 @@ describe('duplicateStabilityNodes', () => {
133
148
duplicateNode , // This should trigger an issue
134
149
] ) ;
135
150
136
- deepStrictEqual ( duplicateStabilityNodes ( context ) , [
151
+ duplicateStabilityNodes ( context ) ;
152
+
153
+ strictEqual ( context . report . mock . callCount ( ) , 1 ) ;
154
+
155
+ const call = context . report . mock . calls [ 0 ] ;
156
+
157
+ deepStrictEqual ( call . arguments , [
137
158
{
138
159
level : 'warn' ,
139
160
message : LINT_MESSAGES . duplicateStabilityNode ,
@@ -158,7 +179,13 @@ describe('duplicateStabilityNodes', () => {
158
179
duplicateNode2 , // This should trigger another issue
159
180
] ) ;
160
181
161
- deepStrictEqual ( duplicateStabilityNodes ( context ) , [
182
+ duplicateStabilityNodes ( context ) ;
183
+
184
+ strictEqual ( context . report . mock . callCount ( ) , 2 ) ;
185
+
186
+ const calls = context . report . mock . calls . flatMap ( call => call . arguments ) ;
187
+
188
+ deepStrictEqual ( calls , [
162
189
{
163
190
level : 'warn' ,
164
191
message : LINT_MESSAGES . duplicateStabilityNode ,
@@ -199,6 +226,8 @@ describe('duplicateStabilityNodes', () => {
199
226
} ,
200
227
] ) ;
201
228
202
- deepStrictEqual ( duplicateStabilityNodes ( context ) , [ ] ) ;
229
+ duplicateStabilityNodes ( context ) ;
230
+
231
+ strictEqual ( context . report . mock . callCount ( ) , 0 ) ;
203
232
} ) ;
204
233
} ) ;
0 commit comments