Skip to content

Commit d12048a

Browse files
committed
Move getDetectionResults into corpus-fixture.
1 parent ffcaa0d commit d12048a

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

tests/corpus-fixture.ts

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

3232
import { describe as baseDescribe, test as baseTest, expect } from 'vitest'
33+
import type { StrippedLocation } from '@/lib/enhancer'
34+
import { EnhancerRegistry } from '../src/lib/registries'
3335
import type { CORPUS } from './corpus/_corpus-index'
3436
import { cleanupDOM, setupDOM } from './corpus-utils'
3537

@@ -38,6 +40,26 @@ export const describe = baseDescribe
3840
// Re-export expect from vitest
3941
export { expect }
4042

43+
// Helper function for detection tests
44+
export function getDetectionResults(document: Document, window: Window) {
45+
const enhancers = new EnhancerRegistry()
46+
const textareas = document.querySelectorAll('textarea')
47+
const location: StrippedLocation = {
48+
host: window.location.host,
49+
pathname: window.location.pathname,
50+
}
51+
const detectionResults = []
52+
for (const textarea of textareas) {
53+
const enhanced = enhancers.tryToEnhance(textarea, location)
54+
const forValue = `id=${textarea.id} name=${textarea.name} className=${textarea.className}`
55+
detectionResults.push({
56+
for: forValue,
57+
spot: enhanced ? enhanced.spot : 'NO_SPOT',
58+
})
59+
}
60+
return detectionResults
61+
}
62+
4163
// Fluent interface for any corpus type (HAR or HTML)
4264
export function withCorpus(corpusKey: keyof typeof CORPUS) {
4365
return {

tests/lib/enhancers/gh_detection.test.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
1-
import { describe, expect, withCorpus } from '../../corpus-fixture'
2-
3-
expect
4-
5-
import type { StrippedLocation } from '@/lib/enhancer'
6-
import { EnhancerRegistry } from '../../../src/lib/registries'
71
import { CORPUS } from '../../corpus/_corpus-index'
8-
9-
const enhancers = new EnhancerRegistry()
10-
11-
function getDetectionResults(document: Document, window: Window) {
12-
const textareas = document.querySelectorAll('textarea')
13-
const location: StrippedLocation = {
14-
host: window.location.host,
15-
pathname: window.location.pathname,
16-
}
17-
const detectionResults = []
18-
for (const textarea of textareas) {
19-
const enhanced = enhancers.tryToEnhance(textarea, location)
20-
const forValue = `id=${textarea.id} name=${textarea.name} className=${textarea.className}`
21-
detectionResults.push({
22-
for: forValue,
23-
spot: enhanced ? enhanced.spot : 'NO_SPOT',
24-
})
25-
}
26-
return detectionResults
27-
}
2+
import { describe, expect, getDetectionResults, withCorpus } from '../../corpus-fixture'
283

294
// Get all corpus entries that start with 'gh_'
305
const githubCorpusEntries = Object.keys(CORPUS).filter((key) => key.startsWith('gh_'))

0 commit comments

Comments
 (0)