-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace FileSystem wrapper object with functions from our turbomodule (…
…#530) * Rewrote check for null turbomodule * Removed dependency on react-native-file-access, leave it for test fixture
- Loading branch information
1 parent
8285b38
commit 77f7558
Showing
15 changed files
with
207 additions
and
247 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
packages/platforms/react-native/__mocks__/file-native.ts
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,102 @@ | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 alpha0010 | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
* https://github.com/alpha0010/react-native-file-access/blob/7179426e701fa6e54bda6c2a753cfe31a4a08293/LICENSE | ||
*/ | ||
|
||
// Copied from v3.0.4: | ||
// https://github.com/alpha0010/react-native-file-access/blob/7179426e701fa6e54bda6c2a753cfe31a4a08293/jest/react-native-file-access.ts | ||
|
||
/* eslint-disable */ | ||
/* global jest */ | ||
|
||
export const Dirs = { | ||
CacheDir: '/mock/CacheDir', | ||
DocumentDir: '/mock/DocumentDir', | ||
}; | ||
|
||
const DIR_MARKER = '__dir__'; | ||
|
||
class FileSystemMock { | ||
/** | ||
* Data store for mock filesystem. | ||
*/ | ||
public filesystem = new Map<string, string>(); | ||
|
||
/** | ||
* Check if a path exists. | ||
*/ | ||
public exists = jest.fn(async (path: string) => this.filesystem.has(path)); | ||
|
||
/** | ||
* Check if a path is a directory. | ||
*/ | ||
public isDir = jest.fn(async (path: string) => !this.filesystem.has(path)); | ||
|
||
/** | ||
* List files in a directory. | ||
*/ | ||
public ls = jest.fn(async (_path: string) => ['file1', 'file2']); | ||
|
||
/** | ||
* Make a directory. | ||
* | ||
* This is a noop as the mock file system does not differentiate between files | ||
* and directories | ||
* | ||
* NOTE: this method was added by bugsnag | ||
*/ | ||
public mkdir = jest.fn(async (path: string) => { | ||
this.filesystem.set(path, DIR_MARKER) | ||
return path | ||
}) | ||
|
||
/** | ||
* Read the content of a file. | ||
*/ | ||
public readFile = jest.fn(async (path: string) => this.getFileOrThrow(path)); | ||
|
||
/** | ||
* Delete a file. | ||
*/ | ||
public unlink = jest.fn(async (path: string) => { | ||
this.filesystem.delete(path); | ||
}); | ||
|
||
/** | ||
* Write content to a file. | ||
*/ | ||
public writeFile = jest.fn(async (path: string, data: string) => { | ||
this.filesystem.set(path, data); | ||
}); | ||
|
||
private getFileOrThrow(path: string): string { | ||
const data = this.filesystem.get(path); | ||
if (data == null) { | ||
throw new Error(`File ${path} not found`); | ||
} | ||
return data; | ||
} | ||
} | ||
|
||
export const FileSystem = new FileSystemMock(); |
228 changes: 0 additions & 228 deletions
228
packages/platforms/react-native/__mocks__/react-native-file-access.ts
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
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
Oops, something went wrong.