Files
yoshiko 9e2643cfda Refactor dev startup logging and hide internal server output (#257)
* fix(dev): print shutdown review comments

* refactor(dev): only hide internal server url

* fix(dev): declare stdout proxy types

* fix(dev): hide internal port retry logs

* refactor(dev): hide nested script banners

* style(dev): use rocket banner for vite startup

* fix(dev): disable vite clear screen

* fix(dev): preserve repeated startup log lines

* fix(dev): keep ctrl-c during compile as clean exit

* refactor(dev): move pnpm dev helpers into dev dir

* rm dev message

* fix(hooks): run checks for scripts changes
2026-03-19 09:33:49 +09:00

81 lines
3.0 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { createCliStdoutProxy } from './dev-stdout.js';
describe('createCliStdoutProxy', () => {
it('detects the CLI server URL across chunks and hides only that line', () => {
const onServerUrl = vi.fn();
const output: string[] = [];
const proxy = createCliStdoutProxy({
onServerUrl,
onOutput: (text: string) => output.push(text),
});
proxy.push('\n🚀 difit server started on http://localhost:4966\n📋 Rev');
proxy.push('iewing: HEAD\n💡 Use --open to automatically open browser\n');
proxy.push('\n👋 Shutting down difit server...\n\n📝 Comments from review session:\n');
proxy.push('==================================================\n');
proxy.push('src/index.ts:L10\nFix this edge case\n');
proxy.push('==================================================\nTotal comments: 1\n');
proxy.flush();
expect(onServerUrl).toHaveBeenCalledWith('http://localhost:4966');
expect(output.join('')).toBe(
'📋 Reviewing: HEAD\n' +
'💡 Use --open to automatically open browser\n' +
'\n👋 Shutting down difit server...\n\n📝 Comments from review session:\n' +
'==================================================\n' +
'src/index.ts:L10\nFix this edge case\n' +
'==================================================\n' +
'Total comments: 1\n',
);
});
it('drops the leading blank line that only belongs to the hidden server URL', () => {
const output: string[] = [];
const proxy = createCliStdoutProxy({
onServerUrl: vi.fn(),
onOutput: (text: string) => output.push(text),
});
proxy.push('\n🚀 difit server started on http://localhost:4966\n📋 Reviewing: HEAD\n');
proxy.flush();
expect(output).toEqual(['📋 Reviewing: HEAD\n']);
});
it('hides internal port retry logs before the server URL is known', () => {
const onServerUrl = vi.fn();
const output: string[] = [];
const proxy = createCliStdoutProxy({
onServerUrl,
onOutput: (text: string) => output.push(text),
});
proxy.push('Port 4966 is busy, trying 4967...\n');
proxy.push('\n🚀 difit server started on http://localhost:4967\n📋 Reviewing: HEAD\n');
proxy.flush();
expect(onServerUrl).toHaveBeenCalledWith('http://localhost:4967');
expect(output).toEqual(['📋 Reviewing: HEAD\n']);
});
it('preserves later lines that repeat the startup message', () => {
const output: string[] = [];
const proxy = createCliStdoutProxy({
onServerUrl: vi.fn(),
onOutput: (text: string) => output.push(text),
});
proxy.push('\n🚀 difit server started on http://localhost:4966\n');
proxy.push('📝 Comments from review session:\n');
proxy.push('🚀 difit server started on http://localhost:4966\n');
proxy.flush();
expect(output).toEqual([
'📝 Comments from review session:\n',
'🚀 difit server started on http://localhost:4966\n',
]);
});
});