Update to use fs-extra to get recursive rm, updated tests

This commit is contained in:
Mandie Smith 2018-10-22 10:59:58 -04:00
parent 86debb6dec
commit f8e207653a
No known key found for this signature in database
GPG Key ID: B53135F06E8BFC28
2 changed files with 11 additions and 7 deletions

View File

@ -1,6 +1,6 @@
'use strict';
import fs from 'fs';
import fs from 'fs-extra';
import path from 'path';
import * as logger from 'winston';
@ -78,9 +78,9 @@ export default class Storage {
const retArray = [];
plugins.forEach((plugin) => {
retArray.push(new Promise((resolve, reject) => {
fs.rmdir(`${pluginPath}/${plugin}`, (err) => {
fs.remove(`${pluginPath}/${plugin}`, (err) => {
if(err) {
reject(err);
logger.debug(`${pluginPath}/${plugin} was not found.`);
}
logger.info(`${pluginPath}/${plugin} was removed`);
resolve(true);
@ -90,7 +90,7 @@ export default class Storage {
fs.unlink(`${pluginPath}/${plugin}.hpi`, (err) => {
if (err) {
reject(err);
logger.debug(`${pluginPath}/${plugin}.hpi was not found.`);
}
logger.info(`${pluginPath}/${plugin}.hpi was deleted`);
UI.publish(`Deleted ${plugin}.hpi`);

View File

@ -45,11 +45,15 @@ describe('The storage module', () => {
});
describe('removePlugins()', () => {
it('should return cleanly on empty plugins', () => {
expect(Storage.removePlugins());
it('should return cleanly on empty plugins', async () => {
expect(() => {
Storage.removePlugins();
}).not.toThrow();
});
it('should not error if file not found', async () => {
await expect(Storage.removePlugins(['not-found']));
expect(() => {
Storage.removePlugins(['not-found']);
}).not.toThrow();
});
it('should remove all files in a list', async () => {
const filenames = ['first', 'second', 'third', 'fourth'];