Skip to content

Commit 50454e6

Browse files
committed
Fix all CI stuff.
1 parent 193c00e commit 50454e6

File tree

2 files changed

+44
-39
lines changed

2 files changed

+44
-39
lines changed

browser-extension/tests/lib/enhancers/github.test.ts

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
import { describe, expect, it, vi } from 'vitest'
2-
import { EnhancerRegistry } from '../../../src/lib/registries'
3-
import { PAGES } from '../../har-index'
41
import fs from 'node:fs/promises'
52
import path from 'node:path'
63
import { fileURLToPath } from 'node:url'
74
import { 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

99
vi.stubGlobal('defineContentScript', vi.fn())
1010

1111
vi.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> {
5558
describe('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
{

browser-extension/tests/setup.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,38 @@ const dom = parseHTML(`
1515

1616
// Mock global DOM objects
1717
Object.assign(globalThis, {
18-
window: dom.window,
19-
document: dom.document,
2018
Document: dom.Document,
2119
DocumentFragment: dom.DocumentFragment,
22-
HTMLElement: dom.HTMLElement,
23-
HTMLTextAreaElement: dom.HTMLTextAreaElement,
20+
document: dom.document,
21+
Element: dom.Element,
2422
HTMLDivElement: dom.HTMLDivElement,
23+
HTMLElement: dom.HTMLElement,
2524
HTMLMetaElement: dom.HTMLMetaElement,
26-
Element: dom.Element,
25+
HTMLTextAreaElement: dom.HTMLTextAreaElement,
26+
location: dom.window.location,
2727
Node: dom.Node,
2828
Text: dom.Text,
29-
location: dom.window.location
29+
window: dom.window,
3030
})
3131

3232
// Mock querySelector methods properly
3333
const originalQuerySelector = dom.document.querySelector.bind(dom.document)
3434
const originalQuerySelectorAll = dom.document.querySelectorAll.bind(dom.document)
3535

36-
dom.document.querySelector = function(selector) {
36+
dom.document.querySelector = (selector: string) => {
3737
try {
3838
return originalQuerySelector(selector)
39-
} catch (e) {
39+
} catch (_e) {
4040
return null
4141
}
4242
}
4343

44-
dom.document.querySelectorAll = function(selector) {
44+
dom.document.querySelectorAll = ((selector: string) => {
4545
try {
4646
return originalQuerySelectorAll(selector)
47-
} catch (e) {
48-
return []
47+
} catch (_e) {
48+
// Return an empty NodeList-like object instead of array
49+
const emptyNodeList = document.createDocumentFragment().childNodes
50+
return emptyNodeList as unknown as NodeListOf<Element>
4951
}
50-
}
52+
}) as typeof dom.document.querySelectorAll

0 commit comments

Comments
 (0)