-
Notifications
You must be signed in to change notification settings - Fork 375
refactor: Improve litegraph preprocessing for i18n collection #5297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 40 commits
5bc5050
c183026
61f9628
83de398
4c2715e
29add8f
ea917ba
4e56bae
2403b47
0a3f878
3700457
f037567
2a611cb
adbfd59
32b8a1e
457cbbd
4bd68c8
e4bc294
c7e9f83
728828e
09ec3ad
8afd007
33dd251
bbb6396
4aec5fe
be87bd0
595b5f0
c393c48
b1c6622
1869484
450f156
ad111f0
98318c8
a79d87d
4984e96
08d4c07
9d7eac2
85b51b1
9ac1a0a
f4d2185
6ef3650
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { FullConfig } from '@playwright/test' | ||
|
||
import { preprocessLitegraph } from './i18nSetup' | ||
|
||
export default async function globalSetup(config: FullConfig) { | ||
await preprocessLitegraph() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { FullConfig } from '@playwright/test' | ||
|
||
import { restoreLitegraph } from './i18nSetup' | ||
|
||
export default async function globalTeardown(config: FullConfig) { | ||
await restoreLitegraph() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Setup for i18n collection tests | ||
* Handles preprocessing of litegraph files that contain TypeScript 'declare' keywords | ||
*/ | ||
import { promises as fs } from 'fs' | ||
import { glob } from 'glob' | ||
import * as path from 'path' | ||
import { fileURLToPath } from 'url' | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
const rootDir = path.resolve(__dirname, '..') | ||
const litegraphSrcDir = path.join(rootDir, 'src/lib/litegraph/src') | ||
|
||
const backupMap = new Map<string, string>() | ||
|
||
export async function preprocessLitegraph() { | ||
console.log('Preprocessing litegraph files for i18n collection...') | ||
|
||
// Search for all .ts files in litegraph src directory | ||
const pattern = path.join(litegraphSrcDir, '**/*.ts') | ||
const files = await glob(pattern, { | ||
ignore: ['**/*.test.ts', '**/*.spec.ts', '**/node_modules/**'] | ||
}) | ||
|
||
let processedCount = 0 | ||
|
||
// Process files in parallel - read once and process if needed | ||
await Promise.all( | ||
files.map(async (filePath) => { | ||
try { | ||
const originalContent = await fs.readFile(filePath, 'utf-8') | ||
|
||
// Check for class property declarations with 'declare' keyword | ||
if (!/^\s*declare\s+/m.test(originalContent)) { | ||
return // Skip files without declare keywords | ||
} | ||
|
||
// Store original content in memory | ||
backupMap.set(filePath, originalContent) | ||
|
||
// Remove 'declare' keyword from class properties | ||
const modifiedContent = originalContent.replace( | ||
/^(\s*)declare\s+/gm, | ||
'$1// @ts-ignore - removed declare for Playwright\n$1' | ||
) | ||
|
||
// Write modified content | ||
await fs.writeFile(filePath, modifiedContent) | ||
console.log(` ✓ Processed ${path.relative(litegraphSrcDir, filePath)}`) | ||
processedCount++ | ||
} catch (error: unknown) { | ||
console.warn( | ||
` ⚠ Could not preprocess file for litegraph ${filePath}: ${String((error as Error)?.message || error)}` | ||
) | ||
} | ||
}) | ||
) | ||
|
||
if (processedCount === 0) { | ||
console.log(' ℹ No files with declare keywords found') | ||
} else { | ||
console.log(` Processed ${processedCount} files with declare keywords`) | ||
} | ||
} | ||
|
||
export async function restoreLitegraph() { | ||
if (backupMap.size === 0) { | ||
return | ||
} | ||
|
||
console.log('Restoring original litegraph files...') | ||
|
||
await Promise.all( | ||
Array.from(backupMap.entries()).map(async ([filePath, originalContent]) => { | ||
await fs.writeFile(filePath, originalContent) | ||
console.log(` ✓ Restored ${path.relative(litegraphSrcDir, filePath)}`) | ||
}) | ||
) | ||
|
||
backupMap.clear() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,11 @@ export default defineConfig({ | |
}, | ||
reporter: 'list', | ||
timeout: 60000, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we are here, should we increase the timeout as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as for timeout, is 1 min not enough? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I never got timeout error for i18n yet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The concept of a test timetout just doesn't apply to this, because we are not using it as a test. So we would want to give it a lot of time. It's fine I guess. |
||
testMatch: /collect-i18n-.*\.ts/ | ||
testMatch: /collect-i18n-.*\.ts/, | ||
// Run tests sequentially to avoid conflicts | ||
workers: 1, | ||
fullyParallel: false, | ||
// Use combined setup that includes litegraph preprocessing | ||
globalSetup: './browser_tests/globalSetupWithI18n.ts', | ||
globalTeardown: './browser_tests/globalTeardownWithI18n.ts' | ||
}) |
Uh oh!
There was an error while loading. Please reload this page.