How to use clearDirSync method in apimocker

Best JavaScript code snippet using apimocker

utils.js

Source:utils.js Github

copy

Full Screen

...65/**66 * 删除目录67 * @param dir68 */69function clearDirSync(dir) {70 var files = [];71 if (_fs2.default.existsSync(dir)) {72 files = _fs2.default.readdirSync(dir);73 files.forEach(function (file, index) {74 var curPath = dir + '/' + file;75 if (_fs2.default.statSync(curPath).isDirectory()) {76 clearDirSync(curPath);77 } else {78 _fs2.default.unlinkSync(curPath);79 }80 });81 _fs2.default.rmdirSync(dir);82 }83}8485/**86 * 规范日志87 */88var colorconsole = exports.colorconsole = {89 trace: function trace() {90 var _console; ...

Full Screen

Full Screen

fs.js

Source:fs.js Github

copy

Full Screen

1const fs = require('fs')2const path = require('path')3const copydirSync = (source, target) => {4 if (!fs.existsSync(target)) {5 fs.mkdirSync(target)6 }7 const filePaths = fs.readdirSync(source, 'utf-8')8 filePaths.forEach(fileName => {9 const from = path.resolve(source, fileName)10 const to = path.resolve(target, fileName)11 if (fs.statSync(from).isDirectory()) {12 copydirSync(from, to)13 } else {14 const readStream = fs.createReadStream(from)15 const writeStream = fs.createWriteStream(to)16 readStream.pipe(writeStream)17 // fs.copyFileSync(from, to)18 }19 })20}21const cleardirSync = (dirPath, { ignore = [] }) => {22 const filePaths = fs.readdirSync(dirPath, 'utf-8')23 const ignoreFiles = ignore.length > 0 ? ignore : null24 filePaths.forEach(fileName => {25 if (!ignoreFiles || ignoreFiles.indexOf(fileName) === -1) {26 const delPath = path.resolve(dirPath, fileName)27 if (fs.statSync(delPath).isDirectory()) {28 cleardirSync(delPath, { ignore })29 } else {30 fs.unlinkSync(delPath)31 }32 }33 })34}35module.exports = {36 existsSync: fs.existsSync,37 mkdirSync: fs.mkdirSync,38 rmdirSync: fs.rmdirSync,39 readdirSync: fs.readdirSync,40 copydirSync: copydirSync,41 cleardirSync: cleardirSync...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run apimocker automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful