summaryrefslogtreecommitdiff
path: root/apps/web/scripts/test-excessive-projects.ts
blob: a8451ddd057eaddcd16ab95237988f651af5a7c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env bun

/**
 * CLI Test Runner: Excessive Project Creation Bug
 * 
 * This script runs comprehensive tests to validate the excessive project creation bug
 * and can be executed from the command line like `cargo test`.
 * 
 * Usage:
 *   bun run scripts/test-excessive-projects.ts
 *   bun run test:excessive-projects
 */

import { spawn } from 'child_process'
import { existsSync } from 'fs'
import path from 'path'

interface TestResult {
  name: string
  passed: boolean
  duration: number
  error?: string
}

class ExcessiveProjectsTestRunner {
  private results: TestResult[] = []
  private startTime: number = 0

  constructor() {
    console.log('๐Ÿงช Excessive Project Creation Bug - Test Runner')
    console.log('=' .repeat(60))
  }

  async runAllTests(): Promise<void> {
    this.startTime = Date.now()

    try {
      // Check if test files exist
      await this.validateTestEnvironment()

      // Run unit tests
      await this.runUnitTests()

      // Run integration tests  
      await this.runIntegrationTests()

      // Run specific excessive projects tests
      await this.runExcessiveProjectsTests()

      // Generate report
      this.generateReport()

    } catch (error) {
      console.error('โŒ Test runner failed:', error)
      process.exit(1)
    }
  }

  private async validateTestEnvironment(): Promise<void> {
    console.log('๐Ÿ” Validating test environment...')

    const requiredFiles = [
      'src/__tests__/setup.ts',
      'src/__tests__/excessive-projects.test.ts',
      'src/__tests__/editor-page-integration.test.tsx',
      'vitest.config.ts'
    ]

    for (const file of requiredFiles) {
      if (!existsSync(path.join(process.cwd(), file))) {
        throw new Error(`Required test file not found: ${file}`)
      }
    }

    console.log('โœ… Test environment validated')
  }

  private async runUnitTests(): Promise<void> {
    console.log('\n๐Ÿ“‹ Running Unit Tests...')
    
    const result = await this.runVitest([
      'src/__tests__/excessive-projects.test.ts',
      '--reporter=verbose'
    ])

    this.results.push({
      name: 'Unit Tests - Excessive Projects Logic',
      passed: result.success,
      duration: result.duration,
      error: result.error
    })
  }

  private async runIntegrationTests(): Promise<void> {
    console.log('\n๐Ÿ”— Running Integration Tests...')
    
    const result = await this.runVitest([
      'src/__tests__/editor-page-integration.test.tsx',
      '--reporter=verbose'
    ])

    this.results.push({
      name: 'Integration Tests - Editor Page Component',
      passed: result.success,
      duration: result.duration,
      error: result.error
    })
  }

  private async runExcessiveProjectsTests(): Promise<void> {
    console.log('\n๐Ÿšจ Running Excessive Projects Bug Tests...')
    
    const result = await this.runVitest([
      'src/__tests__/excessive-projects.test.ts',
      'src/__tests__/editor-page-integration.test.tsx',
      '--reporter=verbose',
      '--run'
    ])

    this.results.push({
      name: 'Bug Reproduction Tests - All Scenarios',
      passed: result.success,
      duration: result.duration,
      error: result.error
    })
  }

  private async runVitest(args: string[]): Promise<{ success: boolean; duration: number; error?: string }> {
    const startTime = Date.now()

    return new Promise((resolve) => {
      const vitestProcess = spawn('bunx', ['vitest', ...args], {
        stdio: 'inherit',
        cwd: process.cwd()
      })

      vitestProcess.on('close', (code) => {
        const duration = Date.now() - startTime
        resolve({
          success: code === 0,
          duration,
          error: code !== 0 ? `Process exited with code ${code}` : undefined
        })
      })

      vitestProcess.on('error', (error) => {
        const duration = Date.now() - startTime
        resolve({
          success: false,
          duration,
          error: error.message
        })
      })
    })
  }

  private generateReport(): void {
    const totalDuration = Date.now() - this.startTime
    const passedTests = this.results.filter(r => r.passed).length
    const totalTests = this.results.length

    console.log('\n' + '='.repeat(60))
    console.log('๐Ÿ“Š TEST RESULTS SUMMARY')
    console.log('='.repeat(60))

    this.results.forEach((result, index) => {
      const status = result.passed ? 'โœ… PASS' : 'โŒ FAIL'
      const duration = `${result.duration}ms`
      
      console.log(`${index + 1}. ${status} ${result.name} (${duration})`)
      
      if (result.error) {
        console.log(`   Error: ${result.error}`)
      }
    })

    console.log('\n' + '-'.repeat(60))
    console.log(`๐Ÿ“ˆ Overall: ${passedTests}/${totalTests} tests passed`)
    console.log(`โฑ๏ธ  Total duration: ${totalDuration}ms`)

    if (passedTests === totalTests) {
      console.log('๐ŸŽ‰ All tests passed! Bug reproduction confirmed.')
    } else {
      console.log('โš ๏ธ  Some tests failed. Check the output above.')
      process.exit(1)
    }

    console.log('\n๐Ÿ’ก To run individual test suites:')
    console.log('   bun run test src/__tests__/excessive-projects.test.ts')
    console.log('   bun run test src/__tests__/editor-page-integration.test.tsx')
    console.log('\n๐Ÿ”ง To run with coverage:')
    console.log('   bun run test:coverage')
  }
}

// CLI execution
if (import.meta.main) {
  const runner = new ExcessiveProjectsTestRunner()
  runner.runAllTests().catch((error) => {
    console.error('Fatal error:', error)
    process.exit(1)
  })
}

export { ExcessiveProjectsTestRunner }