1- import { describe , expect , it , vi } from 'vitest'
2- import { EnhancerRegistry } from '../../../src/lib/registries'
3- import { PAGES } from '../../har-index'
41import fs from 'node:fs/promises'
52import path from 'node:path'
63import { fileURLToPath } from 'node:url'
74import { parseHTML } from 'linkedom'
5+ import { describe , expect , it , vi } from 'vitest'
6+ import { EnhancerRegistry } from '../../../src/lib/registries'
7+ import { PAGES } from '../../har-index'
88
99vi . stubGlobal ( 'defineContentScript' , vi . fn ( ) )
1010
1111vi . mock ( '../../../src/overtype/overtype' , ( ) => {
12- const mockConstructor = vi . fn ( ) . mockImplementation ( ( ) => [ {
13- container : document . createElement ( 'div' ) ,
14- wrapper : document . createElement ( 'div' ) ,
15- textarea : document . createElement ( 'textarea' ) ,
16- preview : document . createElement ( 'div' ) ,
17- getValue : vi . fn ( ( ) => '' ) ,
18- setValue : vi . fn ( ) ,
19- focus : vi . fn ( ) ,
20- destroy : vi . fn ( )
21- } ] )
22- mockConstructor . setCodeHighlighter = vi . fn ( )
12+ const mockConstructor = vi . fn ( ) . mockImplementation ( ( ) => [
13+ {
14+ container : document . createElement ( 'div' ) ,
15+ destroy : vi . fn ( ) ,
16+ focus : vi . fn ( ) ,
17+ getValue : vi . fn ( ( ) => '' ) ,
18+ preview : document . createElement ( 'div' ) ,
19+ setValue : vi . fn ( ) ,
20+ textarea : document . createElement ( 'textarea' ) ,
21+ wrapper : document . createElement ( 'div' ) ,
22+ } ,
23+ ] )
24+ ; ( mockConstructor as any ) . setCodeHighlighter = vi . fn ( )
2325 return {
24- default : mockConstructor
26+ default : mockConstructor ,
2527 }
2628} )
2729
@@ -32,18 +34,19 @@ async function loadHtmlFromHar(key: string): Promise<string> {
3234 const harContent = await fs . readFile ( harPath , 'utf-8' )
3335 const harData = JSON . parse ( harContent )
3436
35- const mainEntry = harData . log . entries . find ( ( entry : any ) =>
36- entry . request . url . includes ( 'github.com' ) &&
37- entry . response . content . mimeType ?. includes ( 'text/html' ) &&
38- entry . response . content . text
37+ const mainEntry = harData . log . entries . find (
38+ ( entry : any ) =>
39+ entry . request . url . includes ( 'github.com' ) &&
40+ entry . response . content . mimeType ?. includes ( 'text/html' ) &&
41+ entry . response . content . text ,
3942 )
4043
4144 if ( ! mainEntry ) {
4245 throw new Error ( `No HTML content found in HAR file: ${ key } .har` )
4346 }
4447
4548 let html = mainEntry . response . content . text
46-
49+
4750 // Check if content is base64 encoded
4851 if ( mainEntry . response . content . encoding === 'base64' ) {
4952 html = Buffer . from ( html , 'base64' ) . toString ( 'utf-8' )
@@ -55,28 +58,28 @@ async function loadHtmlFromHar(key: string): Promise<string> {
5558describe ( 'github' , ( ) => {
5659 it ( 'should identify gh_pr textarea and create proper spot object' , async ( ) => {
5760 const html = await loadHtmlFromHar ( 'gh_pr' )
58-
61+
5962 // Parse HTML with linkedom
6063 const dom = parseHTML ( html )
61-
64+
6265 // Replace global document with parsed one
6366 Object . assign ( globalThis , {
6467 document : dom . document ,
6568 window : {
6669 ...dom . window ,
67- location : new URL ( PAGES . gh_pr )
68- }
70+ location : new URL ( PAGES . gh_pr ) ,
71+ } ,
6972 } )
70-
73+
7174 const enhancers = new EnhancerRegistry ( )
7275 const textareas = document . querySelectorAll ( 'textarea' )
73-
76+
7477 let enhanced : any = null
7578 for ( const textarea of textareas ) {
7679 enhanced = enhancers . tryToEnhance ( textarea as HTMLTextAreaElement )
7780 if ( enhanced ) break
7881 }
79-
82+
8083 expect ( enhanced ) . toBeTruthy ( )
8184 expect ( enhanced . spot ) . toMatchInlineSnapshot ( `
8285 {
0 commit comments