d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
146 lines
4.8 KiB
JavaScript
146 lines
4.8 KiB
JavaScript
/**
|
|
* Tests for scripts/hooks/auto-tmux-dev.js
|
|
*
|
|
* Tests dev server command transformation for tmux wrapping.
|
|
*
|
|
* Run with: node tests/hooks/auto-tmux-dev.test.js
|
|
*/
|
|
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const { spawnSync } = require('child_process');
|
|
|
|
const script = path.join(__dirname, '..', '..', 'scripts', 'hooks', 'auto-tmux-dev.js');
|
|
|
|
function test(name, fn) {
|
|
try {
|
|
fn();
|
|
console.log(` \u2713 ${name}`);
|
|
return true;
|
|
} catch (err) {
|
|
console.log(` \u2717 ${name}`);
|
|
console.log(` Error: ${err.message}`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function runScript(input) {
|
|
const result = spawnSync('node', [script], {
|
|
encoding: 'utf8',
|
|
input: typeof input === 'string' ? input : JSON.stringify(input),
|
|
timeout: 10000,
|
|
});
|
|
return {
|
|
code: result.status || 0,
|
|
stdout: result.stdout || '',
|
|
stderr: result.stderr || '',
|
|
};
|
|
}
|
|
|
|
function runTests() {
|
|
console.log('\n=== Testing auto-tmux-dev.js ===\n');
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
// Check if tmux is available for conditional tests
|
|
const tmuxAvailable = spawnSync('which', ['tmux'], { encoding: 'utf8' }).status === 0;
|
|
|
|
console.log('Dev server detection:');
|
|
|
|
if (test('transforms npm run dev command', () => {
|
|
const result = runScript({ tool_input: { command: 'npm run dev' } });
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
if (process.platform !== 'win32' && tmuxAvailable) {
|
|
assert.ok(output.tool_input.command.includes('tmux'), 'Should contain tmux');
|
|
assert.ok(output.tool_input.command.includes('npm run dev'), 'Should contain original command');
|
|
}
|
|
})) passed++; else failed++;
|
|
|
|
if (test('transforms pnpm dev command', () => {
|
|
const result = runScript({ tool_input: { command: 'pnpm dev' } });
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
if (process.platform !== 'win32' && tmuxAvailable) {
|
|
assert.ok(output.tool_input.command.includes('tmux'));
|
|
}
|
|
})) passed++; else failed++;
|
|
|
|
if (test('transforms yarn dev command', () => {
|
|
const result = runScript({ tool_input: { command: 'yarn dev' } });
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
if (process.platform !== 'win32' && tmuxAvailable) {
|
|
assert.ok(output.tool_input.command.includes('tmux'));
|
|
}
|
|
})) passed++; else failed++;
|
|
|
|
if (test('transforms bun run dev command', () => {
|
|
const result = runScript({ tool_input: { command: 'bun run dev' } });
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
if (process.platform !== 'win32' && tmuxAvailable) {
|
|
assert.ok(output.tool_input.command.includes('tmux'));
|
|
}
|
|
})) passed++; else failed++;
|
|
|
|
console.log('\nNon-dev commands (pass-through):');
|
|
|
|
if (test('does not transform npm install', () => {
|
|
const input = { tool_input: { command: 'npm install' } };
|
|
const result = runScript(input);
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
assert.strictEqual(output.tool_input.command, 'npm install');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('does not transform npm test', () => {
|
|
const input = { tool_input: { command: 'npm test' } };
|
|
const result = runScript(input);
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
assert.strictEqual(output.tool_input.command, 'npm test');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('does not transform npm run build', () => {
|
|
const input = { tool_input: { command: 'npm run build' } };
|
|
const result = runScript(input);
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
assert.strictEqual(output.tool_input.command, 'npm run build');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('does not transform npm run develop (partial match)', () => {
|
|
const input = { tool_input: { command: 'npm run develop' } };
|
|
const result = runScript(input);
|
|
assert.strictEqual(result.code, 0);
|
|
const output = JSON.parse(result.stdout);
|
|
assert.strictEqual(output.tool_input.command, 'npm run develop');
|
|
})) passed++; else failed++;
|
|
|
|
console.log('\nEdge cases:');
|
|
|
|
if (test('handles empty input gracefully', () => {
|
|
const result = runScript('{}');
|
|
assert.strictEqual(result.code, 0);
|
|
})) passed++; else failed++;
|
|
|
|
if (test('handles invalid JSON gracefully', () => {
|
|
const result = runScript('not json');
|
|
assert.strictEqual(result.code, 0);
|
|
assert.strictEqual(result.stdout, 'not json');
|
|
})) passed++; else failed++;
|
|
|
|
if (test('passes through missing command field', () => {
|
|
const input = { tool_input: {} };
|
|
const result = runScript(input);
|
|
assert.strictEqual(result.code, 0);
|
|
})) passed++; else failed++;
|
|
|
|
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
|
process.exit(failed > 0 ? 1 : 0);
|
|
}
|
|
|
|
runTests();
|