()
| 47 | } |
| 48 | |
| 49 | function runTests() { |
| 50 | console.log('\n=== Testing setup-package-manager.js ===\n'); |
| 51 | |
| 52 | let passed = 0; |
| 53 | let failed = 0; |
| 54 | |
| 55 | // --help flag |
| 56 | console.log('--help:'); |
| 57 | |
| 58 | if (test('shows help with --help flag', () => { |
| 59 | const result = run(['--help']); |
| 60 | assert.strictEqual(result.code, 0); |
| 61 | assert.ok(result.stdout.includes('Package Manager Setup')); |
| 62 | assert.ok(result.stdout.includes('--detect')); |
| 63 | assert.ok(result.stdout.includes('--global')); |
| 64 | assert.ok(result.stdout.includes('--project')); |
| 65 | })) passed++; else failed++; |
| 66 | |
| 67 | if (test('shows help with -h flag', () => { |
| 68 | const result = run(['-h']); |
| 69 | assert.strictEqual(result.code, 0); |
| 70 | assert.ok(result.stdout.includes('Package Manager Setup')); |
| 71 | })) passed++; else failed++; |
| 72 | |
| 73 | if (test('shows help with no arguments', () => { |
| 74 | const result = run([]); |
| 75 | assert.strictEqual(result.code, 0); |
| 76 | assert.ok(result.stdout.includes('Package Manager Setup')); |
| 77 | })) passed++; else failed++; |
| 78 | |
| 79 | // --detect flag |
| 80 | console.log('\n--detect:'); |
| 81 | |
| 82 | if (test('detects current package manager', () => { |
| 83 | const result = run(['--detect']); |
| 84 | assert.strictEqual(result.code, 0); |
| 85 | assert.ok(result.stdout.includes('Package Manager Detection')); |
| 86 | assert.ok(result.stdout.includes('Current selection')); |
| 87 | })) passed++; else failed++; |
| 88 | |
| 89 | if (test('shows detection sources', () => { |
| 90 | const result = run(['--detect']); |
| 91 | assert.ok(result.stdout.includes('From package.json')); |
| 92 | assert.ok(result.stdout.includes('From lock file')); |
| 93 | assert.ok(result.stdout.includes('Environment var')); |
| 94 | })) passed++; else failed++; |
| 95 | |
| 96 | if (test('shows available managers in detection output', () => { |
| 97 | const result = run(['--detect']); |
| 98 | assert.ok(result.stdout.includes('npm')); |
| 99 | assert.ok(result.stdout.includes('pnpm')); |
| 100 | assert.ok(result.stdout.includes('yarn')); |
| 101 | assert.ok(result.stdout.includes('bun')); |
| 102 | })) passed++; else failed++; |
| 103 | |
| 104 | // --list flag |
| 105 | console.log('\n--list:'); |
| 106 |
no test coverage detected