From 9ed91c197fba1ba253b8bd94bc7c21bc45583fa1 Mon Sep 17 00:00:00 2001 From: snomiao Date: Fri, 17 Oct 2025 00:55:15 +0000 Subject: [PATCH] [test] Improve shimFiles.test.ts to work with standard dist folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use standard `dist` folder instead of hardcoded `dist-treeshake-*` paths - Add fallback logic to check multiple dist directory candidates - Remove local-only comparison test between treeshake-enabled/disabled builds - Add helper test to verify dist directory is found This ensures tests work in CI/CD environments where only the standard `dist` folder exists, while still supporting local debugging builds. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- tests-ui/tests/shimFiles.test.ts | 81 ++++++++++---------------------- 1 file changed, 26 insertions(+), 55 deletions(-) diff --git a/tests-ui/tests/shimFiles.test.ts b/tests-ui/tests/shimFiles.test.ts index f5f0e9b0b..653d47ed5 100644 --- a/tests-ui/tests/shimFiles.test.ts +++ b/tests-ui/tests/shimFiles.test.ts @@ -9,13 +9,36 @@ import { describe, expect, it } from 'vitest' * These are static file tests that don't require the browser or ComfyUI backend to be running. */ -const DIST_DIR = path.join(__dirname, '../../dist-treeshake-enabled') -const SCRIPTS_DIR = path.join(DIST_DIR, 'scripts') +// Use standard dist folder (built by CI/CD and normal builds) +// Falls back to local debug builds if available +const findDistDir = (): string | null => { + const candidates = [ + path.join(__dirname, '../../dist'), + path.join(__dirname, '../../dist-treeshake-enabled'), + path.join(__dirname, '../../dist-treeshake-disabled') + ] + + for (const dir of candidates) { + if (fs.existsSync(dir) && fs.existsSync(path.join(dir, 'scripts'))) { + return dir + } + } + + return null +} + +const DIST_DIR = findDistDir() +const SCRIPTS_DIR = DIST_DIR ? path.join(DIST_DIR, 'scripts') : '' // Skip these tests if dist folder doesn't exist (e.g., during development before build) -const distExists = fs.existsSync(DIST_DIR) +const distExists = DIST_DIR !== null describe.skipIf(!distExists)('Shim Files Exports', () => { + it('should find a valid dist directory', () => { + expect(DIST_DIR).toBeTruthy() + expect(fs.existsSync(SCRIPTS_DIR)).toBe(true) + }) + describe('Core shim files should exist', () => { const coreShimFiles = [ 'api.js', @@ -223,56 +246,4 @@ describe.skipIf(!distExists)('Shim Files Exports', () => { }) }) }) - - describe('Compare with treeshake-disabled build', () => { - const treeshakeDisabledDir = path.join( - __dirname, - '../../dist-treeshake-disabled' - ) - const treeshakeDisabledScriptsDir = path.join( - treeshakeDisabledDir, - 'scripts' - ) - - if (fs.existsSync(treeshakeDisabledDir)) { - it('should have identical shim files between treeshake-enabled and treeshake-disabled builds', () => { - const getShimFiles = (dir: string): string[] => { - const files: string[] = [] - const walk = (currentDir: string, relativePath = '') => { - const entries = fs.readdirSync(currentDir, { withFileTypes: true }) - for (const entry of entries) { - const fullPath = path.join(currentDir, entry.name) - const relPath = path.join(relativePath, entry.name) - if (entry.isDirectory()) { - walk(fullPath, relPath) - } else if (entry.name.endsWith('.js')) { - files.push(relPath) - } - } - } - walk(dir) - return files.sort() - } - - const enabledShimFiles = getShimFiles(SCRIPTS_DIR) - const disabledShimFiles = getShimFiles(treeshakeDisabledScriptsDir) - - // Check that both builds have the same shim files - expect(enabledShimFiles).toEqual(disabledShimFiles) - - // Check that the content of each shim file is identical - for (const file of enabledShimFiles) { - const enabledContent = fs.readFileSync( - path.join(SCRIPTS_DIR, file), - 'utf-8' - ) - const disabledContent = fs.readFileSync( - path.join(treeshakeDisabledScriptsDir, file), - 'utf-8' - ) - expect(enabledContent).toBe(disabledContent) - } - }) - } - }) })