Skip to content

Commit

Permalink
chore: Add more Compose command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed Feb 20, 2024
1 parent 1225edd commit 176b4f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/commands/compose/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const composeCommand = () => {
'Uses Compose under the hood.',
)
.addCommand(composeShowArgsCommand())
.action(async (options) => {
.action(() => {
const config = projectConfig();
const args = process.argv.slice(3);

Expand Down
24 changes: 18 additions & 6 deletions test/commands/compose.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
import { describe, expect, test } from 'bun:test';
import { projectConfig } from '../../src/config/project';
import { composeExecParams, composeFiles } from '../../src/utils/compose';
import { composeCommand } from '../../src/commands/compose';

describe("Command: 'compose'", () => {
const config = projectConfig();

test('Returns compose files string', () => {
const composeFileString = composeFiles({});
test('Returns compose exec params', () => {
const composeSettingsString = composeExecParams();

expect(composeFileString).toBeArray();
expect(composeSettingsString).toContain(
`--env-file ${projectConfig().paths.env_file}`,
`--env-file ${config.paths.env_file}`,
);
expect(composeSettingsString).toContain(
`--project-name ${projectConfig().compose.project_name}`,
`--project-name ${config.compose.project_name}`,
);
});

test('Returns compose files params', () => {
const files = composeFiles({});
expect(files).toBeArray();
expect(files.join(' ').split(' ')).toContain('--file');
})

test('Returns error when no arguments', () => {
const command = Bun.spawnSync(['./cli.ts', 'compose']);
expect(command.stdout.toString()).toContain(
'A Compose command needs to be specified.',
);
expect(command.exitCode).toEqual(1);
});

test('Returns both files and exec params', () => {
const command = Bun.spawnSync(['./cli.ts', 'compose', 'show-args']);
expect(command.stdout.toString()).toContain('Compose command params:');
expect(command.stdout.toString()).toContain('Compose files params:');
expect(command.exitCode).toEqual(0);
})
});

0 comments on commit 176b4f2

Please sign in to comment.