11// Polyfills for axe-core DOM access in Node.js environment
22// This must be imported before any axe-core imports
33
4+ /* eslint-disable functional/immutable-data, @typescript-eslint/no-explicit-any, unicorn/prefer-global-this, n/no-unsupported-features/node-builtins, unicorn/no-typeof-undefined, @typescript-eslint/no-empty-function */
45if ( typeof global . window === 'undefined' ) {
56 const mockElement = {
67 style : { } ,
@@ -25,15 +26,15 @@ if (typeof global.window === 'undefined') {
2526
2627 // Mock document
2728 const mockDocument = {
28- createElement : tagName => ( {
29+ createElement : ( tagName : string ) => ( {
2930 ...mockElement ,
3031 tagName : tagName . toUpperCase ( ) ,
3132 } ) ,
32- createElementNS : ( ns , tagName ) => ( {
33+ createElementNS : ( _ns : string , tagName : string ) => ( {
3334 ...mockElement ,
3435 tagName : tagName . toUpperCase ( ) ,
3536 } ) ,
36- createTextNode : text => ( { ...mockElement , textContent : text } ) ,
37+ createTextNode : ( text : string ) => ( { ...mockElement , textContent : text } ) ,
3738 body : { ...mockElement , tagName : 'BODY' } ,
3839 documentElement : { ...mockElement , tagName : 'HTML' } ,
3940 head : { ...mockElement , tagName : 'HEAD' } ,
@@ -52,30 +53,30 @@ if (typeof global.window === 'undefined') {
5253 } ;
5354
5455 // Set up global objects
55- global . window = global ;
56- global . document = mockDocument ;
56+ ( global as any ) . window = global ;
57+ ( global as any ) . document = mockDocument ;
5758
5859 // Only set navigator if it doesn't exist or isn't read-only
5960 try {
6061 if ( typeof global . navigator === 'undefined' ) {
61- global . navigator = {
62+ ( global as any ) . navigator = {
6263 userAgent : 'Node.js' ,
6364 platform : 'Node.js' ,
6465 appVersion : 'Node.js' ,
6566 } ;
6667 }
67- } catch ( e ) {
68+ } catch {
6869 // navigator is read-only, skip setting it
6970 }
7071
7172 // Also set on globalThis for consistency
72- globalThis . window = global . window ;
73- globalThis . document = global . document ;
73+ ( globalThis as any ) . window = ( global as any ) . window ;
74+ ( globalThis as any ) . document = ( global as any ) . document ;
7475 try {
7576 if ( typeof globalThis . navigator === 'undefined' ) {
76- globalThis . navigator = global . navigator ;
77+ ( globalThis as any ) . navigator = ( global as any ) . navigator ;
7778 }
78- } catch ( e ) {
79+ } catch {
7980 // navigator is read-only, skip setting it
8081 }
8182}
0 commit comments