1- import { expect , test , mock , describe , beforeEach , type Mock } from " bun:test" ;
1+ import { expect , test , mock , describe , beforeEach , type Mock } from ' bun:test' ;
22import {
33 showGlobalConfig ,
44 showSession ,
@@ -7,34 +7,30 @@ import {
77 endSession ,
88 resetGlobalConfig ,
99 type ConfigData ,
10- } from " ./config" ;
11- import * as common from " ./common" ;
10+ } from ' ./config' ;
11+ import * as common from ' ./common' ;
1212
13- describe ( " Config management" , ( ) => {
13+ describe ( ' Config management' , ( ) => {
1414 const mockConfig : ConfigData = {
1515 tts : {
16- voiceName : " test_voice" ,
17- voiceId : " voice123" ,
18- outputDir : " /test/output" ,
19- play : " all" ,
20- format : " wav" ,
16+ voiceName : ' test_voice' ,
17+ voiceId : ' voice123' ,
18+ outputDir : ' /test/output' ,
19+ play : ' all' ,
20+ format : ' wav' ,
2121 } ,
2222 json : true ,
23- apiKey : " test-api-key" ,
23+ apiKey : ' test-api-key' ,
2424 } ;
2525
2626 const mockSettings = {
2727 globalConfig : { ...mockConfig } ,
2828 session : { ...mockConfig } ,
2929 reporter : {
30- json : mock ( ( _ : unknown ) => { } ) as unknown as Mock <
31- common . Reporter [ "json" ]
32- > ,
33- info : mock ( ( _ : unknown ) => { } ) as unknown as Mock <
34- common . Reporter [ "info" ]
35- > ,
30+ json : mock ( ( _ : unknown ) => { } ) as unknown as Mock < common . Reporter [ 'json' ] > ,
31+ info : mock ( ( _ : unknown ) => { } ) as unknown as Mock < common . Reporter [ 'info' ] > ,
3632 withSpinner : mock ( ( msg , callback ) => callback ( ) ) as unknown as Mock <
37- common . Reporter [ " withSpinner" ]
33+ common . Reporter [ ' withSpinner' ]
3834 > ,
3935 } ,
4036 } ;
@@ -46,83 +42,73 @@ describe("Config management", () => {
4642 mockSettings . reporter . withSpinner . mockReset ( ) ;
4743
4844 // Mock getSettings and makeReporter
49- mock . module ( " ./common" , ( ) => ( {
45+ mock . module ( ' ./common' , ( ) => ( {
5046 ...common ,
5147 getSettings : ( ) => Promise . resolve ( mockSettings ) ,
5248 makeReporter : ( ) => mockSettings . reporter ,
5349 } ) ) ;
5450 } ) ;
5551
56- describe ( " show commands" , ( ) => {
57- test ( " showGlobalConfig displays global config" , async ( ) => {
52+ describe ( ' show commands' , ( ) => {
53+ test ( ' showGlobalConfig displays global config' , async ( ) => {
5854 await showGlobalConfig ( ) ;
5955 expect ( mockSettings . reporter . json ) . toHaveBeenCalledWith ( mockConfig ) ;
6056 } ) ;
6157
62- test ( " showSession displays session config" , async ( ) => {
58+ test ( ' showSession displays session config' , async ( ) => {
6359 await showSession ( ) ;
6460 expect ( mockSettings . reporter . json ) . toHaveBeenCalledWith ( mockConfig ) ;
6561 } ) ;
6662 } ) ;
6763
68- describe ( " set commands" , ( ) => {
64+ describe ( ' set commands' , ( ) => {
6965 const mockWriteFile = mock ( ( ) => Promise . resolve ( ) ) ;
70- mock . module ( " node:fs/promises" , ( ) => ( {
66+ mock . module ( ' node:fs/promises' , ( ) => ( {
7167 writeFile : mockWriteFile ,
7268 readFile : mock ( ( ) => Promise . resolve ( JSON . stringify ( mockConfig ) ) ) ,
7369 } ) ) ;
7470
75- test ( " setGlobalConfig updates global config" , async ( ) => {
71+ test ( ' setGlobalConfig updates global config' , async ( ) => {
7672 await setGlobalConfig ( {
77- name : " tts.voiceName" ,
78- value : " new_voice" ,
73+ name : ' tts.voiceName' ,
74+ value : ' new_voice' ,
7975 } ) ;
8076
81- expect ( mockSettings . reporter . info . mock . calls ) . toEqual ( [
82- [ "global config updated" ] ,
83- ] ) ;
84- expect ( mockSettings . reporter . json . mock . calls ) . toEqual ( [
85- [ { "tts.voiceName" : "new_voice" } ] ,
86- ] ) ;
77+ expect ( mockSettings . reporter . info . mock . calls ) . toEqual ( [ [ 'global config updated' ] ] ) ;
78+ expect ( mockSettings . reporter . json . mock . calls ) . toEqual ( [ [ { 'tts.voiceName' : 'new_voice' } ] ] ) ;
8779 } ) ;
8880
89- test ( " setSessionConfig updates session config" , async ( ) => {
81+ test ( ' setSessionConfig updates session config' , async ( ) => {
9082 await setSessionConfig ( {
91- name : " tts.format" ,
92- value : " mp3" ,
83+ name : ' tts.format' ,
84+ value : ' mp3' ,
9385 } ) ;
9486
95- expect ( mockSettings . reporter . info ) . toHaveBeenCalledWith (
96- "session config updated" ,
97- ) ;
87+ expect ( mockSettings . reporter . info ) . toHaveBeenCalledWith ( 'session config updated' ) ;
9888 expect ( mockSettings . reporter . json ) . toHaveBeenCalledWith ( {
99- " tts.format" : " mp3" ,
89+ ' tts.format' : ' mp3' ,
10090 } ) ;
10191 } ) ;
10292
103- test ( " setConfig validates input values" , async ( ) => {
93+ test ( ' setConfig validates input values' , async ( ) => {
10494 await expect (
10595 setGlobalConfig ( {
106- name : " tts.play" ,
107- value : " invalid" ,
108- } ) ,
109- ) . rejects . toThrow ( " Invalid value for tts.play" ) ;
96+ name : ' tts.play' ,
97+ value : ' invalid' ,
98+ } )
99+ ) . rejects . toThrow ( ' Invalid value for tts.play' ) ;
110100 } ) ;
111101 } ) ;
112102
113- describe ( " clear commands" , ( ) => {
114- test ( " endSession clears session config" , async ( ) => {
103+ describe ( ' clear commands' , ( ) => {
104+ test ( ' endSession clears session config' , async ( ) => {
115105 await endSession ( ) ;
116- expect ( mockSettings . reporter . info ) . toHaveBeenCalledWith (
117- "session config cleared" ,
118- ) ;
106+ expect ( mockSettings . reporter . info ) . toHaveBeenCalledWith ( 'session config cleared' ) ;
119107 } ) ;
120108
121- test ( " resetGlobalConfig clears global config" , async ( ) => {
109+ test ( ' resetGlobalConfig clears global config' , async ( ) => {
122110 await resetGlobalConfig ( ) ;
123- expect ( mockSettings . reporter . info ) . toHaveBeenCalledWith (
124- "global config cleared" ,
125- ) ;
111+ expect ( mockSettings . reporter . info ) . toHaveBeenCalledWith ( 'global config cleared' ) ;
126112 } ) ;
127113 } ) ;
128114} ) ;
0 commit comments