How to use fs.readdirSync method in istanbul

Best JavaScript code snippet using istanbul

load-plugins.spec.js

Source:load-plugins.spec.js Github

copy

Full Screen

1/* global describe:true, it:true */2// Test setup:3import { expect, NOOP, sinon } from '../test-setup';4// Dependencies:5import fs from 'fs';6import module from 'module';7import path from 'path';8import * as tractorLogger from 'tractor-logger';9import { TractorError } from 'tractor-error-handler';10// Under test:11import { loadPlugins } from './load-plugins';12describe('tractor-plugin-loader:', () => {13 describe('load-plugins:', () => {14 it('should do nothing if there is not any installed plugins', () => {15 let nodeModules = [];16 sinon.stub(fs, 'readdirSync').returns(nodeModules);17 sinon.stub(tractorLogger, 'info');18 let plugins = loadPlugins();19 expect(plugins.length).to.equal(0);20 fs.readdirSync.restore();21 tractorLogger.info.restore();22 });23 it('should create a plugin for each installed plugin', () => {24 let nodeModules = ['tractor-plugin-test'];25 let pluginModule = {};26 sinon.stub(fs, 'readdirSync').returns(nodeModules);27 sinon.stub(module, '_load').returns(pluginModule);28 sinon.stub(tractorLogger, 'info');29 let plugins = loadPlugins();30 expect(plugins.length).to.equal(1);31 expect(pluginModule.fullName).to.equal('tractor-plugin-test');32 expect(pluginModule.name).to.equal('test');33 fs.readdirSync.restore();34 module._load.restore();35 tractorLogger.info.restore();36 });37 it('should create a plugin for an ES2015 module', () => {38 let nodeModules = ['tractor-plugin-test'];39 let pluginModule = {40 default: {}41 };42 sinon.stub(fs, 'readdirSync').returns(nodeModules);43 sinon.stub(module, '_load').returns(pluginModule);44 sinon.stub(tractorLogger, 'info');45 let plugins = loadPlugins();46 expect(plugins.length).to.equal(1);47 fs.readdirSync.restore();48 module._load.restore();49 tractorLogger.info.restore();50 });51 it('should throw if the plugin cannot be loaded', () => {52 let nodeModules = ['tractor-plugin-test'];53 sinon.stub(fs, 'readdirSync').returns(nodeModules);54 sinon.stub(module, '_load').throws(new Error());55 sinon.stub(tractorLogger, 'info');56 expect(() => {57 loadPlugins();58 }).to.throw(TractorError, `could not require 'tractor-plugin-test'`);59 fs.readdirSync.restore();60 module._load.restore();61 tractorLogger.info.restore();62 });63 it('should decorate the `description` with display values', () => {64 let nodeModules = ['tractor-plugin-test-plugin'];65 let pluginModule = {};66 sinon.stub(fs, 'readdirSync').returns(nodeModules);67 sinon.stub(module, '_load').returns(pluginModule);68 sinon.stub(tractorLogger, 'info');69 let plugins = loadPlugins();70 let [test] = plugins;71 expect(test.description.name).to.equal('Test Plugin');72 expect(test.description.variableName).to.equal('testPlugin');73 expect(test.description.url).to.equal('test-plugin');74 fs.readdirSync.restore();75 module._load.restore();76 tractorLogger.info.restore();77 });78 it('should not overwrite an existing `description`', () => {79 let nodeModules = ['tractor-plugin-test-plugin'];80 let pluginModule = {81 description: {}82 };83 sinon.stub(fs, 'readdirSync').returns(nodeModules);84 sinon.stub(module, '_load').returns(pluginModule);85 sinon.stub(tractorLogger, 'info');86 let plugins = loadPlugins();87 let [test] = plugins;88 expect(test.description).to.equal(pluginModule.description);89 fs.readdirSync.restore();90 module._load.restore();91 tractorLogger.info.restore();92 });93 it('should decorate the `description` with the version', () => {94 let nodeModules = ['tractor-plugin-test-plugin'];95 let pluginModule = {};96 let pluginPackage = {97 version: '0.1.0'98 };99 sinon.stub(process, 'cwd').returns('');100 sinon.stub(fs, 'readdirSync').returns(nodeModules);101 sinon.stub(module, '_load')102 .withArgs('node_modules/tractor-plugin-test-plugin').returns(pluginModule)103 .withArgs('node_modules/tractor-plugin-test-plugin/package.json').returns(pluginPackage);104 sinon.stub(tractorLogger, 'info');105 let plugins = loadPlugins();106 let [test] = plugins;107 expect(test.description.version).to.equal('0.1.0');108 process.cwd.restore();109 fs.readdirSync.restore();110 module._load.restore();111 tractorLogger.info.restore();112 });113 it('should have a default `create` function that is a noop', () => {114 let nodeModules = ['tractor-plugin-test'];115 let pluginModule = {};116 sinon.stub(fs, 'readdirSync').returns(nodeModules);117 sinon.stub(module, '_load').returns(pluginModule);118 sinon.stub(tractorLogger, 'info');119 let plugins = loadPlugins();120 let [test] = plugins;121 expect(() => {122 test.create();123 }).to.not.throw();124 fs.readdirSync.restore();125 module._load.restore();126 tractorLogger.info.restore();127 });128 it('should not overwrite an existing `create` function', () => {129 let nodeModules = ['tractor-plugin-test'];130 let pluginModule = {131 create: NOOP132 };133 sinon.stub(fs, 'readdirSync').returns(nodeModules);134 sinon.stub(module, '_load').returns(pluginModule);135 sinon.stub(pluginModule, 'create');136 sinon.stub(tractorLogger, 'info');137 let plugins = loadPlugins();138 let [test] = plugins;139 test.create();140 expect(pluginModule.create).to.have.been.called();141 fs.readdirSync.restore();142 module._load.restore();143 tractorLogger.info.restore();144 });145 it('should have a default `init` function that is a noop', () => {146 let nodeModules = ['tractor-plugin-test'];147 let pluginModule = {};148 sinon.stub(fs, 'readdirSync').returns(nodeModules);149 sinon.stub(module, '_load').returns(pluginModule);150 sinon.stub(tractorLogger, 'info');151 let plugins = loadPlugins();152 let [test] = plugins;153 expect(() => {154 test.init();155 }).to.not.throw();156 fs.readdirSync.restore();157 module._load.restore();158 tractorLogger.info.restore();159 });160 it('should not overwrite an existing `init` function', () => {161 let nodeModules = ['tractor-plugin-test'];162 let pluginModule = {163 init: NOOP164 };165 sinon.stub(fs, 'readdirSync').returns(nodeModules);166 sinon.stub(module, '_load').returns(pluginModule);167 sinon.stub(pluginModule, 'init');168 sinon.stub(tractorLogger, 'info');169 let plugins = loadPlugins();170 let [test] = plugins;171 test.init();172 expect(pluginModule.init).to.have.been.called();173 fs.readdirSync.restore();174 module._load.restore();175 tractorLogger.info.restore();176 });177 it('should have a default `plugin` function that is a noop', () => {178 let nodeModules = ['tractor-plugin-test'];179 let pluginModule = {};180 sinon.stub(fs, 'readdirSync').returns(nodeModules);181 sinon.stub(module, '_load').returns(pluginModule);182 sinon.stub(tractorLogger, 'info');183 let plugins = loadPlugins();184 let [test] = plugins;185 expect(() => {186 test.plugin();187 }).to.not.throw();188 fs.readdirSync.restore();189 module._load.restore();190 tractorLogger.info.restore();191 });192 it('should not overwrite an existing `plugin` function', () => {193 let nodeModules = ['tractor-plugin-test'];194 let pluginModule = {195 plugin: NOOP196 };197 sinon.stub(fs, 'readdirSync').returns(nodeModules);198 sinon.stub(module, '_load').returns(pluginModule);199 sinon.stub(pluginModule, 'plugin');200 sinon.stub(tractorLogger, 'info');201 let plugins = loadPlugins();202 let [test] = plugins;203 test.plugin();204 expect(pluginModule.plugin).to.have.been.called();205 fs.readdirSync.restore();206 module._load.restore();207 tractorLogger.info.restore();208 });209 it('should have a default `run` function that is a noop', () => {210 let nodeModules = ['tractor-plugin-test'];211 let pluginModule = {};212 sinon.stub(fs, 'readdirSync').returns(nodeModules);213 sinon.stub(module, '_load').returns(pluginModule);214 sinon.stub(tractorLogger, 'info');215 let plugins = loadPlugins();216 let [test] = plugins;217 expect(() => {218 test.run();219 }).to.not.throw();220 fs.readdirSync.restore();221 module._load.restore();222 tractorLogger.info.restore();223 });224 it('should not overwrite an existing `run` function', () => {225 let nodeModules = ['tractor-plugin-test'];226 let pluginModule = {227 run: NOOP228 };229 sinon.stub(fs, 'readdirSync').returns(nodeModules);230 sinon.stub(module, '_load').returns(pluginModule);231 sinon.stub(pluginModule, 'run');232 sinon.stub(tractorLogger, 'info');233 let plugins = loadPlugins();234 let [test] = plugins;235 test.run();236 expect(pluginModule.run).to.have.been.called();237 fs.readdirSync.restore();238 module._load.restore();239 tractorLogger.info.restore();240 });241 it('should have a default `serve` function that is a noop', () => {242 let nodeModules = ['tractor-plugin-test'];243 let pluginModule = {};244 sinon.stub(fs, 'readdirSync').returns(nodeModules);245 sinon.stub(module, '_load').returns(pluginModule);246 sinon.stub(tractorLogger, 'info');247 let plugins = loadPlugins();248 let [test] = plugins;249 expect(() => {250 test.serve();251 }).to.not.throw();252 fs.readdirSync.restore();253 module._load.restore();254 tractorLogger.info.restore();255 });256 it('should not overwrite an existing `serve` function', () => {257 let nodeModules = ['tractor-plugin-test'];258 let pluginModule = {259 serve: NOOP260 };261 sinon.stub(fs, 'readdirSync').returns(nodeModules);262 sinon.stub(module, '_load').returns(pluginModule);263 sinon.stub(pluginModule, 'serve');264 sinon.stub(tractorLogger, 'info');265 let plugins = loadPlugins();266 let [test] = plugins;267 test.serve();268 expect(pluginModule.serve).to.have.been.called();269 fs.readdirSync.restore();270 module._load.restore();271 tractorLogger.info.restore();272 });273 it('should have a default `upgrade` function that is a noop', () => {274 let nodeModules = ['tractor-plugin-test'];275 let pluginModule = {};276 sinon.stub(fs, 'readdirSync').returns(nodeModules);277 sinon.stub(module, '_load').returns(pluginModule);278 sinon.stub(tractorLogger, 'info');279 let plugins = loadPlugins();280 let [test] = plugins;281 expect(() => {282 test.upgrade();283 }).to.not.throw();284 fs.readdirSync.restore();285 module._load.restore();286 tractorLogger.info.restore();287 });288 it('should not overwrite an existing `upgrade` function', () => {289 let nodeModules = ['tractor-plugin-test'];290 let pluginModule = {291 upgrade: NOOP292 };293 sinon.stub(fs, 'readdirSync').returns(nodeModules);294 sinon.stub(module, '_load').returns(pluginModule);295 sinon.stub(pluginModule, 'upgrade');296 sinon.stub(tractorLogger, 'info');297 let plugins = loadPlugins();298 let [test] = plugins;299 test.upgrade();300 expect(pluginModule.upgrade).to.have.been.called();301 fs.readdirSync.restore();302 module._load.restore();303 tractorLogger.info.restore();304 });305 it('should try to load the UI bundle and set the `hasUI` flag to true if it works', () => {306 let nodeModules = ['tractor-plugin-test'];307 let pluginModule = {};308 sinon.stub(fs, 'accessSync').returns(true);309 sinon.stub(fs, 'readdirSync').returns(nodeModules);310 sinon.stub(module, '_load').returns(pluginModule);311 sinon.stub(process, 'cwd').returns('.');312 sinon.stub(tractorLogger, 'info');313 let plugins = loadPlugins();314 let [test] = plugins;315 expect(test.script).to.equal(path.join('node_modules', 'tractor-plugin-test', 'dist', 'client', 'bundle.js'));316 expect(test.description.hasUI).to.equal(true);317 fs.accessSync.restore();318 fs.readdirSync.restore();319 module._load.restore();320 process.cwd.restore();321 tractorLogger.info.restore();322 });323 it('should try to load the UI bundle and set the `hasUI` flag to false if it fails', () => {324 let nodeModules = ['tractor-plugin-test'];325 let pluginModule = {};326 sinon.stub(fs, 'accessSync').throws(new Error());327 sinon.stub(fs, 'readdirSync').returns(nodeModules);328 sinon.stub(module, '_load').returns(pluginModule);329 sinon.stub(process, 'cwd').returns('.');330 sinon.stub(tractorLogger, 'info');331 let plugins = loadPlugins();332 let [test] = plugins;333 expect(test.description.hasUI).to.equal(false);334 fs.accessSync.restore();335 fs.readdirSync.restore();336 module._load.restore();337 process.cwd.restore();338 tractorLogger.info.restore();339 });340 });...

Full Screen

Full Screen

Images.js

Source:Images.js Github

copy

Full Screen

1import fs from 'fs'2export const getProjectsPaths = () => {3 let folders = fs.readdirSync('public/images/' + 'projects/')4 folders = folders.filter(item => !(/(^|\/)\.[^\/\.]/g).test(item));5 return folders;6}7export const getProjects = () => {8 let result = [];9 let folders = fs.readdirSync('public/images/projects/')10 folders = folders.filter(item => !(/(^|\/)\.[^\/\.]/g).test(item));11 folders.forEach(el => {12 let files = fs.readdirSync('public/images/projects/' + el + '/')13 files = files.filter(item => !(/(^|\/)\.[^\/\.]/g).test(item));14 const folderArr = el.split('-')15 const id = el;16 const name = folderArr[3]17 const year = folderArr[0]18 const temp = { id, name, year, cover: '/images/projects/' + el + '/' + files[0] }19 result.push(temp);20 })21 return result;22}23export const getProjectImages = (projectsID) => {24 let files = fs.readdirSync('public/images/' + 'projects/' + projectsID);25 files = files.filter(item => !(/(^|\/)\.[^\/\.]/g).test(item));26 files = files.filter(item => item != 'resized-50');27 files = files.map(el => '/images/projects/' + projectsID + '/' + el)28 return files;29}30// ------31export const getWorksImages = (category, id) => {32 let files = fs.readdirSync('public' + '/images/works/' + category + '/' + id);33 files = files.filter(item => !(/(^|\/)\.[^\/\.]/g).test(item));34 files = files.filter(item => item != 'resized-50');35 files = files.map(el => '/images/works/' + category + '/' + id + '/' + el)36 return files;37}38export const getWorksPaths = () => {39 let temp = []40 let folders = fs.readdirSync('public/images/works/')41 folders = folders.filter(item => !(/(^|\/)\.[^\/\.]/g).test(item));42 folders.forEach(el => {43 let folders2 = fs.readdirSync('public/images/works/' + el + '/')44 folders2 = folders2.filter(item => !(/(^|\/)\.[^\/\.]/g).test(item));45 temp.push({46 category: el,47 ids: folders248 });49 })50 return temp;51}52export const getWorks = () => {53 let result = [];54 let folders = fs.readdirSync('public/images/works/')55 folders = folders.filter(item => !(/(^|\/)\.[^\/\.]/g).test(item));56 folders.forEach(el => {57 let folders2 = fs.readdirSync('public/images/works/' + el + '/')58 folders2 = folders2.filter(item => !(/(^|\/)\.[^\/\.]/g).test(item));59 folders2.forEach(el2 => {60 let files = fs.readdirSync('public/images/works/' + el + '/' + el2 + '/')61 files = files.filter(item => !(/(^|\/)\.[^\/\.]/g).test(item));62 const folderArr = el2.split('-')63 const id = el + '/' + el2;64 const name = folderArr[3] || folderArr[1]65 const year = folderArr[0] || el66 const category = el67 const temp = { id, name, year, category, cover: '/images/works/' + el + '/' + el2 + '/' + files[0] }68 result.push(temp);69 });70 })71 return { categories: folders, works: result };...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

...28let projectsArray = [];29let technologies = ['css','javascript','php','jquery','python','data-modeling', 'final-project']30let level = ["beginner", "junior", "senior","semi-senior", "full-stack"]31let projects = []32fs.readdirSync("./css/beginner").forEach(e=>projects.push(String(e)))33fs.readdirSync("./css/career-support").forEach(e=>projects.push(String(e)))34fs.readdirSync("./css/junior").forEach(e=>projects.push(String(e)))35fs.readdirSync("./css/senior").forEach(e=>projects.push(String(e)))36fs.readdirSync("./data-modeling/beginner").forEach(e=>projects.push(String(e)))37fs.readdirSync("./final-project/full-stack").forEach(e=>projects.push(String(e)))38fs.readdirSync("./javascript/beginner").forEach(e=>projects.push(String(e)))39fs.readdirSync("./javascript/junior").forEach(e=>projects.push(String(e)))40fs.readdirSync("./javascript/semi-senior").forEach(e=>projects.push(String(e)))41fs.readdirSync("./jquery/beginner").forEach(e=>projects.push(String(e)))42fs.readdirSync("./php/begginer").forEach(e=>projects.push(String(e)))43fs.readdirSync("./php/junior").forEach(e=>projects.push(String(e)))44fs.readdirSync("./python/beginner").forEach(e=>projects.push(String(e)))45function search(route) {46 let folderList = fs.readdirSync(route);47console.log(folderList)48 folderList.forEach(folder=>{49 let newPath = route +'/'+ folder50 if (String(folder).toUpperCase().includes("README"))51 projectsArray.push({52 technology: newPath.split('/').find(dir => technologies.includes(dir.toLowerCase())),53 project_Name:newPath.split('/').find(dir => projects.includes(dir.toLowerCase())),54 difficulty:newPath.split('/').find(folder=> level.includes(folder.toLowerCase())),55 readMe:newPath56 })57 if (fs.lstatSync(newPath).isDirectory()===true) {58 search(newPath)59 }60 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var files = fs.readdirSync('./');3console.log(files);4var fs = require('fs');5var files = fs.readdirSync('./');6console.log(files);7var fs = require('fs');8var files = fs.readdirSync('./');9console.log(files);10var fs = require('fs');11var files = fs.readdirSync('./');12console.log(files);13var fs = require('fs');14var files = fs.readdirSync('./');15console.log(files);16var fs = require('fs');17var files = fs.readdirSync('./');18console.log(files);19var fs = require('fs');20var files = fs.readdirSync('./');21console.log(files);22var fs = require('fs');23var files = fs.readdirSync('./');24console.log(files);25var fs = require('fs');26var files = fs.readdirSync('./');27console.log(files);28var fs = require('fs');29var files = fs.readdirSync('./');30console.log(files);31var fs = require('fs');32var files = fs.readdirSync('./');33console.log(files);34var fs = require('fs');35var files = fs.readdirSync('./');36console.log(files);37var fs = require('fs');38var files = fs.readdirSync('./');39console.log(files);40var fs = require('fs');41var files = fs.readdirSync('./');42console.log(files);43var fs = require('fs');44var files = fs.readdirSync('./');45console.log(files);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { readdirSync } from 'fs';2const files = readdirSync('./src');3console.log(files);4import { readdir } from 'fs';5readdir('./src', (err, files) => {6 if (err) {7 console.error(err);8 return;9 }10 console.log(files);11});12import { readdirSync } from 'fs';13const files = readdirSync('./src');14console.log(files);15import { readdir } from 'fs';16readdir('./src', (err, files) => {17 if (err) {18 console.error(err);19 return;20 }21 console.log(files);22});

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var path = require('path');3var dirPath = path.join(__dirname, 'test');4var files = fs.readdirSync(dirPath);5console.log(files);6var fs = require('fs');7var path = require('path');8var dirPath = path.join(__dirname, 'test');9var files = fs.readdirSync(dirPath);10console.log(files);11var fs = require('fs');12var path = require('path');13var dirPath = path.join(__dirname, 'test');14var files = fs.readdirSync(dirPath);15console.log(files);16var time;17var start = document.getElementById('start');18var stop = document.getElementById('stop');19var reset = document.getElementById('reset');20start.addEventListener('click', function() {21 time = setTimeout(function() {22 console.log('hello');23 }, 1000);24});25stop.addEventListener('click', function() {26 clearTimeout(time);27});28reset.addEventListener('click', function() {29 clearTimeout(time);30});31var time;32var start = document.getElementById('start');33var stop = document.getElementById('stop');34var reset = document.getElementById('reset');35start.addEventListener('click', function() {36 time = setInterval(function() {37 console.log('hello');38 }, 1000);39});40stop.addEventListener('click', function() {41 clearInterval(time);42});43reset.addEventListener('click', function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2const path = require('path');3const dir = path.join(__dirname, 'test');4const files = fs.readdirSync(dir);5console.log(files);6const fs = require('fs');7const path = require('path');8const dir = path.join(__dirname, 'test');9const files = fs.readdirSync(dir);10console.log(files);11const fs = require('fs');12const path = require('path');13const dir = path.join(__dirname, 'test');14const files = fs.readdirSync(dir);15console.log(files);16const fs = require('fs');17const path = require('path');18const dir = path.join(__dirname, 'test');19const files = fs.readdirSync(dir);20console.log(files);21const fs = require('fs');22const path = require('path');23const dir = path.join(__dirname, 'test');24const files = fs.readdirSync(dir);25console.log(files);

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var path = require('path');3var files = fs.readdirSync(path.join(__dirname, 'path/to/directory'));4console.log(files);5FN:1,(anonymous_0)6FN:3,(anonymous_1)7FN:4,(anonymous_2)8FN:5,(anonymous_3)9FN:6,(anonymous_4)10FN:7,(anonymous_5)11FN:8,(anonymous_6)12FN:9,(anonymous_7)13FN:10,(anonymous_8)14FN:11,(anonymous_9)15FN:12,(anonymous_10)16FN:13,(anonymous_11)17FN:14,(anonymous_12)18FN:15,(anonymous_13)19FN:16,(anonymous_14)20FN:17,(anonymous_15)21FN:18,(anonymous_16)22FN:19,(anonymous_17)23FN:20,(anonymous_18)24FN:21,(anonymous_19)25FN:22,(anonymous_20)26FN:23,(anonymous_21)27FN:24,(anonymous_22)28FN:25,(anonymous_23)29FN:26,(anonymous_24)30FN:27,(anonymous_25)31FN:28,(anonymous_26)32FN:29,(anonymous_27)33FN:30,(anonymous_28)34FN:31,(anonymous_29)35FN:32,(anonymous_30)36FN:33,(anonymous_31)37FN:34,(anonymous_32)38FN:35,(anonymous_33)39FN:36,(anonymous_34)40FN:37,(anonymous_35)41FN:38,(anonymous_36)42FN:39,(anonymous_37)43FN:40,(anonymous_38)44FN:41,(anonymous_39)45FN:42,(anonymous_40)46FN:43,(anonymous_41)47FN:44,(anonymous_42)48FN:45,(anonymous_43)49FN:46,(anonymous_44)50FN:47,(anonymous_45)51FN:48,(anonymous_46)52FN:49,(anonymous_47)53FN:50,(anonymous_48)54FN:51,(anonymous_49)55FN:52,(anonymous_50)56FN:53,(anonymous_51)57FN:54,(anonymous_52)

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 istanbul 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