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
132 lines
3.9 KiB
TypeScript
132 lines
3.9 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { Spinner } from '../../src/cli/cliSpinner.js';
|
|
import type { CliOptions } from '../../src/cli/types.js';
|
|
|
|
const mockPicoInstances: Array<{
|
|
start: ReturnType<typeof vi.fn>;
|
|
setText: ReturnType<typeof vi.fn>;
|
|
succeed: ReturnType<typeof vi.fn>;
|
|
fail: ReturnType<typeof vi.fn>;
|
|
stop: ReturnType<typeof vi.fn>;
|
|
}> = [];
|
|
|
|
// Mock picospinner
|
|
vi.mock('picospinner', () => {
|
|
return {
|
|
Spinner: class MockPicoSpinner {
|
|
start = vi.fn();
|
|
setText = vi.fn();
|
|
succeed = vi.fn();
|
|
fail = vi.fn();
|
|
stop = vi.fn();
|
|
constructor() {
|
|
mockPicoInstances.push(this);
|
|
}
|
|
},
|
|
renderer: {
|
|
terminalWidth: 80,
|
|
},
|
|
};
|
|
});
|
|
|
|
describe('cliSpinner', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
mockPicoInstances.length = 0;
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
const getLastPicoInstance = () => mockPicoInstances[mockPicoInstances.length - 1];
|
|
|
|
describe('Spinner', () => {
|
|
describe('when quiet mode is disabled', () => {
|
|
it('should start spinner', () => {
|
|
const spinner = new Spinner('Processing...', {} as CliOptions);
|
|
spinner.start();
|
|
|
|
expect(getLastPicoInstance().start).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should update spinner message', () => {
|
|
const spinner = new Spinner('Initial message', {} as CliOptions);
|
|
spinner.start();
|
|
|
|
spinner.update('Updated message');
|
|
|
|
expect(getLastPicoInstance().setText).toHaveBeenCalledWith('Updated message', false);
|
|
});
|
|
|
|
it('should succeed with success message', () => {
|
|
const spinner = new Spinner('Processing...', {} as CliOptions);
|
|
spinner.start();
|
|
|
|
spinner.succeed('Success!');
|
|
|
|
expect(getLastPicoInstance().succeed).toHaveBeenCalledWith('Success!');
|
|
});
|
|
|
|
it('should fail with error message', () => {
|
|
const spinner = new Spinner('Processing...', {} as CliOptions);
|
|
spinner.start();
|
|
|
|
spinner.fail('Failed!');
|
|
|
|
expect(getLastPicoInstance().fail).toHaveBeenCalledWith('Failed!');
|
|
});
|
|
});
|
|
|
|
describe('when quiet mode is enabled', () => {
|
|
it('should not create PicoSpinner when quiet flag is true', () => {
|
|
const instancesBefore = mockPicoInstances.length;
|
|
const spinner = new Spinner('Processing...', { quiet: true } as CliOptions);
|
|
spinner.start();
|
|
|
|
expect(mockPicoInstances.length).toBe(instancesBefore);
|
|
});
|
|
|
|
it('should not create PicoSpinner when verbose flag is true', () => {
|
|
const instancesBefore = mockPicoInstances.length;
|
|
const spinner = new Spinner('Processing...', { verbose: true } as CliOptions);
|
|
spinner.start();
|
|
|
|
expect(mockPicoInstances.length).toBe(instancesBefore);
|
|
});
|
|
|
|
it('should not create PicoSpinner when stdout flag is true', () => {
|
|
const instancesBefore = mockPicoInstances.length;
|
|
const spinner = new Spinner('Processing...', { stdout: true } as CliOptions);
|
|
spinner.start();
|
|
|
|
expect(mockPicoInstances.length).toBe(instancesBefore);
|
|
});
|
|
|
|
it('should not throw when update is called in quiet mode', () => {
|
|
const spinner = new Spinner('Initial', { quiet: true } as CliOptions);
|
|
expect(() => {
|
|
spinner.start();
|
|
spinner.update('Updated');
|
|
}).not.toThrow();
|
|
});
|
|
|
|
it('should not throw when succeed is called in quiet mode', () => {
|
|
const spinner = new Spinner('Processing...', { quiet: true } as CliOptions);
|
|
expect(() => {
|
|
spinner.start();
|
|
spinner.succeed('Success!');
|
|
}).not.toThrow();
|
|
});
|
|
|
|
it('should not throw when fail is called in quiet mode', () => {
|
|
const spinner = new Spinner('Processing...', { quiet: true } as CliOptions);
|
|
expect(() => {
|
|
spinner.start();
|
|
spinner.fail('Failed!');
|
|
}).not.toThrow();
|
|
});
|
|
});
|
|
});
|
|
});
|