-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from trajano/devmenu
feat: removed react-native devmenu and only use expo-dev-client menu
- Loading branch information
Showing
23 changed files
with
485 additions
and
76 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
File renamed without changes.
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
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { DevMenuItemModule } from '@/devmenu/types'; | ||
import * as FileSystem from 'expo-file-system'; | ||
import { DevSettings } from 'react-native'; | ||
|
||
const deleteFilesRecursivelyAsync = async (directoryUri: string) => { | ||
// Get all items in the directory | ||
const items = await FileSystem.readDirectoryAsync(directoryUri); | ||
|
||
// Iterate over each item and check if it's a directory or a file | ||
for (const item of items) { | ||
const itemUri = `${directoryUri}/${item}`; | ||
const info = await FileSystem.getInfoAsync(itemUri); | ||
|
||
if (info.isDirectory) { | ||
// Recursively delete contents of the directory | ||
await deleteFilesRecursivelyAsync(itemUri); | ||
} | ||
|
||
// Delete the file or empty directory as long as it isn't the root | ||
if ( | ||
itemUri !== FileSystem.documentDirectory && | ||
itemUri !== FileSystem.cacheDirectory | ||
) { | ||
await FileSystem.deleteAsync(itemUri, { idempotent: true }); | ||
} | ||
} | ||
}; | ||
|
||
export default { | ||
name: 'Reset app', | ||
callback: async () => { | ||
await Promise.all([ | ||
deleteFilesRecursivelyAsync(FileSystem.documentDirectory!), | ||
deleteFilesRecursivelyAsync(FileSystem.cacheDirectory!), | ||
]); | ||
DevSettings.reload('application reset'); | ||
}, | ||
} satisfies DevMenuItemModule; |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { DevSettings } from 'react-native'; | ||
import * as FileSystem from 'expo-file-system'; | ||
import ClearAllData from './ClearAllData.devmenu'; | ||
|
||
jest.mock('expo-file-system', () => ({ | ||
readDirectoryAsync: jest.fn(), | ||
getInfoAsync: jest.fn(), | ||
deleteAsync: jest.fn(), | ||
documentDirectory: 'document-directory', | ||
cacheDirectory: 'cache-directory', | ||
})); | ||
|
||
jest.mock('react-native', () => ({ | ||
DevSettings: { | ||
reload: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('Reset App Module', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should delete all files and directories recursively and reload the app', async () => { | ||
// Mock file structure | ||
const mockFileStructure: Record<string, string[]> = { | ||
'document-directory': ['file1', 'dir1'], | ||
'document-directory/dir1': ['file2'], | ||
'cache-directory': ['file3'], | ||
}; | ||
|
||
// Mock FileSystem functions | ||
jest | ||
.mocked(FileSystem.readDirectoryAsync) | ||
.mockImplementation(async (dir) => { | ||
return mockFileStructure[dir] || []; | ||
}); | ||
|
||
jest.mocked(FileSystem.getInfoAsync).mockImplementation(async (path) => ({ | ||
isDirectory: path.includes('dir'), | ||
exists: true, | ||
modificationTime: Date.now(), | ||
uri: path, | ||
size: 42, | ||
})); | ||
|
||
jest.mocked(FileSystem.deleteAsync).mockResolvedValue(); | ||
|
||
// Execute the callback | ||
await ClearAllData.callback(); | ||
|
||
// Assert file deletion | ||
expect(FileSystem.deleteAsync).toHaveBeenCalledWith( | ||
'document-directory/file1', | ||
{ idempotent: true }, | ||
); | ||
expect(FileSystem.deleteAsync).toHaveBeenCalledWith( | ||
'document-directory/dir1/file2', | ||
{ idempotent: true }, | ||
); | ||
expect(FileSystem.deleteAsync).toHaveBeenCalledWith( | ||
'document-directory/dir1', | ||
{ idempotent: true }, | ||
); | ||
expect(FileSystem.deleteAsync).toHaveBeenCalledWith( | ||
'cache-directory/file3', | ||
{ idempotent: true }, | ||
); | ||
expect(FileSystem.deleteAsync).not.toHaveBeenCalledWith( | ||
'document-directory', | ||
{ idempotent: true }, | ||
); | ||
expect(FileSystem.deleteAsync).not.toHaveBeenCalledWith('cache-directory', { | ||
idempotent: true, | ||
}); | ||
|
||
// Assert app reload | ||
expect(DevSettings.reload).toHaveBeenCalledWith('application reset'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
import { DevMenuItemModule } from '@/devmenu/types'; | ||
|
||
export default { | ||
name: 'Clear AsyncStorage', | ||
callback: async () => { | ||
await AsyncStorage.clear(); | ||
}, | ||
} satisfies DevMenuItemModule; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import ClearAsyncStorageDevmenu from '@/devmenu/ClearAsyncStorage.devmenu'; | ||
|
||
test('ClearAsyncStorageDevmenu', async () => { | ||
await ClearAsyncStorageDevmenu.callback(); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { DevMenuItemModule } from '@/devmenu/types'; | ||
import * as FileSystem from 'expo-file-system'; | ||
|
||
const clearLogFilesByPrefixAndSuffixAsync = async ( | ||
prefix: string, | ||
suffix: string, | ||
): Promise<void> => { | ||
await Promise.all( | ||
(await FileSystem.readDirectoryAsync(FileSystem.documentDirectory!)) | ||
.filter((it) => it.startsWith(prefix) && it.endsWith(suffix)) | ||
.map((it) => FileSystem.documentDirectory + it) | ||
.map((it) => FileSystem.deleteAsync(it, { idempotent: true })), | ||
); | ||
}; | ||
|
||
export default { | ||
name: 'Clear Log Files', | ||
callback: async () => { | ||
await Promise.all([ | ||
clearLogFilesByPrefixAndSuffixAsync('logs_', '.txt'), | ||
clearLogFilesByPrefixAndSuffixAsync('background_fetch_', '.txt'), | ||
clearLogFilesByPrefixAndSuffixAsync('notification_', '.txt'), | ||
clearLogFilesByPrefixAndSuffixAsync('location_', '.txt'), | ||
]); | ||
}, | ||
} satisfies DevMenuItemModule; |
Oops, something went wrong.