@@ -28,6 +28,11 @@ describe('ui', () => {
28
28
constants . forEach ( c => {
29
29
it ( `context should contain ${ c } ` , ( ) => expect ( context [ c ] ) . is . ok )
30
30
} )
31
+
32
+ it ( 'context should contain Feature.only' , ( ) => {
33
+ expect ( context . Feature . only ) . is . ok
34
+ expect ( context . Feature . only ) . to . be . a ( 'function' )
35
+ } )
31
36
} )
32
37
33
38
describe ( 'Feature' , ( ) => {
@@ -129,6 +134,68 @@ describe('ui', () => {
129
134
expect ( suiteConfig . suite . opts ) . to . deep . eq ( { } , 'Features should have no skip info' )
130
135
} )
131
136
137
+ it ( 'Feature can be run exclusively with only' , ( ) => {
138
+ // Create a new mocha instance to test grep behavior
139
+ const mocha = new Mocha ( )
140
+ let grepPattern = null
141
+
142
+ // Mock mocha.grep to capture the pattern
143
+ const originalGrep = mocha . grep
144
+ mocha . grep = function ( pattern ) {
145
+ grepPattern = pattern
146
+ return this
147
+ }
148
+
149
+ // Reset environment variable
150
+ delete process . env . FEATURE_ONLY
151
+
152
+ // Re-emit pre-require with our mocked mocha instance
153
+ suite . emit ( 'pre-require' , context , { } , mocha )
154
+
155
+ suiteConfig = context . Feature . only ( 'exclusive feature' , { key : 'value' } )
156
+
157
+ expect ( suiteConfig . suite . title ) . eq ( 'exclusive feature' )
158
+ expect ( suiteConfig . suite . opts ) . to . deep . eq ( { key : 'value' } , 'Feature.only should pass options correctly' )
159
+ expect ( suiteConfig . suite . pending ) . eq ( false , 'Feature.only must not be pending' )
160
+ expect ( grepPattern ) . to . be . instanceOf ( RegExp )
161
+ expect ( grepPattern . source ) . eq ( '^exclusive feature:' )
162
+ expect ( process . env . FEATURE_ONLY ) . eq ( 'true' , 'FEATURE_ONLY environment variable should be set' )
163
+
164
+ // Restore original grep
165
+ mocha . grep = originalGrep
166
+ } )
167
+
168
+ it ( 'Feature.only should work without options' , ( ) => {
169
+ // Create a new mocha instance to test grep behavior
170
+ const mocha = new Mocha ( )
171
+ let grepPattern = null
172
+
173
+ // Mock mocha.grep to capture the pattern
174
+ const originalGrep = mocha . grep
175
+ mocha . grep = function ( pattern ) {
176
+ grepPattern = pattern
177
+ return this
178
+ }
179
+
180
+ // Reset environment variable
181
+ delete process . env . FEATURE_ONLY
182
+
183
+ // Re-emit pre-require with our mocked mocha instance
184
+ suite . emit ( 'pre-require' , context , { } , mocha )
185
+
186
+ suiteConfig = context . Feature . only ( 'exclusive feature without options' )
187
+
188
+ expect ( suiteConfig . suite . title ) . eq ( 'exclusive feature without options' )
189
+ expect ( suiteConfig . suite . opts ) . to . deep . eq ( { } , 'Feature.only without options should have empty opts' )
190
+ expect ( suiteConfig . suite . pending ) . eq ( false , 'Feature.only must not be pending' )
191
+ expect ( grepPattern ) . to . be . instanceOf ( RegExp )
192
+ expect ( grepPattern . source ) . eq ( '^exclusive feature without options:' )
193
+ expect ( process . env . FEATURE_ONLY ) . eq ( 'true' , 'FEATURE_ONLY environment variable should be set' )
194
+
195
+ // Restore original grep
196
+ mocha . grep = originalGrep
197
+ } )
198
+
132
199
it ( 'Feature should correctly pass options to suite context' , ( ) => {
133
200
suiteConfig = context . Feature ( 'not skipped suite' , { key : 'value' } )
134
201
expect ( suiteConfig . suite . opts ) . to . deep . eq ( { key : 'value' } , 'Features should have passed options' )
0 commit comments