From 5031a84d6e28a28e9d46c5d90423913352c3f5c1 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 13 Feb 2026 07:23:16 -0800 Subject: [PATCH] test: add 3 tests for setup-pm --project success, demo export, --list marker (Round 68) --- tests/scripts/setup-package-manager.test.js | 38 +++++++++++++++++++++ tests/scripts/skill-create-output.test.js | 11 ++++++ 2 files changed, 49 insertions(+) diff --git a/tests/scripts/setup-package-manager.test.js b/tests/scripts/setup-package-manager.test.js index 25861d21..ca0b6fa5 100644 --- a/tests/scripts/setup-package-manager.test.js +++ b/tests/scripts/setup-package-manager.test.js @@ -306,6 +306,44 @@ function runTests() { assert.ok(result.stdout.includes('Source: environment'), 'Should show environment as source'); })) passed++; else failed++; + // ── Round 68: --project success path and --list (current) marker ── + console.log('\n--project success path (Round 68):'); + + if (test('--project npm writes project config and succeeds', () => { + const tmpDir = path.join(os.tmpdir(), `spm-test-project-${Date.now()}`); + fs.mkdirSync(tmpDir, { recursive: true }); + try { + const result = require('child_process').spawnSync('node', [SCRIPT, '--project', 'npm'], { + encoding: 'utf8', + stdio: ['pipe', 'pipe', 'pipe'], + env: { ...process.env }, + timeout: 10000, + cwd: tmpDir + }); + assert.strictEqual(result.status, 0, `Expected exit 0, got ${result.status}. stderr: ${result.stderr}`); + assert.ok(result.stdout.includes('Project preference set to'), 'Should show project success message'); + assert.ok(result.stdout.includes('npm'), 'Should mention npm'); + // Verify config file was created in the project CWD + const configPath = path.join(tmpDir, '.claude', 'package-manager.json'); + assert.ok(fs.existsSync(configPath), 'Project config file should be created in CWD'); + 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--list (current) marker (Round 68):'); + + if (test('--list output includes (current) marker for active PM', () => { + const result = run(['--list']); + assert.strictEqual(result.code, 0); + assert.ok(result.stdout.includes('(current)'), '--list should mark the active PM with (current)'); + // The (current) marker should appear exactly once + const currentCount = (result.stdout.match(/\(current\)/g) || []).length; + assert.strictEqual(currentCount, 1, `Expected exactly 1 "(current)" in --list, found ${currentCount}`); + })) passed++; else failed++; + // Summary console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`); process.exit(failed > 0 ? 1 : 0); diff --git a/tests/scripts/skill-create-output.test.js b/tests/scripts/skill-create-output.test.js index 2f2ff42f..e2895679 100644 --- a/tests/scripts/skill-create-output.test.js +++ b/tests/scripts/skill-create-output.test.js @@ -470,6 +470,17 @@ function runTests() { assert.ok(boxLines.length >= 3, 'Should render a complete box'); })) passed++; else failed++; + // ── Round 68: demo function export ── + console.log('\ndemo export (Round 68):'); + + if (test('module exports demo function alongside SkillCreateOutput', () => { + const mod = require('../../scripts/skill-create-output'); + assert.ok(mod.demo, 'Should export demo function'); + assert.strictEqual(typeof mod.demo, 'function', 'demo should be a function'); + assert.ok(mod.SkillCreateOutput, 'Should also export SkillCreateOutput'); + assert.strictEqual(typeof mod.SkillCreateOutput, 'function', 'SkillCreateOutput should be a constructor'); + })) passed++; else failed++; + // Summary console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`); process.exit(failed > 0 ? 1 : 0);