Skip to content

Commit

Permalink
cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TMisiukiewicz committed Nov 27, 2023
1 parent 44a36ab commit 30e3ea9
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/cli-tools/src/__tests__/cacheManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
import fs from 'fs';
import path from 'path';
import cacheManager from '../cacheManager';
import {cleanup, getTempDirectory} from '../../../../jest/helpers';

const DIR = getTempDirectory('.react-native-cli/cache');
const projectName = 'Project1';
const cachePath = '.react-native-cli/cache';
const fullPath = path.join(cachePath, projectName);
const fullPath = path.join(DIR, projectName);

describe('cacheManager', () => {
beforeEach(() => {
jest.resetAllMocks();
jest.restoreAllMocks();
});

test('should remove cache if it exists', () => {
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
afterEach(() => {
cleanup(DIR);
});

test('should not remove cache if it does not exist', () => {
jest.spyOn(fs, 'existsSync').mockReturnValue(false);
jest.spyOn(fs, 'rmSync').mockImplementation(() => {});
jest
.spyOn(path, 'resolve')
.mockReturnValue(path.join(cachePath, projectName));

cacheManager.removeProjectCache(projectName);

expect(fs.rmSync).toHaveBeenCalledWith(fullPath, {recursive: true});
expect(fs.rmSync).not.toHaveBeenCalled();
});

test('should not remove cache if it does not exist', () => {
jest.spyOn(fs, 'existsSync').mockReturnValue(false);
test('should remove cache if it exists', () => {
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
jest.spyOn(fs, 'rmSync').mockImplementation(() => {});
jest.spyOn(path, 'resolve').mockReturnValue(fullPath);

cacheManager.removeProjectCache(projectName);

expect(fs.rmSync).not.toHaveBeenCalled();
expect(fs.rmSync).toHaveBeenCalledWith(fullPath, {recursive: true});
});
});

0 comments on commit 30e3ea9

Please sign in to comment.