How to use readDirPromise method in Nightwatch

Best JavaScript code snippet using nightwatch

generate.js

Source:generate.js Github

copy

Full Screen

...173 const generateComponent = async (component) => {174 const componentsPath = resolve('components')175 const componentsComponentPath = path.join(componentsPath, component)176 let componentsComponentErr, componentsComponentDir177 ;[componentsComponentErr, componentsComponentDir] = await to(readDirPromise(componentsComponentPath))178 if (componentsComponentErr) {179 failLog(`${componentsComponentPath}打开失败。`)180 return181 }182 const componentDemoPath = path.join(componentsPath, component, 'demo')183 let demos = []184 let componentDemoMdErr, componentDemoMdPaths185 ;[componentDemoMdErr, componentDemoMdPaths] = await to(readDirPromise(componentDemoPath))186 if (componentDemoMdErr) {187 generalLog(`${componentDemoPath}不存在,已跳过。`)188 } else {189 const vaildComponentDemoMdPaths = getFilesByExtension(componentDemoMdPaths, '.md')190 vaildComponentDemoMdPaths && await Promise.all(vaildComponentDemoMdPaths.map(componentDemoMdPath => {191 const route = path.join(componentDemoPath, componentDemoMdPath)192 const name = componentDemoMdPath.replace('.md', '')193 return readDemoMds(route, component, name)194 })).then(v => {195 demos = v196 })197 }198 const siteDocPath = path.join(resolve('site'), 'components', component)199 generateDomes(path.join(siteDocPath, 'demo'), demos)200 generateNormalVue(componentsComponentPath, componentsComponentDir, siteDocPath, 'component', demos)201 }202 components.forEach(component => {203 ignore.components.indexOf(component) === -1 && generateComponent(component)204 })205}206const generateDocs = (docs) => {207 const generateDoc = async (doc) => {208 const docsPath = resolve('docs')209 const docsDocPath = path.join(docsPath, doc)210 let docsDocErr, docsDocDir211 ;[docsDocErr, docsDocDir] = await to(readDirPromise(docsDocPath))212 if (docsDocErr) {213 generalLog(`${docsDocDir}不是文件夹,已跳过。`)214 return215 }216 const siteDocPath = path.join(resolve('site'), 'docs', doc)217 generateNormalVue(docsDocPath, docsDocDir, siteDocPath)218 }219 docs.forEach(doc => {220 ignore.docs.indexOf(doc) === -1 && generateDoc(doc)221 })222}223const generateComponentsRouterConfig = async () => {224 const sitePath = resolve('site')225 let importString = `import Vue from 'vue'\nimport Router from 'vue-router'\n`226 let configString = ''227 const redirectString = ` { path: '/', redirect: '/docs/development/first/zh' },\n`228 await Promise.all(['components', 'docs'].map(async dir => {229 let err, components230 ;[err, components] = await to(readDirPromise(path.join(sitePath, dir)))231 err !== null && console.log(err)232 await Promise.all(components.map(async component => {233 let err, files234 ;[err, files] = await to(readDirPromise(path.join(sitePath, dir, component)))235 err !== null && console.log(err)236 getFilesByExtension(files, '.vue').forEach(file => {237 let lang = file.indexOf('zh-CN') > -1 ? 'zh' : 'en'238 let mdName = file.split('.')[0]239 let dirName = dir.slice(0, 4)240 let name = generateCamelName(dirName, component, mdName, lang)241 importString += `import ${name} from './${dir}/${component}/${file}'\n`242 configString += ` {\n path: '/${dir}/${component}/${mdName}/${lang}',\n component: ${name},\n name: '${name}'\n },\n`243 })244 }))245 }))246 configString = redirectString + configString.substring(0, configString.length - 2)247 importString += 'Vue.use(Router)\n'248 const config = '\nlet router = new Router({\n routes: [\n' + configString + '\n ]\n})\n\nexport default router\n'249 stableWriteFile(sitePath, 'router.js', importString + config)250}251const generate = async (params) => {252 const cDir = await readDirPromise(resolve('components'))253 const dDir = await readDirPromise(resolve('docs'))254 if (params[0] === '-a') {255 generateDocs(dDir)256 generateComponents(cDir)257 } else if (params[0] === '-c') {258 generateComponents(cDir)259 } else if (params[0] === '-d') {260 generateDocs(dDir)261 } else if (params[0] === '-r') {262 generateComponentsRouterConfig().catch(err => console.log(err))263 }264}265const params = process.argv.splice(2)...

Full Screen

Full Screen

readAppDeployConfig.js

Source:readAppDeployConfig.js Github

copy

Full Screen

1/**2 * Created by krasilneg on 25.04.19.3 */4const fs = require('fs');5const path = require('path');6const {7 readConfigFiles, merge8} = require('core/util/read');9const {promisify} = require('util');10const configReader = require('lib/config-reader');11const read = promisify(configReader);12const readdirPromise = promisify(fs.readdir);13const isConfig = fn => ['.json', '.yml'].includes(path.extname(fn));14const joinPath = (...pths) => fn => path.join(...pths, fn);15const isBasename = nm => fn => path.basename(fn, path.extname(fn)) === nm;16const readdir = pth => readdirPromise(pth)17 .then(files => files.filter(isConfig).map(joinPath(pth)))18 .catch(() => []);19const mergeConfigs = (data) => {20 let result = {};21 Object.keys(data).forEach((key) => {22 result = merge(result, data[key]);23 });24 return result;25};26function readModulesConfigs(modulesPath) {27 let result = {};28 const configs = [];29 return readdirPromise(modulesPath)30 .then((files) => {31 let subdirPromise = Promise.resolve();32 files.forEach((fn) => {33 if (isConfig(fn)) {34 configs.push(fn);35 } else {36 subdirPromise = subdirPromise37 .then(() => readdir(path.join(modulesPath, fn)))38 .then(files => files.filter(isConfig))39 .then((configFiles) => {40 if (!configFiles.length) {41 return;42 }43 return readConfigFiles(configFiles)44 .then((configFilesData) => {45 result[fn] = mergeConfigs(configFilesData);46 });47 });48 }49 });50 return subdirPromise;51 })52 .then(() => readConfigFiles(configs.map(joinPath(modulesPath))))53 .then((configsData) => {54 result = merge(configsData, result);55 return result;56 })57 .catch(() => {58 return {};59 });60}61module.exports = (appPath) => {62 let config = {};63 const configDirs = [64 readdir(appPath),65 readdir(path.join(appPath, 'deploy'))66 ];67 return Promise.all(configDirs)68 .then((dirs) => {69 const [rootFiles, deployFiles] = dirs;70 return readConfigFiles([...rootFiles.filter(isBasename('deploy')), ...deployFiles]);71 })72 .then((results) => {73 config = results.deploy || {};74 delete results.deploy;75 config = merge(config, mergeConfigs(results));76 config.modules = config.modules || {};77 return readModulesConfigs(path.join(appPath, 'deploy', 'modules'));78 })79 .then((modulesConfig) => {80 config.modules = merge(config.modules, modulesConfig);81 return read(config, appPath);82 });...

Full Screen

Full Screen

email-browse.js

Source:email-browse.js Github

copy

Full Screen

1const { promisify } = require('util');2const { readdir } = require('fs');3const { join } = require('path');4const emailPreviewer = require('./email-preview');5const readdirPromise = promisify(readdir);6/**7 * Scans directory hierachy for email files (.eml.gz).8 * @param {string} dirPath Absolute path to directory to scan.9 * @return {array} Non-nested list of absolute paths to files.10 * @private11 */12async function getEmailFileNamesFromDir(dirPath) {13 try {14 const allFiles = await readdirPromise(dirPath);15 const emails = allFiles16 .filter(fileName => fileName.match(/^\d+.eml.gz$/))17 .sort()18 .reverse()19 .map(fileName => join(dirPath, fileName));20 return emails;21 } catch (error) {22 if (error.code === 'ENOTDIR') {23 console.warn('Found misplaced file at ', dirPath);24 } else {25 throw error;26 }27 }28 return [];29}30/**31 * Get list of emails32 */33async function browse(rootPath, limit = 20, offset = 0) {34 const allFiles = await readdirPromise(rootPath);35 const monthDirs = allFiles36 .filter(fileName => fileName.match(/^20\d{2}-(0[1-9]|1[0-2])$/))37 .sort()38 .reverse();39 const emails = [];40 for (let i = 0; i < monthDirs.length; ++i) {41 const dirPath = join(rootPath, monthDirs[i]);42 const foundEmails = await getEmailFileNamesFromDir(dirPath);43 if (offset >= foundEmails.length) {44 offset -= foundEmails.length;45 continue;46 }47 if (offset > 0) {48 foundEmails.splice(0, offset);49 offset = 0;50 }51 if (foundEmails.length < limit) {52 emails.push(...foundEmails);53 limit -= foundEmails.length;54 continue;55 }56 const neededEmails = foundEmails.splice(0, limit);57 emails.push(...neededEmails);58 break;59 }60 return await emailPreviewer(rootPath, emails);61}...

Full Screen

Full Screen

cb-to-promises.js

Source:cb-to-promises.js Github

copy

Full Screen

...21})22const sequence = () => Promise.resolve()23 .then(() => writePromise('test1.txt', 'Hello World'))24 .then(() => console.log('created'))25 .then(() => readDirPromise(__dirname))26 .then(console.log)27 .then(() => tick(1))28 .then(() => readPromise('test1.txt', 'utf8'))29 .then(console.log)30 .then(() => tick(1))31 .then(() => unlinkPromise('test1.txt'))32 .then(() => console.log('deleted'))33 .catch(console.error)34// sequence()35const asyncSequence = async () => {36 await writePromise('test1.txt', 'Hello World')37 console.log('created')38 const dir = await readDirPromise(__dirname)39 console.log(dir)40 await tick(1)41 const content = await readPromise('test1.txt', 'utf8')42 console.log(content)43 await tick(1)44 await unlinkPromise('test1.txt')45 console.log('deleted')46 return Promise.resolve()47}48// try {49// asyncSequence()50// } catch (err) {51// console.log(err)52// }...

Full Screen

Full Screen

files.js

Source:files.js Github

copy

Full Screen

1const fs = require("fs");2const util = require("util");3const bluebird = require("bluebird");4// let readdirPromise = util.promisify(fs.readdir);5// let readFilePromise = util.promisify(fs.readFile);6bluebird.promisifyAll(fs, { suffix: 'Promise' });7async function readDir(path) {8 try {9 console.time('Read all files');10 // const dataFromFiles = [];11 const filesNames = await fs.readdirPromise(path);12 let readFilesPromises = []13 // for (let i = 0; i < filesNames.length; i++) {14 // readFilesPromises.push(fs.readFilePromise(`${path}/${filesNames[i]}`));15 // }16 const dataFromFiles = 17 await bluebird.map(filesNames, (fileName)=>{18 return fs.readFilePromise(`${path}/${fileName}`)19 }, {20 concurrency:60021 })22 // filesNames.forEach(async (fileName) => {23 // })24 console.timeEnd('Read all files');25 console.log(dataFromFiles.length);26 } catch (e) {27 console.timeEnd('Read all files');28 console.error(e);29 }30}...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1const path = require('path');2const fs = require('fs');3const util = require('util');45module.exports = {6 async loadModules() {7 const rootName = path.dirname(require.main.filename);8 const directoryModulesPath = path.join(rootName, 'modules');9 const readdirPromise = util.promisify(fs.readdir);10 let files = [];11 try {12 files = await readdirPromise(directoryModulesPath);13 for (let file of files) {14 let fullPath = path.join(directoryModulesPath, file, 'index');15 ////////////////////////CARGO EL MÓDULO////////////////////////16 require(fullPath)();17 }18 } catch (err) {19 console.log("******Error cargando los módulos**********")20 console.log(err);21 }22 readdirPromise(directoryModulesPath)23 }24 ...

Full Screen

Full Screen

loadImages.js

Source:loadImages.js Github

copy

Full Screen

1import { remote } from 'electron'2import { readdir, readFile } from 'fs'3import get from 'lodash/get'4import Promise from "bluebird";5import Image from './classes/image';6const readdirPromise = Promise.promisify(readdir)7const readFilePromise = Promise.promisify(readFile)8function loadImages() {9 const directory = get(remote.dialog.showOpenDialog({properties: ['openDirectory']}), '0')10 if (!directory) {11 return Promise.resolve()12 }13 return readdirPromise(directory)14 .then(items => {15 const images = []16 for (let item of items) {17 const path = directory + "/" + item18 images.push(readFilePromise(path).then(data => {19 return new Image(path)20 }))21 }22 return Promise.all(images)23 })24}...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1const util = require("util");2const fs = require("fs");3const readdirPromise = util.promisify(fs.readdir);4const readFilePromise = util.promisify(fs.readFile);5const fileExt = ".json";6const getFolderFilesList = path =>7 readdirPromise(path).then(folders =>8 folders.filter(folder => !folder.includes("."))9 );10const getFilesList = path =>11 readdirPromise(path).then(files =>12 files.filter(file => file.includes(fileExt))13 );14const getFile = path => readFilePromise(path, "utf8");15module.exports = {16 getFolderFilesList,17 getFile,18 getFilesList...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 'Demo test Google' : function (browser) {3 .waitForElementVisible('body', 1000)4 .assert.title('Google')5 .assert.visible('input[type=text]')6 .setValue('input[type=text]', 'nightwatch')7 .waitForElementVisible('button[name=btnG]', 1000)8 .click('button[name=btnG]')9 .pause(1000)10 .assert.containsText('#main', 'Night Watch')11 .end();12 }13};14module.exports = {15 selenium : {16 cli_args : {17 }18 },19 test_settings : {20 default : {21 screenshots : {22 },23 desiredCapabilities: {24 }25 },26 chrome : {27 desiredCapabilities: {28 }29 }30 }31}

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2module.exports = {3 'Demo test Google' : function (browser) {4 .waitForElementVisible('body', 1000)5 .setValue('input[type=text]', 'nightwatch')6 .waitForElementVisible('button[name=btnG]', 1000)7 .click('button[name=btnG]')8 .pause(1000)9 .assert.containsText('#main', 'Night Watch')10 .end();11 }12};13{14 "selenium" : {

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 'Demo test Nightwatch' : function (browser) {3 .waitForElementVisible('body', 1000)4 .assert.title('Nightwatch.js')5 .assert.visible('input[type=text]')6 .setValue('input[type=text]', 'nightwatch')7 .waitForElementVisible('button[name=btnG]', 1000)8 .click('button[name=btnG]')9 .pause(1000)10 .assert.containsText('#main', 'Nightwatch.js')11 .end();12 }13};14{15 "selenium" : {

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 'demo test Nightwatch' : function (browser) {3 .waitForElementVisible('body', 1000)4 .setValue('input[type=text]', 'nightwatch')5 .waitForElementVisible('button[name=btnG]', 1000)6 .click('button[name=btnG]')7 .pause(1000)8 .assert.containsText('#main', 'Night Watch')9 .end();10 }11};12var seleniumServer = require('selenium-server');13var chromedriver = require('chromedriver');14var geckodriver = require('geckodriver');15module.exports = {16 'selenium' : {17 'cli_args' : {18 }19 },20 'test_settings' : {21 'default' : {22 'screenshots' : {23 },24 'desiredCapabilities': {25 }26 },27 'chrome' : {28 'desiredCapabilities': {29 }30 },31 'firefox' : {32 'desiredCapabilities': {33 }34 },35 'edge' : {

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 'Test Case' : function (browser) {3 .readDirPromise('path/to/directory')4 .then(function(result) {5 console.log(result);6 })7 .end();8 }9};10{11 "selenium" : {

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 'Test case' : function (client) {3 .readDirPromise('/path/to/directory')4 .then(function (files) {5 console.log(files);6 });7 }8};9module.exports = {10 'Test case' : function (client) {11 .readFilePromise('/path/to/file')12 .then(function (data) {13 console.log(data);14 });15 }16};17module.exports = {18 'Test case' : function (client) {19 .writeFilePromise('/path/to/file', 'data to be written')20 .then(function (data) {21 console.log(data);22 });23 }24};25module.exports = {26 'Test case' : function (client) {27 .appendFilePromise('/path/to/file', 'data to be appended')28 .then(function (data) {29 console.log(data);30 });31 }32};33module.exports = {34 'Test case' : function (client) {35 .mkdirPromise('/path/to/directory')36 .then(function (data) {37 console.log(data);38 });39 }40};

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 'demo test' : function (client) {3 client.readDirPromise('C:\\Users\\johndoe\\Desktop\\test').then(function(result) {4 console.log(result);5 });6 }7};8module.exports = {9 'demo test' : function (client) {10 client.readfilePromise('C:\\Users\\johndoe\\Desktop\\test\\file1.txt').then(function(result) {11 console.log(result);12 });13 }14};15module.exports = {16 'demo test' : function (client) {17 client.readJsonPromise('C:\\Users\\johndoe\\Desktop\\test\\file2.json').then(function(result) {18 console.log(result);19 });20 }21};22{23}24module.exports = {25 'demo test' : function (client) {26 client.writefilePromise('C:\\Users\\johndoe\\Desktop

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