Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should raises an error when pass invalid arguments', () => {
// $ExpectError: first argument is required
makeDirectoryAsync();
// $ExpectError: first argument must be a string
makeDirectoryAsync(69);
// $ExpectError: second argument must be an object
makeDirectoryAsync('', 69);
// $ExpectError: 'abc' is missing in options
makeDirectoryAsync('', { abc: 'test' });
makeDirectoryAsync('', {
// $ExpectError
intermediates: 'need boolean',
});
});
});
it('should raises an error when pass invalid arguments', () => {
// $ExpectError: first argument is required
makeDirectoryAsync();
// $ExpectError: first argument must be a string
makeDirectoryAsync(69);
// $ExpectError: second argument must be an object
makeDirectoryAsync('', 69);
// $ExpectError: 'abc' is missing in options
makeDirectoryAsync('', { abc: 'test' });
makeDirectoryAsync('', {
// $ExpectError
intermediates: 'need boolean',
});
});
});
it('should passes when used properly', () => {
makeDirectoryAsync('fileUri').then(fileInfo => {
(fileInfo: void);
// $ExpectError: check any
(fileInfo: number);
});
makeDirectoryAsync('fileUri', { intermediates: true });
});
it('should raises an error when pass invalid arguments', () => {
// $ExpectError: first argument is required
makeDirectoryAsync();
// $ExpectError: first argument must be a string
makeDirectoryAsync(69);
// $ExpectError: second argument must be an object
makeDirectoryAsync('', 69);
// $ExpectError: 'abc' is missing in options
makeDirectoryAsync('', { abc: 'test' });
makeDirectoryAsync('', {
// $ExpectError
intermediates: 'need boolean',
});
});
});
async _init () {
if (await this._checkCacheDirExists()) return
try {
await FileSystem.makeDirectoryAsync(this._path, { intermediates: true })
} catch (e) {
// Expo has a bug where `makeDirectoryAsync` can error, even though it succesfully
// created the directory. See:
// https://github.com/expo/expo/issues/2050
// https://forums.expo.io/t/makedirectoryasync-error-could-not-be-created/11916
//
// To tolerate this, after getting an error, we check whether the directory
// now exist, swallowing the error if so, rethrowing if not.
if (await this._checkCacheDirExists()) return
throw e
}
}
async function ensureDirectory(directory: string): Promise {
try {
await FileSystem.makeDirectoryAsync(directory);
} catch (error) {}
}
.then(({ exists }) => {
if (!exists) {
FileSystem.makeDirectoryAsync(storageDirectoryUri, { intermediates: true });
}
});
};
withCallback(callback, async () => {
await FileSystem.makeDirectoryAsync(baseFolder, {
intermediates: true,
});
const baseFolderLength = baseFolder.length;
const files = await FileSystem.readDirectoryAsync(baseFolder);
return files.map(fileUri =>
decodeURIComponent(fileUri.substring(baseFolderLength)),
);
});