fix: preserve non-page fixtures when rewriting async destructuring

Addresses review feedback:
https://github.com/Comfy-Org/ComfyUI_frontend/pull/10694#pullrequestreview-2856476290
This commit is contained in:
bymyself
2026-04-09 23:00:12 -07:00
parent 7418ce454a
commit 64f3dfcc9b
2 changed files with 23 additions and 3 deletions

View File

@@ -52,6 +52,18 @@ describe('transformRules', () => {
expect(result).toContain('async ({ comfyPage })')
expect(result).not.toContain('{ page }')
})
it('preserves non-page fixtures when rewriting', () => {
const input = `test('my test', async ({ page, context }) => {`
const result = applyRule('replace-page-destructure', input)
expect(result).toContain('async ({ comfyPage, context })')
})
it('preserves multiple non-page fixtures', () => {
const input = `test('my test', async ({ page, context, browser }) => {`
const result = applyRule('replace-page-destructure', input)
expect(result).toContain('async ({ comfyPage, context, browser })')
})
})
describe('locator transforms', () => {

View File

@@ -34,9 +34,17 @@ export const transformRules: TransformRule[] = [
// === Fixture transforms ===
{
name: 'replace-page-destructure',
description: 'Use comfyPage fixture instead of page',
pattern: /async\s*\(\s*\{\s*page\s*(?:,\s*\w+\s*)*\}\s*\)/g,
replacement: 'async ({ comfyPage })',
description:
'Use comfyPage fixture instead of page, preserving other fixtures',
pattern: /async\s*\(\s*\{\s*([^}]*\bpage\b[^}]*)\}\s*\)/g,
replacement: (_match: string, fixtures: string) => {
const mapped = fixtures
.split(',')
.map((f) => f.trim())
.filter(Boolean)
.map((f) => (f === 'page' ? 'comfyPage' : f))
return `async ({ ${mapped.join(', ')} })`
},
category: 'fixture'
},