UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

38 lines (37 loc) 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require('../../mocks/mockAll'); const searchReplaceAllFiles_1 = require("../../../utils/searchReplaceAllFiles"); const mockFs_1 = require("../../mocks/mockFs"); describe('searchReplaceAllFiles', () => { it('should replace all files correctly', async () => { mockFs_1.mockFs.readdir.mockImplementation((p, _opts, cb) => { if (p === '/path/to') cb(null, [{ name: 'project', isDirectory: () => true }]); else cb(null, [{ name: 'file.js', isDirectory: () => false }]); }); mockFs_1.mockFs.writeFileSync('/path/to/project/file.js', 'before, content, after'); const changes = await (0, searchReplaceAllFiles_1.searchReplaceAllFiles)('/path/to', 'content', 'test', false); mockFs_1.mockFs.readdir.mockRestore(); expect(mockFs_1.mockFs.readFileSync('/path/to/project/file.js')).toBe('before, test, after'); expect(changes).toBe(1); }); it('should search with ignore case', async () => { mockFs_1.mockFs.readdir.mockImplementation((_p, _opts, cb) => { cb(null, [{ name: 'file.js', isDirectory: () => false }]); }); mockFs_1.mockFs.writeFileSync('/path/to/project/file.js', 'before, content, after'); const changes = await (0, searchReplaceAllFiles_1.searchReplaceAllFiles)('/path/to/project', 'CONTENT', 'test', true); mockFs_1.mockFs.readdir.mockRestore(); expect(mockFs_1.mockFs.readFileSync('/path/to/project/file.js')).toBe('before, test, after'); expect(changes).toBe(1); }); it('should throw on read error', async () => { mockFs_1.mockFs.readdir.mockImplementation((_p, _opts, cb) => { cb(new Error('some error'), null); }); await expect((0, searchReplaceAllFiles_1.searchReplaceAllFiles)('/path/to/project', 'CONTENT', 'test', true)).rejects.toThrow('some error'); mockFs_1.mockFs.readdir.mockRestore(); }); });