Best JavaScript code snippet using ava
L0.ts
Source: L0.ts
...11 });12 after(function () {13 });14 it('Search simple pattern', (done) => {15 let test = ff.findFiles(path.join(data, '*.log'));16 assert(test.length === 2);17 assert(test[0] === posixFormat(path.join(data, 'a.log')));18 assert(test[1] === posixFormat(path.join(data, 'b.log')));19 done();20 });21 it('Search multiple patterns', (done) => {22 let test = ff.findFiles([path.join(data, '*.log'), path.join(data, '*.txt')]);23 assert(test.length === 4);24 assert(test[0] === posixFormat(path.join(data, 'a.log')));25 assert(test[1] === posixFormat(path.join(data, 'b.log')));26 assert(test[2] === posixFormat(path.join(data, 'a.txt')));27 assert(test[3] === posixFormat(path.join(data, 'b.txt')));28 done();29 });30 it('Search simple pattern with (+:) filter', (done) => {31 let test = ff.findFiles('+:' + path.join(data, '*.log'));32 assert(test.length === 2);33 assert(test[0] === posixFormat(path.join(data, 'a.log')));34 assert(test[1] === posixFormat(path.join(data, 'b.log')));35 done();36 });37 it('Search multiple patterns with (+:) filter', (done) => {38 let test = ff.findFiles(['+:' + path.join(data, '*.log'), '+:' + path.join(data, '*.txt')]);39 assert(test.length === 4);40 assert(test[0] === posixFormat(path.join(data, 'a.log')));41 assert(test[1] === posixFormat(path.join(data, 'b.log')));42 assert(test[2] === posixFormat(path.join(data, 'a.txt')));43 assert(test[3] === posixFormat(path.join(data, 'b.txt')));44 done();45 });46 it('Search simple pattern with (+:) filter and (-:) filter', (done) => {47 let test = ff.findFiles(['+:' + path.join(data, '*.log'), '-:' + path.join(data, 'a*')]);48 assert(test.length === 1);49 assert(test[0] === posixFormat(path.join(data, 'b.log')));50 done();51 });52 it('Search simple pattern with exclude files', (done) => {53 let test = ff.findFiles(['+:' + path.join(data, '*'), '-:' + path.join(data, 'a*')]);54 assert(test.length === 3);55 done();56 });57 it('Search recursively with include files', (done) => {58 let test = ff.findFiles(['+:' + path.join(data, '**', '*.log')]);59 assert(test.length === 4);60 done();61 });62 it('Search recursively with exclude files', (done) => {63 let test = ff.findFiles([path.join(data, '**', '*'), '-:' + path.join(data, '**', '*.log')]);64 assert(test.length === 6);65 done();66 });67 it('Search recursively with include files and exclude files', (done) => {68 let test = ff.findFiles(['+:' + path.join(data, '**', '*.log'), '-:' + path.join(data, '**', 'a*')]);69 assert(test.length === 2);70 done();71 });72 it('Search recursively with exclude files with ignore dir', (done) => {73 let test = ff.findFiles([path.join(data, '**', '*'), '-:' + path.join(data, '**', '*.log')], true);74 assert(test.length === 7);75 done();76 });77 it('Search simple pattern (relative path) starting with ..', (done) => {78 let relativePath = path.relative(process.cwd(), path.join(__dirname, 'data', '*.log'));79 let test = ff.findFiles(relativePath);80 assert(test.length === 2);81 assert(test[0] === posixFormat(path.join(data, 'a.log')));82 assert(test[1] === posixFormat(path.join(data, 'b.log')));83 done();84 });85 it('Search simple pattern (relative path)', (done) => {86 let relativePath = path.relative(process.cwd(), path.join(__dirname, 'data', '*.log'));87 let test = ff.findFiles(path.join('L0', '..' , relativePath));88 assert(test.length === 2);89 assert(test[0] === posixFormat(path.join(data, 'a.log')));90 assert(test[1] === posixFormat(path.join(data, 'b.log')));91 done();92 });93 it('Search pattern seperated by semi-colon(delimiter)', (done) => {94 let test = ff.findFiles(path.join(data, '*.log') + ";" +path.join(data, '*.txt'));95 assert(test.length === 4);96 assert(test[0] === posixFormat(path.join(data, 'a.log')));97 assert(test[1] === posixFormat(path.join(data, 'b.log')));98 assert(test[2] === posixFormat(path.join(data, 'a.txt')));99 assert(test[3] === posixFormat(path.join(data, 'b.txt')));100 done();101 });102 103 it('Search pattern seperated by semi-colon(delimiter)', (done) => {104 let test = ff.findFiles(path.join(data, 'a*') + ";-:" + path.join(data, 'a.txt'));105 assert(test.length === 1);106 assert(test[0] === posixFormat(path.join(data, 'a.log')));107 done();108 });109});110function posixFormat(p: string): string {111 let path_regex = /\/\//;112 p = p.replace(/\\/g, '/');113 while (p.match(path_regex)) {114 p = p.replace(path_regex, '/');115 }116 return p;...
parse.js
Source: parse.js
...17 '@jayway',18 'tds-styleguide',19 'src'20 )21 const configFile = findFiles(/tds\.config\.js/, tree, true)22 const config = {23 ...configDefaults,24 ...(configFile ? require(configFile) : {})25 }26 return {27 ...config,28 configFile,29 path: root,30 distPath: config.distPath || 'dist',31 webpack:32 typeof config.webpack !== 'undefined'33 ? config.webpack34 : findFiles(/webpack.config/, tree, true),35 babel:36 typeof config.babel !== 'undefined'37 ? config.babel38 : findFiles(/babelrc/, tree, true),39 entry:40 config.entry ||41 findFiles(42 /(index|App|app)\.(t|j)sx?$/,43 resolveTreePath(tree, 'src'),44 true45 ) ||46 findFiles(/(index|App|app)\.(t|j)sx?$/, tree, true),47 documentation: findFiles(48 /.mdx?/,49 resolveTreePath(tree, /(docs|documentation)/), // TODO: /**/*.md globbing?50 true51 ),52 alias: {53 ...(hasTdsUI ? { ui: hasTdsUI.path } : {}),54 ...(hasTdsStyleguide ? { styleguide: hasTdsStyleguide.path } : {}),55 ...(config.alias || {})56 },57 cssIndex: findFiles(58 /index\.(s?css|less|styl)/,59 resolveTreePath(tree, 'src', /base|patterns/),60 true61 ),62 src: findDirectories('src', tree)63 ? shallow64 ? true65 : findSrc(resolveTreePath(tree, 'src'), '')66 : false,67 tdsUI: hasTdsUI && hasTdsUI.path,68 tdsStyleguide: !!hasTdsStyleguide,69 ui: findDirectories(70 'tds-ui',71 resolveTreePath(nodeModulesTree, '@jayway'),72 true73 )74 ? shallow75 ? true76 : findSrc(hasTdsUI, 'ui/')77 : false,78 nodeModules: findDirectories(79 /^(react|react-dom|redux|react-redux|graphql|react-router-dom|react-router|react-apollo)$/,80 nodeModulesTree81 ).map(dir => dir.name),82 ...config,83 graphql: {84 queries: findFiles(85 /\.(gql|graphql)/,86 resolveTreePath(tree, 'src', /(gql|graphql)/, 'queries')87 ),88 mutations: findFiles(89 /\.(gql|graphql)/,90 resolveTreePath(tree, 'src', /(gql|graphql)/, 'mutations')91 ),92 types:93 // findFiles(94 // /types.(j|t)sx?$/,95 // resolveTreePath(tree, 'src', /(gql|graphql)/)96 // ) ||97 findFiles(98 /\.(gql|graphql)$/,99 resolveTreePath(tree, 'src', /(gql|graphql)/, 'types')100 ),101 resolvers:102 findFiles(103 /resolvers\.(j|t)sx?$/,104 resolveTreePath(tree, 'src', /(gql|graphql)/)105 ) ||106 findFiles(107 /(index|resolvers)\.(j|t)sx?$/,108 resolveTreePath(tree, 'src', /(gql|graphql)/, 'resolvers')109 ) ||110 findFiles(111 /\.(j|t)sx?$/,112 resolveTreePath(tree, 'src', /(gql|graphql)/, 'resolvers')113 ),114 schema: findFiles(115 /(index|schema)\.(j|t)sx?$/,116 resolveTreePath(tree, 'src', /gql|graphql/),117 true118 ),119 ...(config.graphql || {})120 },121 store: {122 actions: findFiles(123 /\.(j|t)sx?$/,124 resolveTreePath(tree, 'src', /(store|redux)/, 'actions')125 ),126 middlewares: [127 ...(findFiles(128 /middlewares\.(j|t)sx?$/,129 resolveTreePath(tree, 'src', /(store|redux)/)130 ) ||131 findFiles(132 /\.(j|t)sx?$/,133 resolveTreePath(tree, 'src', /(store|redux)/, 'middlewares')134 ) ||135 []),136 ...(hasTdsUI137 ? [path.join(hasTdsUI.path, 'store', 'middlewares', 'index.js')]138 : [])139 ],140 reducers: [141 ...(findFiles(142 /reducers\.(j|t)sx?$/,143 resolveTreePath(tree, 'src', /(store|redux)/)144 ) ||145 findFiles(146 /\.(j|t)sx?$/,147 resolveTreePath(tree, 'src', /(store|redux)/, 'reducers')148 ) ||149 []),150 ...(hasTdsUI151 ? [path.join(hasTdsUI.path, 'store/reducers/index.js')]152 : [])153 ],154 store: findFiles(155 /(index|store)\.(j|t)sx?$/,156 resolveTreePath(tree, 'src', /(store|redux)/)157 ),158 ...(config.redux || {})159 },160 server: {161 cron: findFiles(162 /cron\.js$/,163 resolveTreePath(tree, 'src', 'server'),164 true165 ),166 middlewares:167 findFiles(168 /middlewares\.(j|t)sx?$/,169 resolveTreePath(tree, 'src', 'server')170 ) ||171 findFiles(172 /\.(j|t)sx?$/,173 resolveTreePath(tree, 'src', 'server', 'middlewares')174 ),175 ...(config.server || {})176 }177 }...
FindFiles.test.js
Source: FindFiles.test.js
1import test from 'ava'2import sinon from 'sinon'3import glob from 'glob'4import minimatch from 'minimatch'5import FindFiles from './../lib/streams/FindFiles'6const files = [7 'test1.html',8 'test2.js',9 'node_modules/test3.html',10 'target/test4.html',11 'target/test5.js'12]13const globSyncStub = sinon.stub(glob, 'sync', (pattern) => {14 return files.filter((file) => minimatch(file, pattern))15})16test.after('cleanup', t => globSyncStub.restore())17test('should return the only html file from target dir', async t => {18 const findFiles = new FindFiles({objectMode: true}, 'target/**/*.html')19 let count = 020 await findFiles21 .on('data', file => {22 count++23 return t.is(file, files[3])24 })25 .on('finish', () => t.is(count, 1))26})27test('should return multiple files from target dir', async t => {28 const findFiles = new FindFiles({objectMode: true}, 'target/**/*.{html,js}')29 let count = 330 await findFiles31 .on('data', file => t.is(file, files[count++]))32})33test('should return multiple files from target dir', async t => {34 const findFiles = new FindFiles({objectMode: true}, 'target/**/*.{html,js}')35 let count = 336 await findFiles37 .on('data', file => t.is(file, files[count++]))38})39test('should return results line by line', async t => {40 const findFiles = new FindFiles({objectMode: true}, '*')41 let count = 042 await findFiles43 .on('data', file => t.is(file, files[count++]))44 .on('finish', () => t.is(count, 2))...
findFiles_test.js
Source: findFiles_test.js
...8 });9 });10 describe('Finding files', function(){11 it('Should find files', function(){12 var files = findFiles(__dirname + '/../lib');13 assert.notEqual(files.indexOf(path.normalize(__dirname + '/../lib') + '/findFiles.js'), -1);14 });15 it('Should find files recursively', function(){16 var files = findFiles(__dirname + '/../', true);17 assert.notEqual(files.indexOf(path.normalize(__dirname + '/../lib') + '/findFiles.js'), -1);18 });19 });...
findfiles-ui.profile.js
Source: findfiles-ui.profile.js
1// Copyright 2015 MathWorks, Inc.2var profile = {3 // The location of top level packages declared as dependencies in the UI4 // code. You'll see these in the AMD define() function. For example:5 // define(["dojo/store/Memory", "dijit/Dialog", "MW/Log"], function(...6 packages: [{7 name: "findfiles-ui",8 location: "findfiles-ui"9 }],10 // The JavaScript code will get minimized into layer files. dojo generates11 // files to: [releaseDir]/[package name]/[layer file name].12 layers: {13 "findfiles-ui/findfiles-ui": {14 copyright: "copyright.txt",15 include: [16 // Add your main application modules first17 "findfiles-ui/FindFilesUi"18 ],19 exclude: [20 "findfiles-ui/browsercheck"21 ]22 }23 }...
Using AI Code Generation
1var availableFiles = require("./availableFiles");2var files = new availableFiles();3files.findFiles('D:/test', function (err, files) {4 if (err) {5 console.log(err);6 }7 else {8 console.log(files);9 }10});
Using AI Code Generation
1var fs = require('fs');2var path = require('path');3var dir = path.join(__dirname, 'test');4var files = fs.readdirSync(dir);5var filesWithTxtExtension = files.filter((file) => path.extname(file) === '.txt');6console.log(filesWithTxtExtension);7Your name to display (optional):8Your name to display (optional):9var fs = require('fs');10var path = require('path');11var dir = path.join(__dirname, 'test');12var files = fs.readdirSync(dir);13var filesWithTxtExtension = files.filter((file) => path.extname(file) === '.txt');14console.log(filesWithTxtExtension);15Your name to display (optional):
Check out the latest blogs from LambdaTest on this topic:
Screenshots! These handy snippets have become indispensable to our daily business as well as personal life. Considering how mandatory they are for everyone in these modern times, every OS and a well-designed game, make sure to deliver a built in feature where screenshots are facilitated. However, capturing a screen is one thing, but the ability of highlighting the content is another. There are many third party editing tools available to annotate our snippets each having their own uses in a business workflow. But when we have to take screenshots, we get confused which tool to use. Some tools are dedicated to taking best possible screenshots of whole desktop screen yet some are browser based capable of taking screenshots of the webpages opened in the browsers. Some have ability to integrate with your development process, where as some are so useful that there integration ability can be easily overlooked.
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Automation Testing Tutorial.
Working in IT, we have often heard the term Virtual Machines. Developers working on client machines have used VMs to do the necessary stuffs at the client machines. Virtual machines are an environment or an operating system which when installed on a workstation, simulates an actual hardware. The person using the virtual machine gets the same experience as they would have on that dedicated system. Before moving on to how to setup virtual machine in your system, let’s discuss why it is used.
There is no other automation framework in the market that is more used for automating web testing tasks than Selenium and one of the key functionalities is to take Screenshot in Selenium. However taking full page screenshots across different browsers using Selenium is a unique challenge that many selenium beginners struggle with. In this post we will help you out and dive a little deeper on how we can take full page screenshots of webpages across different browser especially to check for cross browser compatibility of layout.
Cross browser compatibility can simply be summed up as a war between testers and developers versus the world wide web. Sometimes I feel that to achieve browser compatibility, you may need to sell your soul to devil while performing a sacrificial ritual. Even then some API plugins won’t work.(XD)
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!