Skip to content

Commit bee258e

Browse files
committed
biome:fix
1 parent 464cda2 commit bee258e

File tree

3 files changed

+76
-70
lines changed

3 files changed

+76
-70
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export const PAGES = {
2-
'gh_issue': 'https://github.com/diffplug/selfie/issues/523',
3-
'gh_pr': 'https://github.com/diffplug/selfie/pull/517',
4-
} as const
5-
2+
gh_issue: 'https://github.com/diffplug/selfie/issues/523',
3+
gh_pr: 'https://github.com/diffplug/selfie/pull/517',
4+
} as const

browser-extension/tests/har-record.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { chromium } from '@playwright/test'
21
import fs from 'node:fs/promises'
32
import path from 'node:path'
3+
import { chromium } from '@playwright/test'
44
import { PAGES } from './har-index'
55

66
// Convert glob pattern to regex
@@ -18,7 +18,8 @@ function filterPages(pattern: string) {
1818
return PAGES.filter(([name]) => regex.test(name))
1919
}
2020

21-
const FILTER = /^(https?:\/\/(github\.com|assets\.github\.com|avatars\.githubusercontent\.com|user-images\.githubusercontent\.com))/
21+
const FILTER =
22+
/^(https?:\/\/(github\.com|assets\.github\.com|avatars\.githubusercontent\.com|user-images\.githubusercontent\.com))/
2223

2324
// Sanitization config
2425
const REDACTIONS: Array<[RegExp, string]> = [
@@ -29,15 +30,15 @@ const REDACTIONS: Array<[RegExp, string]> = [
2930

3031
async function record(name: string, url: string) {
3132
console.log('Recording HAR:', name, url)
32-
33+
3334
const browser = await chromium.launch()
3435
const context = await browser.newContext({
35-
storageState: 'playwright/.auth/gh.json', // local-only; never commit
3636
recordHar: {
37-
path: `tests/har/${name}.har`,
3837
mode: 'minimal', // smaller; omits cookies etc.
38+
path: `tests/har/${name}.har`,
3939
urlFilter: FILTER, // restrict scope to GitHub + assets
4040
},
41+
storageState: 'playwright/.auth/gh.json', // local-only; never commit
4142
})
4243

4344
const page = await context.newPage()
@@ -61,7 +62,7 @@ function stripHeaders(headers?: any[]) {
6162

6263
async function sanitize(filename: string) {
6364
console.log('Sanitizing:', filename)
64-
65+
6566
const p = path.join('tests/har', filename)
6667
const har = JSON.parse(await fs.readFile(p, 'utf8'))
6768

@@ -83,7 +84,7 @@ async function sanitize(filename: string) {
8384

8485
;(async () => {
8586
const pattern = process.argv[2]
86-
87+
8788
// If no argument provided, show available keys
8889
if (!pattern) {
8990
console.log('Available recording targets:')
@@ -97,10 +98,10 @@ async function sanitize(filename: string) {
9798
console.log(' npm run har:record "github_issue" # Record specific target')
9899
return
99100
}
100-
101+
101102
// Filter pages based on pattern
102103
const pagesToRecord = filterPages(pattern)
103-
104+
104105
if (pagesToRecord.length === 0) {
105106
console.log(`No targets match pattern: ${pattern}`)
106107
console.log('Available targets:')
@@ -109,26 +110,26 @@ async function sanitize(filename: string) {
109110
}
110111
return
111112
}
112-
113+
113114
console.log(`Recording ${pagesToRecord.length} target(s) matching "${pattern}":`)
114115
for (const [name] of pagesToRecord) {
115116
console.log(` ${name}`)
116117
}
117118
console.log()
118-
119+
119120
await fs.mkdir('tests/har', { recursive: true })
120-
121+
121122
// Record filtered HAR files
122123
for (const [name, url] of pagesToRecord) {
123124
await record(name, url)
124125
}
125-
126+
126127
console.log('Recording complete. Sanitizing...')
127-
128+
128129
// Sanitize recorded HAR files
129130
for (const [name] of pagesToRecord) {
130131
await sanitize(`${name}.har`)
131132
}
132-
133+
133134
console.log('Done.')
134-
})()
135+
})()

browser-extension/tests/har-view.ts

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import express from 'express'
21
import fs from 'node:fs/promises'
32
import path from 'node:path'
43
import { fileURLToPath } from 'node:url'
4+
import express from 'express'
55
import { PAGES } from './har-index'
66

77
const __dirname = path.dirname(fileURLToPath(import.meta.url))
@@ -13,7 +13,7 @@ const harCache = new Map<string, any>()
1313

1414
// Create mapping from HAR filename to original URL
1515
const harToUrlMap = Object.fromEntries(
16-
Object.entries(PAGES).map(([key, url]) => [`${key}.har`, url])
16+
Object.entries(PAGES).map(([key, url]) => [`${key}.har`, url]),
1717
)
1818

1919
// Extract URL parts for location patching
@@ -22,14 +22,14 @@ function getUrlParts(filename: string) {
2222
if (!originalUrl) {
2323
return null
2424
}
25-
25+
2626
try {
2727
const url = new URL(originalUrl)
2828
return {
29+
host: url.host,
2930
hostname: url.hostname,
30-
pathname: url.pathname,
3131
href: originalUrl,
32-
host: url.host
32+
pathname: url.pathname,
3333
}
3434
} catch {
3535
return null
@@ -39,9 +39,9 @@ function getUrlParts(filename: string) {
3939
// Check if WXT dev server is running
4040
async function checkDevServer(): Promise<boolean> {
4141
try {
42-
const response = await fetch('http://localhost:3000/@vite/client', {
42+
const response = await fetch('http://localhost:3000/@vite/client', {
4343
method: 'HEAD',
44-
signal: AbortSignal.timeout(2000)
44+
signal: AbortSignal.timeout(2000),
4545
})
4646
return response.ok
4747
} catch {
@@ -54,7 +54,7 @@ async function loadHar(filename: string) {
5454
if (harCache.has(filename)) {
5555
return harCache.get(filename)
5656
}
57-
57+
5858
const harPath = path.join(__dirname, 'har', filename)
5959
const harContent = await fs.readFile(harPath, 'utf-8')
6060
const harData = JSON.parse(harContent)
@@ -67,19 +67,22 @@ app.get('/', async (req, res) => {
6767
try {
6868
const harDir = path.join(__dirname, 'har')
6969
const files = await fs.readdir(harDir)
70-
const harFiles = files.filter(file => file.endsWith('.har'))
70+
const harFiles = files.filter((file) => file.endsWith('.har'))
7171
const devServerRunning = await checkDevServer()
72-
73-
const devServerWarning = !devServerRunning ? `
72+
73+
const devServerWarning = !devServerRunning
74+
? `
7475
<div style="background: #fff3cd; border: 1px solid #ffeaa7; border-radius: 6px; padding: 15px; margin-bottom: 20px;">
7576
<strong>⚠️ Warning:</strong> WXT dev server is not running on localhost:3000<br>
7677
<small>Gitcasso-enabled links won't work. Run <code>npm run dev</code> to start the server and <strong>then refresh this page</strong>.</small>
7778
</div>
78-
` : ''
79-
80-
const links = harFiles.map(file => {
81-
const basename = path.basename(file, '.har')
82-
return `
79+
`
80+
: ''
81+
82+
const links = harFiles
83+
.map((file) => {
84+
const basename = path.basename(file, '.har')
85+
return `
8386
<li>
8487
<div style="margin-bottom: 10px; font-weight: bold; color: #555;">${basename}</div>
8588
<div style="display: flex; gap: 10px;">
@@ -90,8 +93,9 @@ app.get('/', async (req, res) => {
9093
</div>
9194
</li>
9295
`
93-
}).join('')
94-
96+
})
97+
.join('')
98+
9599
res.send(`
96100
<!DOCTYPE html>
97101
<html>
@@ -141,28 +145,29 @@ app.get('/page/:filename', async (req, res) => {
141145
if (!filename.endsWith('.har')) {
142146
return res.status(400).send('Invalid file type')
143147
}
144-
148+
145149
const harData = await loadHar(filename)
146-
150+
147151
// Find the main HTML response
148-
const mainEntry = harData.log.entries.find((entry: any) =>
149-
entry.request.url.includes('github.com') &&
150-
entry.response.content.mimeType?.includes('text/html') &&
151-
entry.response.content.text
152+
const mainEntry = harData.log.entries.find(
153+
(entry: any) =>
154+
entry.request.url.includes('github.com') &&
155+
entry.response.content.mimeType?.includes('text/html') &&
156+
entry.response.content.text,
152157
)
153-
158+
154159
if (!mainEntry) {
155160
return res.status(404).send('No HTML content found in HAR file')
156161
}
157-
162+
158163
let html = mainEntry.response.content.text
159-
164+
160165
// Replace external URLs with local asset URLs
161166
html = html.replace(
162167
/https:\/\/(github\.com|assets\.github\.com|avatars\.githubusercontent\.com|user-images\.githubusercontent\.com)/g,
163-
`/asset/${filename.replace('.har', '')}`
168+
`/asset/${filename.replace('.har', '')}`,
164169
)
165-
170+
166171
res.send(html)
167172
} catch (error) {
168173
console.error('Error serving page:', error)
@@ -177,34 +182,35 @@ app.get('/page/:filename/gitcasso', async (req, res) => {
177182
if (!filename.endsWith('.har')) {
178183
return res.status(400).send('Invalid file type')
179184
}
180-
185+
181186
// Get original URL parts for location patching
182187
const urlParts = getUrlParts(filename)
183188
if (!urlParts) {
184189
return res.status(400).send('Unknown HAR file - not found in har-index.ts')
185190
}
186-
191+
187192
const harData = await loadHar(filename)
188-
193+
189194
// Find the main HTML response
190-
const mainEntry = harData.log.entries.find((entry: any) =>
191-
entry.request.url.includes('github.com') &&
192-
entry.response.content.mimeType?.includes('text/html') &&
193-
entry.response.content.text
195+
const mainEntry = harData.log.entries.find(
196+
(entry: any) =>
197+
entry.request.url.includes('github.com') &&
198+
entry.response.content.mimeType?.includes('text/html') &&
199+
entry.response.content.text,
194200
)
195-
201+
196202
if (!mainEntry) {
197203
return res.status(404).send('No HTML content found in HAR file')
198204
}
199-
205+
200206
let html = mainEntry.response.content.text
201-
207+
202208
// Replace external URLs with local asset URLs
203209
html = html.replace(
204210
/https:\/\/(github\.com|assets\.github\.com|avatars\.githubusercontent\.com|user-images\.githubusercontent\.com)/g,
205-
`/asset/${filename.replace('.har', '')}`
211+
`/asset/${filename.replace('.har', '')}`,
206212
)
207-
213+
208214
// Inject patched content script with location patching
209215
const contentScriptTag = `
210216
<script>
@@ -256,14 +262,14 @@ app.get('/page/:filename/gitcasso', async (req, res) => {
256262
});
257263
</script>
258264
`
259-
265+
260266
// Insert script before closing body tag, or at the end if no body tag
261267
if (html.includes('</body>')) {
262268
html = html.replace('</body>', `${contentScriptTag}</body>`)
263269
} else {
264270
html += contentScriptTag
265271
}
266-
272+
267273
res.send(html)
268274
} catch (error) {
269275
console.error('Error serving page:', error)
@@ -276,24 +282,24 @@ app.get('/asset/:harname/*', async (req, res) => {
276282
try {
277283
const harname = req.params.harname + '.har'
278284
const assetPath = (req.params as any)[0] as string
279-
285+
280286
const harData = await loadHar(harname)
281-
287+
282288
// Find matching asset in HAR
283289
const assetEntry = harData.log.entries.find((entry: any) => {
284290
const url = new URL(entry.request.url)
285291
return url.pathname === '/' + assetPath || url.pathname.endsWith('/' + assetPath)
286292
})
287-
293+
288294
if (!assetEntry) {
289295
return res.status(404).send('Asset not found')
290296
}
291-
297+
292298
const content = assetEntry.response.content
293299
const mimeType = content.mimeType || 'application/octet-stream'
294-
300+
295301
res.set('Content-Type', mimeType)
296-
302+
297303
if (content.encoding === 'base64') {
298304
res.send(Buffer.from(content.text, 'base64'))
299305
} else {
@@ -308,4 +314,4 @@ app.get('/asset/:harname/*', async (req, res) => {
308314
app.listen(PORT, () => {
309315
console.log(`HAR Page Viewer running at http://localhost:${PORT}`)
310316
console.log('Click the links to view recorded GitHub pages')
311-
})
317+
})

0 commit comments

Comments
 (0)