This commit is contained in:
117
tests/integration/cli.test.ts
Normal file
117
tests/integration/cli.test.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs-extra';
|
||||
import { execa } from 'execa';
|
||||
|
||||
describe('CLI Integration Tests', () => {
|
||||
const testDir = path.join(__dirname, '..', '..', '.test-tmp');
|
||||
const layoutsDir = path.join(testDir, 'layouts');
|
||||
const templatesDir = path.join(testDir, 'templates');
|
||||
|
||||
beforeAll(async () => {
|
||||
fs.ensureDirSync(testDir);
|
||||
fs.ensureDirSync(layoutsDir);
|
||||
fs.ensureDirSync(templatesDir);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
fs.removeSync(testDir);
|
||||
});
|
||||
|
||||
describe('info command', () => {
|
||||
it('should display CLI information', async () => {
|
||||
const result = await execa('npx', ['ts-node', 'src/index.ts', 'info'], {
|
||||
cwd: path.join(__dirname, '..', '..'),
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Terminal Layout Sync CLI');
|
||||
});
|
||||
});
|
||||
|
||||
describe('save command', () => {
|
||||
it('should save a layout without arguments', async () => {
|
||||
const result = await execa('npx', ['ts-node', 'src/index.ts', 'save', '--help'], {
|
||||
cwd: path.join(__dirname, '..', '..'),
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Save current terminal layout');
|
||||
});
|
||||
});
|
||||
|
||||
describe('restore command', () => {
|
||||
it('should show help for restore command', async () => {
|
||||
const result = await execa('npx', ['ts-node', 'src/index.ts', 'restore', '--help'], {
|
||||
cwd: path.join(__dirname, '..', '..'),
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Restore a saved layout');
|
||||
});
|
||||
});
|
||||
|
||||
describe('list command', () => {
|
||||
it('should list layouts', async () => {
|
||||
const result = await execa('npx', ['ts-node', 'src/index.ts', 'list'], {
|
||||
cwd: path.join(__dirname, '..', '..'),
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('No layouts found');
|
||||
});
|
||||
|
||||
it('should list layouts in json format', async () => {
|
||||
const result = await execa('npx', ['ts-node', 'src/index.ts', 'list', '--format', 'json'], {
|
||||
cwd: path.join(__dirname, '..', '..'),
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(() => JSON.parse(result.stdout)).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('import command', () => {
|
||||
it('should show help for import command', async () => {
|
||||
const result = await execa('npx', ['ts-node', 'src/index.ts', 'import', '--help'], {
|
||||
cwd: path.join(__dirname, '..', '..'),
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Import a layout');
|
||||
});
|
||||
});
|
||||
|
||||
describe('export command', () => {
|
||||
it('should show help for export command', async () => {
|
||||
const result = await execa('npx', ['ts-node', 'src/index.ts', 'export', '--help'], {
|
||||
cwd: path.join(__dirname, '..', '..'),
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Export a layout');
|
||||
});
|
||||
});
|
||||
|
||||
describe('sync command', () => {
|
||||
it('should show help for sync command', async () => {
|
||||
const result = await execa('npx', ['ts-node', 'src/index.ts', 'sync', '--help'], {
|
||||
cwd: path.join(__dirname, '..', '..'),
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Sync layouts');
|
||||
});
|
||||
});
|
||||
|
||||
describe('template command', () => {
|
||||
it('should show help for template command', async () => {
|
||||
const result = await execa('npx', ['ts-node', 'src/index.ts', 'template', '--help'], {
|
||||
cwd: path.join(__dirname, '..', '..'),
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Manage layout templates');
|
||||
});
|
||||
});
|
||||
|
||||
describe('delete command', () => {
|
||||
it('should show help for delete command', async () => {
|
||||
const result = await execa('npx', ['ts-node', 'src/index.ts', 'delete', '--help'], {
|
||||
cwd: path.join(__dirname', '..', '..'),
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Delete a saved layout');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user