File size: 4,809 Bytes
9284ad7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env node

/**
 * Local Testing Script
 * Validates TypeScript compilation and runs tests without requiring GitHub webhooks/PRs
 *
 * Usage:
 *   npm run test:local           - Run all tests
 *   npm run test:local:patch    - Test patch-utils only
 *   npm run test:local:review   - Test review integration only
 *   npm run test:local:unit      - Run unit tests only
 *   npm run test:local:coverage - Run with coverage
 */

const { spawn } = require('child_process');
const path = require('path');

const args = process.argv.slice(2);
const testArg = args[0] || 'all';

const testCommands = {
  all: ['npm', ['run', 'build', '&&', 'npm', 'run', 'test', '--', '--passWithNoTests'], { shell: true }],
  patch: ['npm', ['run', 'test', '--', '--testPathPattern', 'patch-utils', '--verbose']],
  review: ['npm', ['run', 'test', '--', '--testPathPattern', 'review.integration', '--verbose']],
  unit: ['npm', ['run', 'test', '--', '--testPathIgnorePatterns', 'integration', '--verbose']],
  coverage: ['npm', ['run', 'test', '--', '--coverage', '--coverageReporters', ['text', 'lcov', 'html']],
  watch: ['npm', ['run', 'test', '--', '--watch', '--testPathPattern', 'patch-utils']],
};

function runCommand(cmd, args, options = {}) {
  return new Promise((resolve, reject) => {
    console.log(`\nπŸ”§ Running: ${cmd} ${args.join(' ')}\n`);

    const child = spawn(cmd, args, {
      stdio: 'inherit',
      cwd: path.resolve(__dirname, '..'),
      ...options,
    });

    child.on('exit', (code) => {
      if (code === 0) {
        console.log(`\nβœ… Command succeeded: ${cmd} ${args.join(' ')}`);
        resolve(code);
      } else {
        console.error(`\n❌ Command failed with code ${code}`);
        reject(code);
      }
    });

    child.on('error', (err) => {
      console.error(`\n❌ Command error: ${err.message}`);
      reject(err);
    });
  });
}

async function main() {
  console.log('╔════════════════════════════════════════════════════════════╗');
  console.log('β•‘          PRIX Local Testing System                         β•‘');
  console.log('β•‘  Test your changes without raising PRs!                   β•‘');
  console.log('β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•\n');

  const testTypes = {
    all: 'Run all tests (build + unit + integration)',
    patch: 'Run patch-utils tests only',
    review: 'Run review integration tests only',
    unit: 'Run unit tests only (exclude integration)',
    coverage: 'Run all tests with coverage report',
    watch: 'Watch mode for patch-utils',
  };

  if (testArg === 'help' || testArg === '--help') {
    console.log('Usage: npm run test:local [test-type]\n');
    console.log('Available test types:\n');
    Object.entries(testTypes).forEach(([key, desc]) => {
      console.log(`  ${key.padEnd(12)} - ${desc}`);
    });
    console.log('\nExamples:');
    console.log('  npm run test:local           # Run all tests');
    console.log('  npm run test:local patch     # Test patch-utils only');
    console.log('  npm run test:local coverage  # Run with coverage');
    process.exit(0);
  }

  const selectedTest = testCommands[testArg];
  if (!selectedTest) {
    console.error(`❌ Unknown test type: ${testArg}`);
    console.error('Run "npm run test:local help" for available options.');
    process.exit(1);
  }

  try {
    await runCommand(selectedTest[0], selectedTest[1], selectedTest[2] || {});
    console.log('\n╔════════════════════════════════════════════════════════════╗');
    console.log('β•‘                    TESTS PASSED                          β•‘');
    console.log('β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•\n');
  } catch (code) {
    console.log('\n╔════════════════════════════════════════════════════════════╗');
    console.log('β•‘                    TESTS FAILED                          β•‘');
    console.log('β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•\n');
    process.exit(code || 1);
  }
}

main().catch((err) => {
  console.error('Fatal error:', err);
  process.exit(1);
});