From 6e4ade7a87b6401829f11da4c18e404964c35b7c Mon Sep 17 00:00:00 2001 From: "Angel M. Adames" Date: Thu, 15 Feb 2024 16:23:59 -0400 Subject: [PATCH] chore: Update current-project command tests --- src/commands/config/current-project.ts | 5 ++++- test/commands/config.current-project.test.ts | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/commands/config/current-project.ts b/src/commands/config/current-project.ts index be8bfb6..387db71 100644 --- a/src/commands/config/current-project.ts +++ b/src/commands/config/current-project.ts @@ -9,9 +9,12 @@ export const currentProjectCommand = () => { .summary('Manage DEMS current project state') .description('Manage the current project state of DEMS') .option('-s, --set ', '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}`); diff --git a/test/commands/config.current-project.test.ts b/test/commands/config.current-project.test.ts index 9e0c59e..66aa727 100644 --- a/test/commands/config.current-project.test.ts +++ b/test/commands/config.current-project.test.ts @@ -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', () => {