Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: src/setup/checkEnvFile/checkEnvFile.test.ts from Jest to Vitest #2849

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
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', () => {
const envContent = 'EXISTING_KEY=existing_value\n';
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();

Expand All @@ -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();

Expand Down
Loading