|
| 1 | +import { test, expect, describe, jest, beforeAll } from '@jest/globals'; |
| 2 | +import fs from 'node:fs'; |
| 3 | +import path from 'node:path'; |
| 4 | +import { fileURLToPath } from 'node:url'; |
| 5 | + |
| 6 | +const __filename = fileURLToPath(import.meta.url); |
| 7 | +const __dirname = path.dirname(__filename); |
| 8 | +const rootDir = path.resolve(__dirname, '..'); |
| 9 | +const processEvents: Record<string, Array<() => void>> = { |
| 10 | + 'SIGINT': [], |
| 11 | + 'SIGTERM': [] |
| 12 | +}; |
| 13 | + |
| 14 | +let cleanupFn: boolean | undefined; |
| 15 | + |
| 16 | +beforeAll(() => { |
| 17 | + const executorPath = path.join(rootDir, 'src/executor.ts'); |
| 18 | + const executorContent = fs.readFileSync(executorPath, 'utf8'); |
| 19 | + if (executorContent.includes('process.on(\'SIGINT\'')) { |
| 20 | + processEvents['SIGINT'] = [() => {}]; |
| 21 | + } |
| 22 | + |
| 23 | + if (executorContent.includes('process.on(\'SIGTERM\'')) { |
| 24 | + processEvents['SIGTERM'] = [() => {}]; |
| 25 | + } |
| 26 | + |
| 27 | + if (executorContent.includes('cleanupBrowser')) { |
| 28 | + cleanupFn = true; |
| 29 | + } |
| 30 | +}); |
| 31 | + |
| 32 | +describe('Browser Error Handling Tests', () => { |
| 33 | + test('Executor should contain process cleanup handlers', async () => { |
| 34 | + const executorPath = path.join(rootDir, 'src/executor.ts'); |
| 35 | + const executorContent = fs.readFileSync(executorPath, 'utf8'); |
| 36 | + expect(executorContent.includes('process.on(\'SIGINT\'')).toBeTruthy(); |
| 37 | + expect(executorContent.includes('process.on(\'SIGTERM\'')).toBeTruthy(); |
| 38 | + expect(executorContent.includes('cleanupBrowser')).toBeTruthy(); |
| 39 | + }); |
| 40 | + |
| 41 | + test('README should contain browser process cleanup documentation', () => { |
| 42 | + const readmePath = path.join(rootDir, 'README.md'); |
| 43 | + const readmeContent = fs.readFileSync(readmePath, 'utf8'); |
| 44 | + expect(readmeContent).toContain('Browser process not closing properly'); |
| 45 | + expect(readmeContent).toContain('Windows'); |
| 46 | + expect(readmeContent).toContain('macOS'); |
| 47 | + expect(readmeContent).toContain('Linux'); |
| 48 | + expect(readmeContent).toContain('Playwright'); |
| 49 | + expect(readmeContent).toContain('issues'); |
| 50 | + expect(readmeContent).toContain('github.com/microsoft/playwright/issues'); |
| 51 | + }); |
| 52 | +}); |
0 commit comments