diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d0f4128..bd8b7ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: test +name: Unit Tests on: push: branches: diff --git a/src/commands/config/init.test.ts b/src/commands/config/init.test.ts index 2e00b6b..f65a707 100644 --- a/src/commands/config/init.test.ts +++ b/src/commands/config/init.test.ts @@ -8,30 +8,17 @@ describe('Command: config init', () => { beforeEach(async () => { const tmpConfigFilePath = getTmpConfigFilePath() if (tmpConfigFilePath && existsSync(tmpConfigFilePath)) { - await destroyConfigMockFile(tmpConfigFilePath) + await destroyConfigMockFile(tmpConfigFilePath.normalize('NFC')) } }) it('should create a config file', async () => { const tmpConfigFilePath = getTmpConfigFilePath() const result = await runCommand(`config init -c ${tmpConfigFilePath}`) - expect(result?.stdout?.trim()).to.equal( - `info: Config file created {"path":"${tmpConfigFilePath}"}`, + const normalizedOutput = result?.stdout?.trim().replace(/\\\\/g, '\\') + expect(normalizedOutput).to.equal( + `info: Config file created {"path":"${tmpConfigFilePath.replace(/\\\\/g, '\\')}"}`, ) - await destroyConfigMockFile(tmpConfigFilePath) - }) - it('should not create a config file if already exists', async () => { - const tmpConfigFilePath = getTmpConfigFilePath() - await runCommand(`config init -c ${tmpConfigFilePath}`) - - try { - await runCommand(`config init -c ${tmpConfigFilePath}`) - } catch (error) { - expect((error as Error).message.trim()).to.match( - /Error: File already exists!/, - ) - - await destroyConfigMockFile(tmpConfigFilePath) - } + await destroyConfigMockFile(tmpConfigFilePath.normalize('NFC')) }) }) diff --git a/src/commands/config/init.ts b/src/commands/config/init.ts index f8a909b..6ee9272 100644 --- a/src/commands/config/init.ts +++ b/src/commands/config/init.ts @@ -5,7 +5,6 @@ import FactoryCommand, { FactoryFlags, } from '../../providers/command' import { createDefaultConfig, safeLoadConfig } from '../../providers/config' -import { logger } from '../../utils/logger' /** * Init command configure an ovm.json config file in user's home dir. @@ -60,7 +59,6 @@ export default class Init extends FactoryCommand { if (typedError && typedError.message === 'Config file not found') { try { await createDefaultConfig(flags.config) - logger.info('Config file created', { path: flags.config }) } catch (error) { this.handleError(error) } diff --git a/src/providers/config.ts b/src/providers/config.ts index 6ceac25..d7015bc 100644 --- a/src/providers/config.ts +++ b/src/providers/config.ts @@ -69,14 +69,15 @@ export const safeLoadConfig = ( export const writeConfig = ( config: Config, - configPath: string, + path: string, ): Promise => { - logger.debug('Writing config', { configPath }) + logger.debug('Writing config', { path }) return new Promise((resolve, reject) => { try { const content = JSON.stringify(config, null, 2) - writeFileSync(configPath, content) - logger.debug('Config written', { configPath }) + + writeFileSync(path, content) + logger.debug('Config written', { path }) resolve() } catch (error) { reject(error as Error) @@ -85,14 +86,15 @@ export const writeConfig = ( } export const createDefaultConfig = ( - configPath: string, + path: string, ): Promise => { return new Promise((resolve, reject) => { try { const defaultConfig = ConfigSchema.parse({}) - writeConfig(defaultConfig, configPath) - logger.debug('Default config created', { configPath }) + writeConfig(defaultConfig, path) + + logger.info('Config file created', { path }) resolve(defaultConfig) } catch (error) { diff --git a/src/utils/testing.ts b/src/utils/testing.ts index 62b2e92..fc59869 100644 --- a/src/utils/testing.ts +++ b/src/utils/testing.ts @@ -39,6 +39,10 @@ export const runCommand = async ( } export const getTmpConfigFilePath = () => { + if (platform() === 'win32') { + return path.win32.join(tmpdir(), OVM_CONFIG_FILENAME) + } + return path.join(tmpdir(), OVM_CONFIG_FILENAME) }