Change checkFileExists and touchFile from async to sync
This commit is contained in:
parent
2ee7011444
commit
c594d670de
|
@ -57,11 +57,11 @@ describe('The storage module', () => {
|
|||
mkdirp.sync(pluginPath);
|
||||
filenames.forEach((filename) => {
|
||||
h.touchFile(`${pluginPath}/${filename}.hpi`);
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).resolves.toBeTruthy();
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).toBeTruthy();
|
||||
});
|
||||
await Storage.removePlugins(filenames);
|
||||
filenames.forEach((filename) => {
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).resolves.toBeFalsy();
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -128,7 +128,7 @@ describe('The update module', () => {
|
|||
|
||||
manifest.plugins.deletes.forEach((filename) => {
|
||||
h.touchFile(`${pluginPath}/${filename}.hpi`);
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).resolves.toBeTruthy();
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).toBeTruthy();
|
||||
});
|
||||
|
||||
const response = await update.applyUpdates(manifest);
|
||||
|
@ -136,7 +136,7 @@ describe('The update module', () => {
|
|||
expect(update.updateInProgress).toBeFalsy();
|
||||
|
||||
manifest.plugins.deletes.forEach((filename) => {
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).resolves.toBeFalsy();
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).toBeFalsy();
|
||||
});
|
||||
expect(restartCalled).toBeTruthy();
|
||||
});
|
||||
|
@ -160,7 +160,7 @@ describe('The update module', () => {
|
|||
let response = await update.applyUpdates(manifest);
|
||||
expect(response).toBeTruthy();
|
||||
expect(update.updateInProgress).toBeFalsy();
|
||||
expect(h.checkFileExists(`${pluginPath}/daily-quote.hpi`)).resolves.toBeTruthy();
|
||||
expect(h.checkFileExists(`${pluginPath}/daily-quote.hpi`)).toBeTruthy();
|
||||
expect(restartCalled).toBeTruthy();
|
||||
});
|
||||
|
||||
|
@ -181,14 +181,14 @@ describe('The update module', () => {
|
|||
mkdirp.sync(pluginPath);
|
||||
manifest.plugins.deletes.forEach((filename) => {
|
||||
h.touchFile(`${pluginPath}/${filename}.hpi`);
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).resolves.toBeTruthy();
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).toBeTruthy();
|
||||
});
|
||||
let response = await update.applyUpdates(manifest);
|
||||
expect(response).toBeTruthy();
|
||||
expect(update.updateInProgress).toBeFalsy();
|
||||
expect(h.checkFileExists(`${pluginPath}/daily-quote.hpi`)).resolves.toBeTruthy();
|
||||
expect(h.checkFileExists(`${pluginPath}/daily-quote.hpi`)).toBeTruthy();
|
||||
manifest.plugins.deletes.forEach((filename) => {
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).resolves.toBeFalsy();
|
||||
expect(h.checkFileExists(`${pluginPath}/${filename}.hpi`)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,24 +2,18 @@
|
|||
* This module contains functions which are helpful for running across multiple
|
||||
* tests
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const { promisify } = require('util');
|
||||
const open = promisify(fs.open);
|
||||
const close = promisify(fs.close);
|
||||
const access = promisify(fs.access);
|
||||
import fs from 'fs';
|
||||
|
||||
export class Helpers {
|
||||
constructor () {
|
||||
}
|
||||
|
||||
checkFileExists(filename) {
|
||||
return access(filename, fs.F_OK, () => {
|
||||
return false;
|
||||
});
|
||||
return fs.existsSync(filename);
|
||||
}
|
||||
|
||||
touchFile(filename) {
|
||||
return open(filename, 'w').then(close);
|
||||
return fs.closeSync(fs.openSync(filename, 'w'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue