-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: command 를 매 호출 시 재생성 하도록 수정, number 가 아닌 경우 기본 값 사용하도록 변경
* fix: command 를 매 호출 시 재생성 하도록 수정 * chore: boolean 타입으로 사용할 수 있도록 변경 * fix: number 가 아닌 경우 기본 값 사용하도록 변경 * chore: 불필요한 설정파일 삭제 * chore: cli helper 테스트 코드 추가 * chore: remove unused import
- Loading branch information
1 parent
374952b
commit 577a6b8
Showing
4 changed files
with
105 additions
and
9 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { initCli } from './cli.helper'; | ||
import path from 'node:path'; | ||
|
||
const mockArgv = (arguments_: string[]) => { | ||
process.argv = ['node', 'script', ...arguments_]; | ||
}; | ||
|
||
describe.concurrent('initCli 함수 테스트', () => { | ||
it('기본 옵션 값들을 설정해야 한다', () => { | ||
mockArgv([]); | ||
vi.unstubAllEnvs(); | ||
const options = initCli(); | ||
|
||
expect(options).toEqual({ | ||
MAX_STATUS_LOG: 100, | ||
SOURCE_PATH: path.resolve(process.cwd(), './'), | ||
OUTPUT_FILE_PATH: path.resolve(process.cwd(), './pulse.sqlite'), | ||
FILE_CONCURRENCY: 5, | ||
EXECUTE_CONCURRENCY: 50, | ||
EXPORT_JSON: false, | ||
}); | ||
}); | ||
|
||
it('CLI 옵션으로 설정한 값을 반환해야 한다', () => { | ||
mockArgv([ | ||
'./src', | ||
'-m', | ||
'200', | ||
'-o', | ||
'./output.db', | ||
'-c', | ||
'10', | ||
'-e', | ||
'100', | ||
'--json', | ||
]); | ||
vi.unstubAllEnvs(); | ||
|
||
const options = initCli(); | ||
|
||
expect(options).toEqual({ | ||
MAX_STATUS_LOG: 200, | ||
SOURCE_PATH: path.resolve(process.cwd(), './src'), | ||
OUTPUT_FILE_PATH: path.resolve(process.cwd(), './output.db'), | ||
FILE_CONCURRENCY: 10, | ||
EXECUTE_CONCURRENCY: 100, | ||
EXPORT_JSON: true, | ||
}); | ||
}); | ||
|
||
it('환경 변수 값을 사용해야 한다', () => { | ||
mockArgv([]); | ||
vi.unstubAllEnvs(); | ||
vi.stubEnv('PULSE_STATUS_LOGS_MAX', '300'); | ||
vi.stubEnv('PULSE_OUTPUT_PATH', './env_output.db'); | ||
vi.stubEnv('PULSE_FILE_CONCURRENCY', '15'); | ||
vi.stubEnv('PULSE_EXECUTE_CONCURRENCY', '200'); | ||
|
||
const options = initCli(); | ||
|
||
expect(options).toEqual({ | ||
MAX_STATUS_LOG: 300, | ||
SOURCE_PATH: path.resolve(process.cwd(), './'), | ||
OUTPUT_FILE_PATH: path.resolve(process.cwd(), './env_output.db'), | ||
FILE_CONCURRENCY: 15, | ||
EXECUTE_CONCURRENCY: 200, | ||
EXPORT_JSON: false, | ||
}); | ||
}); | ||
|
||
it('숫자가 아닌 값은 기본값으로 대체해야 한다', () => { | ||
mockArgv([]); | ||
vi.unstubAllEnvs(); | ||
vi.stubEnv('PULSE_STATUS_LOGS_MAX', 'not-a-number'); | ||
vi.stubEnv('PULSE_FILE_CONCURRENCY', 'not-a-number'); | ||
vi.stubEnv('PULSE_EXECUTE_CONCURRENCY', 'not-a-number'); | ||
|
||
const options = initCli(); | ||
expect(options).toEqual({ | ||
MAX_STATUS_LOG: 100, | ||
SOURCE_PATH: path.resolve(process.cwd(), './'), | ||
OUTPUT_FILE_PATH: path.resolve(process.cwd(), './pulse.sqlite'), | ||
FILE_CONCURRENCY: 5, | ||
EXECUTE_CONCURRENCY: 50, | ||
EXPORT_JSON: false, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters