1- import { beforeEach , afterEach , describe , expect , it , vi } from 'vitest' ;
21import * as fs from 'fs' ;
3- import * as os from 'os' ;
42import * as path from 'path' ;
53
4+ import { beforeEach , afterEach , describe , expect , it , vi } from 'vitest' ;
5+
66import { getConfig , updateConfig } from '../../src/settings/config.js' ;
77import { getSettingsDir } from '../../src/settings/settings.js' ;
88
@@ -21,7 +21,7 @@ vi.mock('fs', () => ({
2121describe ( 'Config' , ( ) => {
2222 const mockSettingsDir = '/mock/settings/dir' ;
2323 const mockConfigFile = path . join ( mockSettingsDir , 'config.json' ) ;
24-
24+
2525 beforeEach ( ( ) => {
2626 vi . mocked ( getSettingsDir ) . mockReturnValue ( mockSettingsDir ) ;
2727 } ) ;
@@ -33,9 +33,9 @@ describe('Config', () => {
3333 describe ( 'getConfig' , ( ) => {
3434 it ( 'should return default config if config file does not exist' , ( ) => {
3535 vi . mocked ( fs . existsSync ) . mockReturnValue ( false ) ;
36-
36+
3737 const config = getConfig ( ) ;
38-
38+
3939 expect ( config ) . toEqual ( { githubMode : false } ) ;
4040 expect ( fs . existsSync ) . toHaveBeenCalledWith ( mockConfigFile ) ;
4141 } ) ;
@@ -44,9 +44,9 @@ describe('Config', () => {
4444 const mockConfig = { githubMode : true , customSetting : 'value' } ;
4545 vi . mocked ( fs . existsSync ) . mockReturnValue ( true ) ;
4646 vi . mocked ( fs . readFileSync ) . mockReturnValue ( JSON . stringify ( mockConfig ) ) ;
47-
47+
4848 const config = getConfig ( ) ;
49-
49+
5050 expect ( config ) . toEqual ( mockConfig ) ;
5151 expect ( fs . existsSync ) . toHaveBeenCalledWith ( mockConfigFile ) ;
5252 expect ( fs . readFileSync ) . toHaveBeenCalledWith ( mockConfigFile , 'utf-8' ) ;
@@ -57,9 +57,9 @@ describe('Config', () => {
5757 vi . mocked ( fs . readFileSync ) . mockImplementation ( ( ) => {
5858 throw new Error ( 'Read error' ) ;
5959 } ) ;
60-
60+
6161 const config = getConfig ( ) ;
62-
62+
6363 expect ( config ) . toEqual ( { githubMode : false } ) ;
6464 } ) ;
6565 } ) ;
@@ -70,13 +70,13 @@ describe('Config', () => {
7070 const newConfig = { githubMode : true } ;
7171 vi . mocked ( fs . existsSync ) . mockReturnValue ( true ) ;
7272 vi . mocked ( fs . readFileSync ) . mockReturnValue ( JSON . stringify ( currentConfig ) ) ;
73-
73+
7474 const result = updateConfig ( newConfig ) ;
75-
75+
7676 expect ( result ) . toEqual ( { githubMode : true } ) ;
7777 expect ( fs . writeFileSync ) . toHaveBeenCalledWith (
7878 mockConfigFile ,
79- JSON . stringify ( { githubMode : true } , null , 2 )
79+ JSON . stringify ( { githubMode : true } , null , 2 ) ,
8080 ) ;
8181 } ) ;
8282
@@ -85,9 +85,9 @@ describe('Config', () => {
8585 const partialConfig = { githubMode : true } ;
8686 vi . mocked ( fs . existsSync ) . mockReturnValue ( true ) ;
8787 vi . mocked ( fs . readFileSync ) . mockReturnValue ( JSON . stringify ( currentConfig ) ) ;
88-
88+
8989 const result = updateConfig ( partialConfig ) ;
90-
90+
9191 expect ( result ) . toEqual ( { githubMode : true , existingSetting : 'value' } ) ;
9292 } ) ;
9393 } ) ;
0 commit comments