yamadashy--repomix
719032b19f
Update Schema / Update configuration json schema (push) Has been cancelled
Memory Benchmark / Memory Test (Full Analysis) (push) Has been cancelled
CI Quality / Lint GitHub Actions (actionlint) (push) Has been cancelled
CI Quality / Lint GitHub Actions (zizmor) (push) Has been cancelled
CI Quality / Check typos (push) Has been cancelled
CI / Test coverage (push) Has been cancelled
CI / Test (22.x, windows-latest) (push) Has been cancelled
CI / Test (24.x, macos-latest) (push) Has been cancelled
CI / Test (24.x, ubuntu-latest) (push) Has been cancelled
CI / Test (24.x, windows-latest) (push) Has been cancelled
CI / Test (26.x, macos-latest) (push) Has been cancelled
CI / Test (26.x, ubuntu-latest) (push) Has been cancelled
CI / Test (26.x, windows-latest) (push) Has been cancelled
CI / Test with Bun (latest, macos-latest) (push) Has been cancelled
CI / Test with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Test with Bun (latest, windows-latest) (push) Has been cancelled
CI / Build and run (22.x, macos-latest) (push) Has been cancelled
CI / Build and run (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (22.x, windows-latest) (push) Has been cancelled
autofix.ci / autofix (push) Has been cancelled
CI Browser Extension / Lint Browser Extension (push) Has been cancelled
CI Browser Extension / Test Browser Extension (push) Has been cancelled
Memory Benchmark / Memory Test (push) Has been cancelled
CI Website / Lint Website Client (push) Has been cancelled
CI Website / Lint Website Server (push) Has been cancelled
CI Website / Test Website Server (push) Has been cancelled
CI Website / Bundle Website Server (push) Has been cancelled
CI / Lint Biome (push) Has been cancelled
CI / Lint oxlint (push) Has been cancelled
CI / Lint TypeScript (push) Has been cancelled
CI / Lint Secretlint (push) Has been cancelled
CI / Test (22.x, macos-latest) (push) Has been cancelled
CI / Test (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, macos-latest) (push) Has been cancelled
CI / Build and run (24.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, windows-latest) (push) Has been cancelled
CI / Build and run (26.x, macos-latest) (push) Has been cancelled
CI / Build and run (26.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (26.x, windows-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, macos-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Docker / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Docker / build (linux/arm/v7, ubuntu-24.04-arm) (push) Has been cancelled
Docker / build (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Docker / merge (push) Has been cancelled
Pack repository with Repomix / pack-repo (push) Has been cancelled
Performance Benchmark History / Benchmark (macos-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (ubuntu-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (windows-latest) (push) Has been cancelled
Performance Benchmark History / Store Results (push) Has been cancelled
Test Repomix Action / Test Node.js 22 (push) Has been cancelled
Test Repomix Action / Test Node.js 24 (push) Has been cancelled
Test Repomix Action / Test Node.js 26 (push) Has been cancelled
137 行
4.5 KiB
TypeScript
137 行
4.5 KiB
TypeScript
import { spawn } from 'node:child_process';
|
|
import * as clipboard from 'tinyclip';
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import type { RepomixConfigMerged } from '../../../src/config/configSchema.js';
|
|
import { copyToClipboardIfEnabled } from '../../../src/core/packager/copyToClipboardIfEnabled.js';
|
|
import type { RepomixProgressCallback } from '../../../src/shared/types.js';
|
|
|
|
vi.mock('tinyclip');
|
|
vi.mock('../../../src/shared/logger');
|
|
vi.mock('node:child_process');
|
|
|
|
describe('copyToClipboardIfEnabled', () => {
|
|
const originalEnv = process.env;
|
|
|
|
beforeEach(() => {
|
|
vi.resetAllMocks();
|
|
process.env = { ...originalEnv };
|
|
process.env.WAYLAND_DISPLAY = undefined;
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env = originalEnv;
|
|
});
|
|
|
|
it('should copy output to clipboard if flag enabled in config', async () => {
|
|
const output = 'test output';
|
|
const config: RepomixConfigMerged = {
|
|
output: { copyToClipboard: true },
|
|
} as RepomixConfigMerged;
|
|
const progressCallback: RepomixProgressCallback = vi.fn();
|
|
|
|
await copyToClipboardIfEnabled(output, progressCallback, config);
|
|
|
|
expect(progressCallback).toHaveBeenCalledWith('Copying to clipboard...');
|
|
expect(clipboard.writeText).toHaveBeenCalledWith(output);
|
|
});
|
|
|
|
it('should not copy output to clipboard if flag disabled in config', async () => {
|
|
const output = 'test output';
|
|
const config: RepomixConfigMerged = {
|
|
output: { copyToClipboard: false },
|
|
} as RepomixConfigMerged;
|
|
const progressCallback: RepomixProgressCallback = vi.fn();
|
|
|
|
await copyToClipboardIfEnabled(output, progressCallback, config);
|
|
|
|
expect(progressCallback).not.toHaveBeenCalled();
|
|
expect(clipboard.writeText).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should use wl-copy in Wayland environment', async () => {
|
|
process.env.WAYLAND_DISPLAY = '1';
|
|
process.env.NODE_ENV = 'development';
|
|
|
|
const output = 'test output';
|
|
const config: RepomixConfigMerged = {
|
|
output: { copyToClipboard: true },
|
|
} as RepomixConfigMerged;
|
|
const progressCallback: RepomixProgressCallback = vi.fn();
|
|
|
|
type MockProc = {
|
|
on: ReturnType<typeof vi.fn>;
|
|
stdin: { end: ReturnType<typeof vi.fn> };
|
|
};
|
|
|
|
const mockProc: MockProc = {
|
|
on: vi.fn(),
|
|
stdin: { end: vi.fn() },
|
|
};
|
|
vi.mocked(spawn).mockReturnValue(mockProc as unknown as ReturnType<typeof spawn>);
|
|
|
|
// Simulate successful wl-copy execution
|
|
mockProc.on.mockImplementation((event, callback) => {
|
|
if (event === 'close') {
|
|
callback(0);
|
|
}
|
|
return mockProc;
|
|
});
|
|
|
|
await copyToClipboardIfEnabled(output, progressCallback, config);
|
|
|
|
expect(spawn).toHaveBeenCalledWith('wl-copy', [], { stdio: ['pipe', 'ignore', 'ignore'] });
|
|
expect(mockProc.stdin.end).toHaveBeenCalledWith(output);
|
|
expect(clipboard.writeText).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should fallback to tinyclip when wl-copy fails', async () => {
|
|
process.env.WAYLAND_DISPLAY = '1';
|
|
process.env.NODE_ENV = 'development';
|
|
|
|
const output = 'test output';
|
|
const config: RepomixConfigMerged = {
|
|
output: { copyToClipboard: true },
|
|
} as RepomixConfigMerged;
|
|
const progressCallback: RepomixProgressCallback = vi.fn();
|
|
|
|
type MockProc = {
|
|
on: ReturnType<typeof vi.fn>;
|
|
stdin: { end: ReturnType<typeof vi.fn> };
|
|
};
|
|
|
|
const mockProc: MockProc = {
|
|
on: vi.fn(),
|
|
stdin: { end: vi.fn() },
|
|
};
|
|
vi.mocked(spawn).mockReturnValue(mockProc as unknown as ReturnType<typeof spawn>);
|
|
|
|
// Simulate wl-copy failure
|
|
mockProc.on.mockImplementation((event, callback) => {
|
|
if (event === 'error') {
|
|
callback(new Error('Command not found'));
|
|
}
|
|
return mockProc;
|
|
});
|
|
|
|
await copyToClipboardIfEnabled(output, progressCallback, config);
|
|
|
|
expect(spawn).toHaveBeenCalledWith('wl-copy', [], { stdio: ['pipe', 'ignore', 'ignore'] });
|
|
expect(clipboard.writeText).toHaveBeenCalledWith(output);
|
|
});
|
|
|
|
it('should handle tinyclip failure', async () => {
|
|
const output = 'test output';
|
|
const config: RepomixConfigMerged = {
|
|
output: { copyToClipboard: true },
|
|
} as RepomixConfigMerged;
|
|
const progressCallback: RepomixProgressCallback = vi.fn();
|
|
|
|
vi.mocked(clipboard.writeText).mockRejectedValue(new Error('Clipboard access denied'));
|
|
|
|
await copyToClipboardIfEnabled(output, progressCallback, config);
|
|
|
|
expect(progressCallback).toHaveBeenCalledWith('Copying to clipboard...');
|
|
expect(clipboard.writeText).toHaveBeenCalledWith(output);
|
|
});
|
|
});
|