From 85a86f67471d1a3cc42ef97bfa680d5a9c1c7ddc Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 13 Feb 2026 06:49:29 -0800 Subject: [PATCH] test: add --global success, bare PM name, and source label tests (Round 62) - setup-package-manager.test.js: --global npm writes config and exits 0 - setup-package-manager.test.js: bare PM name sets global preference - setup-package-manager.test.js: --detect with env var shows source 'environment' 791 tests total, all passing. --- tests/scripts/setup-package-manager.test.js | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/scripts/setup-package-manager.test.js b/tests/scripts/setup-package-manager.test.js index 48a1953b..25861d21 100644 --- a/tests/scripts/setup-package-manager.test.js +++ b/tests/scripts/setup-package-manager.test.js @@ -8,6 +8,8 @@ const assert = require('assert'); const path = require('path'); +const fs = require('fs'); +const os = require('os'); const { execFileSync } = require('child_process'); const SCRIPT = path.join(__dirname, '..', '..', 'scripts', 'setup-package-manager.js'); @@ -256,6 +258,54 @@ function runTests() { assert.strictEqual(installCount, 4, `Expected 4 "Install:" entries, found ${installCount}`); })) passed++; else failed++; + // ── Round 62: --global success path and bare PM name ── + console.log('\n--global success path (Round 62):'); + + if (test('--global npm writes config and succeeds', () => { + const tmpDir = path.join(os.tmpdir(), `spm-test-global-${Date.now()}`); + fs.mkdirSync(tmpDir, { recursive: true }); + try { + const result = run(['--global', 'npm'], { HOME: tmpDir, USERPROFILE: tmpDir }); + assert.strictEqual(result.code, 0, `Expected exit 0, got ${result.code}. stderr: ${result.stderr}`); + assert.ok(result.stdout.includes('Global preference set to'), 'Should show success message'); + assert.ok(result.stdout.includes('npm'), 'Should mention npm'); + // Verify config file was created + const configPath = path.join(tmpDir, '.claude', 'package-manager.json'); + assert.ok(fs.existsSync(configPath), 'Config file should be created'); + const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); + assert.strictEqual(config.packageManager, 'npm', 'Config should contain npm'); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + })) passed++; else failed++; + + console.log('\nbare PM name success (Round 62):'); + + if (test('bare npm sets global preference and succeeds', () => { + const tmpDir = path.join(os.tmpdir(), `spm-test-bare-${Date.now()}`); + fs.mkdirSync(tmpDir, { recursive: true }); + try { + const result = run(['npm'], { HOME: tmpDir, USERPROFILE: tmpDir }); + assert.strictEqual(result.code, 0, `Expected exit 0, got ${result.code}. stderr: ${result.stderr}`); + assert.ok(result.stdout.includes('Global preference set to'), 'Should show success message'); + // Verify config file was created + const configPath = path.join(tmpDir, '.claude', 'package-manager.json'); + assert.ok(fs.existsSync(configPath), 'Config file should be created'); + const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); + assert.strictEqual(config.packageManager, 'npm', 'Config should contain npm'); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + })) passed++; else failed++; + + console.log('\n--detect source label (Round 62):'); + + if (test('--detect with env var shows source as environment', () => { + const result = run(['--detect'], { CLAUDE_PACKAGE_MANAGER: 'pnpm' }); + assert.strictEqual(result.code, 0); + assert.ok(result.stdout.includes('Source: environment'), 'Should show environment as source'); + })) passed++; else failed++; + // Summary console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`); process.exit(failed > 0 ? 1 : 0);