Skip to content

Commit 78a9cae

Browse files
committed
Simplify HAR parsing.
1 parent 50454e6 commit 78a9cae

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,17 @@ vi.mock('../../../src/overtype/overtype', () => {
2929

3030
const __dirname = path.dirname(fileURLToPath(import.meta.url))
3131

32-
async function loadHtmlFromHar(key: string): Promise<string> {
32+
async function loadHtmlFromHar(key: keyof typeof PAGES): Promise<string> {
33+
const url = PAGES[key]
3334
const harPath = path.join(__dirname, '../../har', `${key}.har`)
3435
const harContent = await fs.readFile(harPath, 'utf-8')
3536
const harData = JSON.parse(harContent)
3637

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,
42-
)
43-
38+
const mainEntry = harData.log.entries.find((entry: any) => entry.request.url === url)
4439
if (!mainEntry) {
4540
throw new Error(`No HTML content found in HAR file: ${key}.har`)
4641
}
47-
48-
let html = mainEntry.response.content.text
49-
50-
// Check if content is base64 encoded
51-
if (mainEntry.response.content.encoding === 'base64') {
52-
html = Buffer.from(html, 'base64').toString('utf-8')
53-
}
54-
55-
return html
42+
return mainEntry.response.content.text
5643
}
5744

5845
describe('github', () => {

0 commit comments

Comments
 (0)