From 4132c7de13b7468f652d6659d7d92bbadb0681bd Mon Sep 17 00:00:00 2001 From: Abhishek Raj <113784630+abbi4code@users.noreply.github.com> Date: Wed, 25 Dec 2024 12:12:41 +0530 Subject: [PATCH] checkenvFile test migrated from jest to vitest (#2849) --- ...ckEnvFile.test.ts => checkEnvFile.spec.ts} | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) rename src/setup/checkEnvFile/{checkEnvFile.test.ts => checkEnvFile.spec.ts} (62%) diff --git a/src/setup/checkEnvFile/checkEnvFile.test.ts b/src/setup/checkEnvFile/checkEnvFile.spec.ts similarity index 62% rename from src/setup/checkEnvFile/checkEnvFile.test.ts rename to src/setup/checkEnvFile/checkEnvFile.spec.ts index a23976db4a..c2b75db0a6 100644 --- a/src/setup/checkEnvFile/checkEnvFile.test.ts +++ b/src/setup/checkEnvFile/checkEnvFile.spec.ts @@ -1,11 +1,22 @@ import fs from 'fs'; import { checkEnvFile } from './checkEnvFile'; +import { vi } from 'vitest'; -jest.mock('fs'); +/** + * This file contains unit tests for the `checkEnvFile` function. + * + * The tests cover: + * - Behavior when the `.env` file is missing required keys and appending them appropriately. + * - Ensuring no changes are made when all keys are present in the `.env` file. + * + * These tests utilize Vitest for test execution and mock the `fs` module to simulate file operations. + */ + +vi.mock('fs'); describe('checkEnvFile', () => { beforeEach(() => { - jest.resetAllMocks(); + vi.resetAllMocks(); }); it('should append missing keys to the .env file', () => { @@ -13,13 +24,12 @@ describe('checkEnvFile', () => { const envExampleContent = 'EXISTING_KEY=existing_value\nNEW_KEY=default_value\n'; - jest - .spyOn(fs, 'readFileSync') + vi.spyOn(fs, 'readFileSync') .mockReturnValueOnce(envContent) .mockReturnValueOnce(envExampleContent) .mockReturnValueOnce(envExampleContent); - jest.spyOn(fs, 'appendFileSync'); + vi.spyOn(fs, 'appendFileSync'); checkEnvFile(); @@ -33,12 +43,11 @@ describe('checkEnvFile', () => { const envContent = 'EXISTING_KEY=existing_value\n'; const envExampleContent = 'EXISTING_KEY=existing_value\n'; - jest - .spyOn(fs, 'readFileSync') + vi.spyOn(fs, 'readFileSync') .mockReturnValueOnce(envContent) .mockReturnValueOnce(envExampleContent); - jest.spyOn(fs, 'appendFileSync'); + vi.spyOn(fs, 'appendFileSync'); checkEnvFile();