@@ -28,6 +28,11 @@ describe('ui', () => {
2828    constants . forEach ( c  =>  { 
2929      it ( `context should contain ${ c }  ,  ( )  =>  expect ( context [ c ] ) . is . ok ) 
3030    } ) 
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+     } ) 
3136  } ) 
3237
3338  describe ( 'Feature' ,  ( )  =>  { 
@@ -129,6 +134,68 @@ describe('ui', () => {
129134      expect ( suiteConfig . suite . opts ) . to . deep . eq ( { } ,  'Features should have no skip info' ) 
130135    } ) 
131136
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+ 
132199    it ( 'Feature should correctly pass options to suite context' ,  ( )  =>  { 
133200      suiteConfig  =  context . Feature ( 'not skipped suite' ,  {  key : 'value'  } ) 
134201      expect ( suiteConfig . suite . opts ) . to . deep . eq ( {  key : 'value'  } ,  'Features should have passed options' ) 
0 commit comments