Skip to content

Commit

Permalink
chore: Update current-project command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed Feb 15, 2024
1 parent e7aa4ce commit 6e4ade7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/commands/config/current-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ export const currentProjectCommand = () => {
.summary('Manage DEMS current project state')
.description('Manage the current project state of DEMS')
.option('-s, --set <project>', 'Set current project to a new value')
.option('-f, --current-project-file', 'Set the current project file to use')
.action((options) => {
const currentProjectFile =
options.currentProjectFile ?? cliConfig.currentProjectFile;
if (options.set) {
fs.writeFileSync(cliConfig.currentProjectFile, options.set);
fs.writeFileSync(currentProjectFile, options.set);
console.log(`Current project set to: ${options.set}`);
} else {
console.log(`Current project is: ${cliConfig.currentProject}`);
Expand Down
19 changes: 16 additions & 3 deletions test/commands/config.current-project.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import { describe, expect, test } from 'bun:test';
import { spawnSync } from 'bun';
import { currentProjectCommand } from '../../src/commands/config/current-project';
import cliConfig from '../../src/config/cli';
import fs from 'node:fs';
import { createFile, createPath } from '../../src/utils/file-system';

describe("Command: 'config current-project'", () => {
test('is set by --set flag', () => {
const command = currentProjectCommand();
const current = 'testProject';
expect(command.setOptionValue('set', current).getOptionValue('set')).toBe(
const currentProjectFile = './current-project-test';
createFile({ file: currentProjectFile, content: '', verbose: false });
const command = Bun.spawnSync([
'./cli.ts',
'config',
'current-project',
'-s',
current,
);
'-f',
currentProjectFile,
]);
const currentProject = cliConfig.selectCurrentProject(currentProjectFile);
expect(command.stdout.toString()).toEqual(currentProject);
fs.rmSync(currentProjectFile);
});

test('is set by environment variable', () => {
Expand Down

0 comments on commit 6e4ade7

Please sign in to comment.