Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/rules/page/dynamic-technologies.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
},
{
"name": "jQuery",
"matchIn": ["resources"],
"patterns": ["jquery(?:-\\d|\\.)"]
},
{
Expand Down
1 change: 1 addition & 0 deletions public/rules/page/frontend-frameworks.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
{
"name": "jQuery",
"confidence": "高",
"matchIn": ["resources"],
"patterns": ["jquery(?:-\\d|\\.)"],
"globals": ["jQuery"],
"versionFrom": "jQuery.fn.jquery"
Expand Down
61 changes: 61 additions & 0 deletions tests/jquery-detection.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import path from 'node:path'
import { test } from 'node:test'
import { build } from 'esbuild'
import { repoRoot, loadPageRules, runPageDetector } from './helpers/rule-harness.mjs'

test('the extension detector rejects jQuery prose while preserving runtime and resource hits', async () => {
const rules = loadPageRules(['page/frontend-frameworks.json'])
const prose = await runPageDetector(rules, { html: '<p>A tutorial about jQuery.</p>' })
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
assert.ok(!prose.some(technology => technology.name === 'jQuery'))
const runtime = await runPageDetector(rules, { globals: ['jQuery'] })
assert.ok(runtime.some(technology => technology.name === 'jQuery'))
const resource = await runPageDetector(rules, { resources: ['https://example.com/jquery-3.7.1.min.js'] })
assert.equal(resource.find(technology => technology.name === 'jQuery').version, '3.7.1')
})

test('dynamic snapshots reject jQuery in titles while retaining script resource detection', async () => {
const source = await readFile(new URL('../src/background/dynamic-snapshot.ts', import.meta.url), 'utf8')
const compiled = await build({
stdin: {
contents: `${source.replaceAll('export const ', 'const ')}\nexport { detectFromDynamicSnapshot };`,
loader: 'ts',
resolveDir: path.join(repoRoot, 'src/background')
},
bundle: true,
write: false,
format: 'esm',
platform: 'node',
plugins: [
{
name: 'exclude-extension-io',
setup(build) {
// The exported pure matcher does not need tab storage, timers or extension orchestration.
build.onResolve({ filter: /^\.\/(tab-store|detection|detector-settings|bundle-license|tab-write-lock)$/ }, args => ({
path: args.path,
external: true,
sideEffects: false
}))
}
}
]
})
const { detectFromDynamicSnapshot } = await import(
`data:text/javascript;base64,${Buffer.from(compiled.outputFiles[0].text).toString('base64')}`
)
const rules = loadPageRules(['page/frontend-frameworks.json', 'page/dynamic-technologies.json'])
const snapshot = {
url: 'https://example.com/',
title: 'A tutorial about jQuery.',
resources: [],
scripts: [],
stylesheets: [],
iframes: [],
feedLinks: [],
domMarkers: []
}
assert.ok(!detectFromDynamicSnapshot(snapshot, rules).some(technology => technology.name === 'jQuery'))
const positive = detectFromDynamicSnapshot({ ...snapshot, scripts: ['https://example.com/jquery-3.7.1.min.js'] }, rules)
assert.ok(positive.some(technology => technology.name === 'jQuery'))
})