From bc8ad7422d32a940bab194173083a684adcc2706 Mon Sep 17 00:00:00 2001 From: Dimitry Date: Wed, 25 Jan 2017 01:31:44 +0400 Subject: RPC tests --- RPCTests/modules/utils.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 RPCTests/modules/utils.js (limited to 'RPCTests/modules/utils.js') diff --git a/RPCTests/modules/utils.js b/RPCTests/modules/utils.js new file mode 100644 index 000000000..763c9894e --- /dev/null +++ b/RPCTests/modules/utils.js @@ -0,0 +1,44 @@ +const fs = require('fs'); +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + +module.exports = { + + sleep: function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + }, + + + mkdir: function mkdir(path, callback, arg) { + try { + fs.mkdirSync(path); + } catch(e) { + if ( e.code != 'EEXIST' ) throw e; + } + callback(arg); + }, + + rmdir: function rmdir(path) { + if( fs.existsSync(path) ) { + fs.readdirSync(path).forEach(function(file,index){ + var curPath = path + "/" + file; + if(fs.lstatSync(curPath).isDirectory()) { // recurse + rmdir(curPath); + } else { // delete file + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(path); + } + }, + + readFile: function readFile(path, callback) { + fs.readFile(path, 'utf8', (err, data) => { callback (err, data) }); + }, + + writeFile: function writeFile(path, data) { + fs.writeFile(path, data, (err) => { if (err) throw err;}); + } +} + -- cgit