Skip to content

Commit 1f20c7d

Browse files
committed
Fixup
1 parent cf2d3dd commit 1f20c7d

File tree

4 files changed

+40
-24
lines changed

4 files changed

+40
-24
lines changed

browser-extension/tests/corpus-view.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import path from 'node:path'
2727
import { fileURLToPath } from 'node:url'
2828
import express from 'express'
2929
import type { Har } from 'har-format'
30-
import { CORPUS, type CorpusEntry } from './corpus/_corpus-index'
30+
import { CORPUS } from './corpus/_corpus-index'
3131

3232
const __dirname = path.dirname(fileURLToPath(import.meta.url))
3333
const app = express()
@@ -41,7 +41,11 @@ const harCache = new Map<string, Har>()
4141

4242
// Extract URL parts for location patching
4343
function getUrlParts(key: string) {
44-
const originalUrl = CORPUS[key].url
44+
const entry = CORPUS[key]
45+
if (!entry) {
46+
throw new Error(`Corpus entry not found: ${key}`)
47+
}
48+
const originalUrl = entry.url
4549
const url = new URL(originalUrl)
4650
return {
4751
host: url.host,
@@ -77,7 +81,9 @@ app.get('/', async (_req, res) => {
7781
try {
7882
const links = Object.entries(CORPUS)
7983
.map(([key, entry]) => {
80-
const description = entry.description ? `<div style="color: #666; font-size: 0.9em; margin-top: 5px;">${entry.description}</div>` : ''
84+
const description = entry.description
85+
? `<div style="color: #666; font-size: 0.9em; margin-top: 5px;">${entry.description}</div>`
86+
: ''
8187
return `
8288
<li>
8389
<div style="margin-bottom: 10px;">
@@ -143,14 +149,16 @@ app.get('/', async (_req, res) => {
143149
// Serve the main page from corpus
144150
app.get('/corpus/:key/:mode(clean|gitcasso)', async (req, res) => {
145151
try {
146-
const key = req.params.key
147-
const mode = req.params.mode as 'clean' | 'gitcasso'
152+
// biome-ignore lint/complexity/useLiteralKeys: type comes from path string
153+
const key = req.params['key']
154+
// biome-ignore lint/complexity/useLiteralKeys: type comes from path string
155+
const mode = req.params['mode'] as 'clean' | 'gitcasso'
148156

149-
if (!(key in CORPUS)) {
157+
if (!key || !(key in CORPUS)) {
150158
return res.status(400).send('Invalid key - not found in CORPUS')
151159
}
152160

153-
const entry = CORPUS[key]
161+
const entry = CORPUS[key]!
154162

155163
if (entry.type === 'har') {
156164
// Handle HAR corpus
@@ -216,11 +224,11 @@ app.get('/corpus/:key/:mode(clean|gitcasso)', async (req, res) => {
216224
app.get('/asset/:key/*', async (req, res) => {
217225
try {
218226
const key = req.params.key
219-
if (!(key in CORPUS)) {
227+
if (!key || !(key in CORPUS)) {
220228
return res.status(400).send('Invalid key - not found in CORPUS')
221229
}
222230

223-
const entry = CORPUS[key]
231+
const entry = CORPUS[key]!
224232
if (entry.type !== 'har') {
225233
return res.status(400).send('Asset serving only available for HAR corpus')
226234
}
@@ -528,4 +536,4 @@ function injectGitcassoScript(key: string, html: string) {
528536
throw error('No closing body tag, nowhere to put the content script!')
529537
}
530538
return html.replace('</body>', `${contentScriptTag}</body>`)
531-
}
539+
}

browser-extension/tests/corpus/_corpus-index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ export interface CorpusEntry {
99
export const CORPUS: Record<string, CorpusEntry> = {
1010
// HAR corpus (initial page loads)
1111
gh_issue: {
12+
type: 'har',
1213
url: 'https://github.com/diffplug/selfie/issues/523',
13-
type: 'har'
1414
},
1515
gh_new_issue: {
16+
type: 'har',
1617
url: 'https://github.com/diffplug/selfie/issues/new',
17-
type: 'har'
1818
},
1919
gh_new_pr: {
20+
type: 'har',
2021
url: 'https://github.com/diffplug/selfie/compare/main...cavia-porcellus:selfie:main?expand=1',
21-
type: 'har'
2222
},
2323
gh_pr: {
24+
type: 'har',
2425
url: 'https://github.com/diffplug/selfie/pull/517',
25-
type: 'har'
2626
},
2727
// HTML corpus (captured after user interactions via SingleFile)
2828
// Add new entries here as needed, e.g.:
@@ -31,4 +31,4 @@ export const CORPUS: Record<string, CorpusEntry> = {
3131
// type: 'html',
3232
// description: 'Issue page with comment textarea expanded and preview tab active'
3333
// }
34-
} as const
34+
} as const

browser-extension/tests/har-fixture-utils.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path'
33
import { fileURLToPath } from 'node:url'
44
import type { Har as HarFile } from 'har-format'
55
import { parseHTML } from 'linkedom'
6-
import { PAGES } from './har/_har-index'
6+
import { CORPUS } from './corpus/_corpus-index'
77

88
const __dirname = path.dirname(fileURLToPath(import.meta.url))
99

@@ -32,9 +32,13 @@ export interface TestDOMContext {
3232
let currentDOMInstance: any = null
3333
let originalGlobals: Partial<TestDOMGlobals> = {}
3434

35-
export async function loadHtmlFromHar(key: keyof typeof PAGES): Promise<string> {
36-
const url = PAGES[key]
37-
const harPath = path.join(__dirname, 'har', `${key}.har`)
35+
export async function loadHtmlFromHar(key: keyof typeof CORPUS): Promise<string> {
36+
const entry = CORPUS[key]
37+
if (!entry || entry.type !== 'har') {
38+
throw new Error(`Invalid HAR corpus key: ${String(key)}`)
39+
}
40+
const url = entry.url
41+
const harPath = path.join(__dirname, 'corpus', 'har', `${String(key)}.har`)
3842
const harContent = await fs.readFile(harPath, 'utf-8')
3943
const harData: HarFile = JSON.parse(harContent)
4044
const mainEntry = harData.log.entries.find((entry) => entry.request.url === url)
@@ -101,9 +105,13 @@ export function cleanupDOM(): void {
101105
}
102106
}
103107

104-
export async function setupHarDOM(key: keyof typeof PAGES): Promise<TestDOMGlobals> {
108+
export async function setupHarDOM(key: keyof typeof CORPUS): Promise<TestDOMGlobals> {
105109
const html = await loadHtmlFromHar(key)
106-
const url = PAGES[key]
110+
const entry = CORPUS[key]
111+
if (!entry || entry.type !== 'har') {
112+
throw new Error(`Invalid HAR corpus key: ${String(key)}`)
113+
}
114+
const url = entry.url
107115
const domGlobals = createDOMFromHar(html, url)
108116
setupDOMFromHar(domGlobals)
109117
return domGlobals

browser-extension/tests/har-fixture.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ vi.mock('overtype', () => {
3030
})
3131

3232
import { describe as baseDescribe, test as baseTest, expect } from 'vitest'
33-
import type { PAGES } from './har/_har-index'
33+
import type { CORPUS } from './corpus/_corpus-index'
3434
import { cleanupDOM, setupHarDOM } from './har-fixture-utils'
3535

3636
export const describe = baseDescribe
@@ -39,10 +39,10 @@ export const describe = baseDescribe
3939
export { expect }
4040

4141
// Fluent interface for HAR-based tests
42-
export function usingHar(harKey: keyof typeof PAGES) {
42+
export function usingHar(harKey: keyof typeof CORPUS) {
4343
return {
4444
it: (name: string, fn: () => void | Promise<void>) => {
45-
return baseTest(`${harKey}:${name}`, async () => {
45+
return baseTest(`${String(harKey)}:${name}`, async () => {
4646
// Setup HAR DOM before test
4747
await setupHarDOM(harKey)
4848

0 commit comments

Comments
 (0)