Update to use fs-extra to get recursive rm, updated tests
This commit is contained in:
parent
86debb6dec
commit
f8e207653a
|
@ -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`);
|
||||
|
|
|
@ -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'];
|
||||
|
|
Loading…
Reference in New Issue