Skip to content

Commit

Permalink
🎨 Simplify command creation and run
Browse files Browse the repository at this point in the history
  • Loading branch information
segersniels committed Apr 3, 2020
1 parent f36a257 commit 4ccd535
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 56 deletions.
9 changes: 3 additions & 6 deletions src/commands/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ describe('config', () => {
prompt: { choice: ConfigOptions.CAUTION_CHECK },
});

const command = new Config('enable');
await command.run();
await new Config('enable').run();
});

it('should correctly disable', async () => {
mock(Config.prototype, sandbox, {
prompt: { choice: ConfigOptions.CAUTION_CHECK },
});

const command = new Config('disable');
await command.run();
await new Config('disable').run();
});

it('should correctly log usage of fully custom command', async () => {
Expand All @@ -44,7 +42,6 @@ describe('config', () => {
},
});

const command = new Config('disable');
await command.run();
await new Config('disable').run();
});
});
36 changes: 12 additions & 24 deletions src/commands/__tests__/docker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ describe('docker', () => {
mock(Config.prototype, sandbox, {
prompt: { choice: ConfigOptions.FUZZY_SEARCH },
});
const command = new Config('disable');
await command.run();
await new Config('disable').run();

mock(Docker.prototype, sandbox);
});
Expand All @@ -29,8 +28,7 @@ describe('docker', () => {
});

it('should correctly passthrough to docker', async () => {
const command = new Docker('ps');
expect(await command.run()).to.eql('docker ps');
expect(await new Docker('ps').run()).to.eql('docker ps');
});

it('should correctly log usage', async () => {
Expand All @@ -42,8 +40,7 @@ describe('docker', () => {
},
});

const command = new Docker('ps');
expect(await command.run()).to.eql('docker ps --help');
expect(await new Docker('ps').run()).to.eql('docker ps --help');
});

it('should correctly log usage of supdock command', async () => {
Expand All @@ -55,8 +52,7 @@ describe('docker', () => {
},
});

const command = new Docker('start');
await command.run();
await new Docker('start').run();
});

it('should correctly execute supdock prompt command', async () => {
Expand All @@ -65,8 +61,7 @@ describe('docker', () => {
determineChoice: '456 - foo',
});

const command = new Docker('start');
expect(await command.run()).to.eql('docker start 456');
expect(await new Docker('start').run()).to.eql('docker start 456');
});

it('should correctly execute parallel prompt command', async () => {
Expand All @@ -77,8 +72,7 @@ describe('docker', () => {
},
});

const command = new Docker('start');
expect(await command.run()).to.eql(['123', '456', '789']);
expect(await new Docker('start').run()).to.eql(['123', '456', '789']);
});

it('should correctly passthrough to docker when fuzzy search is not enabled', async () => {
Expand All @@ -89,8 +83,7 @@ describe('docker', () => {
},
});

const command = new Docker('start');
expect(await command.run()).to.eql('docker start 123');
expect(await new Docker('start').run()).to.eql('docker start 123');
});
});

Expand All @@ -102,15 +95,13 @@ describe('docker', () => {
mock(Config.prototype, sandbox, {
prompt: { choice: ConfigOptions.FUZZY_SEARCH },
});
const command = new Config('enable');
await command.run();
await new Config('enable').run();

// Disable caution
mock(Config.prototype, sandbox, {
prompt: { choice: ConfigOptions.CAUTION_CHECK },
});
const check = new Config('disable');
await check.run();
await new Config('disable').run();
});

afterEach(() => {
Expand All @@ -126,8 +117,7 @@ describe('docker', () => {
},
});

const command = new Docker('start');
expect(await command.run()).to.eql('docker start abc');
expect(await new Docker('start').run()).to.eql('docker start abc');
});

it('should correctly fuzzy match when typing part of the name', async () => {
Expand All @@ -138,8 +128,7 @@ describe('docker', () => {
},
});

const command = new Docker('start');
expect(await command.run()).to.eql('docker start 123');
expect(await new Docker('start').run()).to.eql('docker start 123');
});

it('should correctly fuzzy match when id is fully matched', async () => {
Expand All @@ -150,8 +139,7 @@ describe('docker', () => {
},
});

const command = new Docker('start');
expect(await command.run()).to.eql('docker start 456');
expect(await new Docker('start').run()).to.eql('docker start 456');
});
});
});
3 changes: 1 addition & 2 deletions src/commands/__tests__/env.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('env', () => {
determineChoice: '456 - foo',
});

const command = new Env();
expect(await command.run()).to.eql('docker exec -ti 456 env');
expect(await new Env().run()).to.eql('docker exec -ti 456 env');
});
});
14 changes: 6 additions & 8 deletions src/commands/__tests__/logs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ describe('logs', async () => {
determineChoice: '456 - foo',
});

const command = new Logs();
expect(await command.run()).to.eql('docker logs 456');
expect(await new Logs().run()).to.eql('docker logs 456');
});

it('should correctly execute when passing --follow', async () => {
Expand All @@ -40,17 +39,15 @@ describe('logs', async () => {
},
});

const command = new Logs();
expect(await command.run()).to.eql('docker logs --follow 456');
expect(await new Logs().run()).to.eql('docker logs --follow 456');
});

it('should append short logs flags', async () => {
mock(Config.prototype, sandbox, {
prompt: { choice: ConfigOptions.SHORT_LOGS },
});

const config = new Config('enable');
await config.run();
await new Config('enable').run();

mock(Logs.prototype, sandbox, {
createChoices: ['123 - abc', '456 - foo', '789 - bar'],
Expand All @@ -62,7 +59,8 @@ describe('logs', async () => {
},
});

const command = new Logs();
expect(await command.run()).to.eql('docker logs --tail 500 --follow 456');
expect(await new Logs().run()).to.eql(
'docker logs --tail 500 --follow 456',
);
});
});
6 changes: 2 additions & 4 deletions src/commands/__tests__/prune.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ describe('prune', () => {
});

it('should correctly execute', async () => {
const command = new Prune();
expect(await command.run()).to.eql('docker system prune -f');
expect(await new Prune().run()).to.eql('docker system prune -f');
});

it('should correctly return info', async () => {
Expand All @@ -30,7 +29,6 @@ describe('prune', () => {
},
});

const command = new Prune();
expect(await command.run()).to.eql('docker system df');
expect(await new Prune().run()).to.eql('docker system df');
});
});
3 changes: 1 addition & 2 deletions src/commands/__tests__/ssh.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('env', () => {
determineShell: { choice: 'bash' },
});

const command = new Ssh();
expect(await command.run()).to.eql(`docker exec -ti 456 bash`);
expect(await new Ssh().run()).to.eql(`docker exec -ti 456 bash`);
});
});
9 changes: 3 additions & 6 deletions src/commands/__tests__/stats.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ describe('stats', () => {
});

it('should correctly execute', async () => {
const command = new Stats();
expect(await command.run()).to.eql('docker stats');
expect(await new Stats().run()).to.eql('docker stats');
});

it('should correctly execute with --all flag', async () => {
Expand All @@ -30,8 +29,7 @@ describe('stats', () => {
},
});

const command = new Stats();
expect(await command.run()).to.eql('docker stats --all');
expect(await new Stats().run()).to.eql('docker stats --all');
});

it('should correctly prompt when passing --prompt flag', async () => {
Expand All @@ -45,7 +43,6 @@ describe('stats', () => {
determineChoice: '456 - foo',
});

const command = new Stats();
expect(await command.run()).to.eql('docker stats 456');
expect(await new Stats().run()).to.eql('docker stats 456');
});
});
6 changes: 2 additions & 4 deletions src/commands/__tests__/stop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ describe('stop', () => {
determineChoice: '456 - foo',
});

const command = new Stop();
expect(await command.run()).to.eql('docker stop 456');
expect(await new Stop().run()).to.eql('docker stop 456');
});

it('should correctly execute with --force flag', async () => {
Expand All @@ -36,7 +35,6 @@ describe('stop', () => {
},
});

const command = new Stop();
expect(await command.run()).to.eql('docker rm --force 456');
expect(await new Stop().run()).to.eql('docker rm --force 456');
});
});

0 comments on commit 4ccd535

Please sign in to comment.