|
| 1 | +import { describe, it, expect, beforeAll } from 'vitest' |
| 2 | +import { readFileSync, existsSync } from 'fs' |
| 3 | +import { resolve } from 'path' |
| 4 | +import { execSync } from 'child_process' |
| 5 | + |
| 6 | +describe('Production Build Checks', () => { |
| 7 | + let panelContent: string |
| 8 | + |
| 9 | + beforeAll(() => { |
| 10 | + // Build the production panel if it doesn't exist |
| 11 | + const panelPath = resolve(__dirname, '../../dist/panel.js') |
| 12 | + if (!existsSync(panelPath)) { |
| 13 | + console.log('Building production panel...') |
| 14 | + execSync('npm run build:ha:prod', { |
| 15 | + cwd: resolve(__dirname, '../..'), |
| 16 | + stdio: 'inherit', |
| 17 | + }) |
| 18 | + } |
| 19 | + |
| 20 | + // Read the built panel.js |
| 21 | + panelContent = readFileSync(panelPath, 'utf-8') |
| 22 | + }) |
| 23 | + |
| 24 | + it('should not contain alert() calls in production build', () => { |
| 25 | + // Check for any alert() calls |
| 26 | + const alertPattern = /alert\s*\(/g |
| 27 | + const matches = panelContent.match(alertPattern) |
| 28 | + |
| 29 | + if (matches) { |
| 30 | + // Find context around each alert |
| 31 | + matches.forEach((match) => { |
| 32 | + const index = panelContent.indexOf(match) |
| 33 | + const context = panelContent.substring( |
| 34 | + Math.max(0, index - 100), |
| 35 | + Math.min(panelContent.length, index + 100) |
| 36 | + ) |
| 37 | + console.error(`Found alert() at index ${index}:`, context) |
| 38 | + }) |
| 39 | + } |
| 40 | + |
| 41 | + expect(matches).toBeNull() |
| 42 | + }) |
| 43 | + |
| 44 | + it('should not contain alert(0) specifically', () => { |
| 45 | + // Check specifically for alert(0) |
| 46 | + const alert0Pattern = /alert\s*\(\s*0\s*\)/g |
| 47 | + const matches = panelContent.match(alert0Pattern) |
| 48 | + |
| 49 | + expect(matches).toBeNull() |
| 50 | + }) |
| 51 | + |
| 52 | + it.todo('should exclude test routes from production build', () => { |
| 53 | + // TODO: Test routes should be excluded from production builds |
| 54 | + // This test is disabled until we implement proper route filtering |
| 55 | + const testConsolePattern = /console\.log\s*\(\s*['"]Configuration exported/g |
| 56 | + const matches = panelContent.match(testConsolePattern) |
| 57 | + |
| 58 | + expect(matches).toBeNull() |
| 59 | + }) |
| 60 | + |
| 61 | + it('should not contain debugger statements', () => { |
| 62 | + const debuggerPattern = /\bdebugger\b/g |
| 63 | + const matches = panelContent.match(debuggerPattern) |
| 64 | + |
| 65 | + expect(matches).toBeNull() |
| 66 | + }) |
| 67 | +}) |
0 commit comments