File tree Expand file tree Collapse file tree 2 files changed +53
-5
lines changed Expand file tree Collapse file tree 2 files changed +53
-5
lines changed Original file line number Diff line number Diff line change 11import { vi } from 'vitest'
22import { EnhancerRegistry } from '../../../src/lib/registries'
3- import { describe , expect , it } from '../../test-fixtures'
3+ import { describe , expect , usingHar } from '../../test-fixtures'
44
55vi . stubGlobal ( 'defineContentScript' , vi . fn ( ) )
66vi . mock ( '../../../src/overtype/overtype' , ( ) => {
@@ -23,10 +23,7 @@ vi.mock('../../../src/overtype/overtype', () => {
2323} )
2424
2525describe ( 'github' , ( ) => {
26- it ( 'should identify gh_pr textarea and create proper spot object' , async ( { harDOM } ) => {
27- // Setup DOM from HAR snapshot
28- await harDOM ( 'gh_pr' )
29-
26+ usingHar ( 'gh_pr' ) . it ( 'should identify gh_pr textarea and create proper spot object' , async ( ) => {
3027 const enhancers = new EnhancerRegistry ( )
3128 const textareas = document . querySelectorAll ( 'textarea' )
3229
Original file line number Diff line number Diff line change @@ -51,3 +51,54 @@ export const it = test
5151
5252// Re-export expect from vitest
5353export { expect }
54+
55+ // Fluent interface for HAR-based tests
56+ export function usingHar ( harKey : keyof typeof PAGES ) {
57+ // Create a test with auto-setup fixture for this HAR
58+ const harTest = baseTest . extend < TestFixtures & { _harAutoSetup : undefined } > ( {
59+ // Auto-setup fixture that runs the HAR setup automatically
60+ _harAutoSetup : [
61+ async ( { harDOM } , use ) => {
62+ await harDOM ( harKey )
63+ await use ( undefined )
64+ } ,
65+ { auto : true } ,
66+ ] ,
67+ // Keep the original harDOM fixture
68+ // biome-ignore lint/correctness/noEmptyPattern: Required by Vitest fixture API
69+ harDOM : async ( { } , use ) => {
70+ let currentDOM : TestDOMGlobals | null = null
71+
72+ const setupDOM = async ( key : keyof typeof PAGES ) : Promise < TestDOMGlobals > => {
73+ if ( currentDOM ) {
74+ cleanupDOM ( )
75+ }
76+ const html = await loadHtmlFromHar ( key )
77+ const url = PAGES [ key ]
78+ const domGlobals = createDOMFromHar ( html , url )
79+ setupDOMFromHar ( domGlobals )
80+ currentDOM = domGlobals
81+ return domGlobals
82+ }
83+
84+ await use ( setupDOM )
85+
86+ if ( currentDOM ) {
87+ cleanupDOM ( )
88+ currentDOM = null
89+ }
90+ } ,
91+ } )
92+
93+ return {
94+ describe : ( name : string , fn : ( ) => void ) => {
95+ return baseDescribe ( name , fn )
96+ } ,
97+
98+ it : ( name : string , fn : ( ) => void | Promise < void > ) => {
99+ return harTest ( name , async ( ) => {
100+ return await fn ( )
101+ } )
102+ } ,
103+ }
104+ }
You can’t perform that action at this time.
0 commit comments