-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44a36ab
commit 30e3ea9
Showing
1 changed file
with
15 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
}); | ||
}); |