How to use fs.lstat method in Cypress

Best JavaScript code snippet using cypress

strainer.js

Source:strainer.js Github

copy

Full Screen

1#!/usr/local/bin/lycheejs-helper env:node2const _fs = require('fs');3const _path = require('path');4const _CWD = process.env.STRAINER_CWD || process.cwd();5const _ROOT = process.env.LYCHEEJS_ROOT || '/opt/lycheejs';6const lychee = require(_ROOT + '/libraries/crux/build/node/dist.js')(_ROOT);7if (process.argv.includes('--autocomplete')) {8 console.log = function() {};9 console.info = function() {};10 console.warn = function() {};11 console.error = function() {};12}13/*14 * USAGE15 */16const _print_autocomplete = function(action, project, flag) {17 let actions = [ 'check', 'simulate', 'transcribe' ];18 let flags = [ '--debug' ];19 let libraries = _fs.readdirSync(_ROOT + '/libraries')20 .sort()21 .map(val => '/libraries/' + val)22 .filter(val => _fs.existsSync(_ROOT + val + '/lychee.pkg'));23 let projects = _fs.readdirSync(_ROOT + '/projects')24 .sort()25 .map(val => '/projects/' + val)26 .filter(val => _fs.existsSync(_ROOT + val + '/lychee.pkg'));27 let suggestions = [];28 let has_action = actions.find(a => a === action);29 let has_project = libraries.find(l => l === project) || projects.find(p => p === project);30 let has_flag = flags.find(f => f === flag);31 if (has_action && has_project && has_flag) {32 // Nothing to suggest33 } else if (has_action && has_project && flag) {34 suggestions = flags.filter(f => f.startsWith(flag));35 } else if (has_action && has_project) {36 suggestions = flags;37 } else if (has_action && project) {38 suggestions.push.apply(suggestions, libraries.filter(l => l.startsWith(project)));39 suggestions.push.apply(suggestions, projects.filter(p => p.startsWith(project)));40 } else if (has_action) {41 suggestions.push.apply(suggestions, libraries);42 suggestions.push.apply(suggestions, projects);43 } else if (action) {44 suggestions = actions.filter(a => a.startsWith(action));45 } else {46 suggestions = actions;47 }48 return suggestions.sort();49};50const _print_help = function() {51 let libraries = _fs.readdirSync(_ROOT + '/libraries')52 .sort()53 .map(val => '/libraries/' + val)54 .filter(val => _fs.existsSync(_ROOT + val + '/lychee.pkg'));55 let projects = _fs.readdirSync(_ROOT + '/projects')56 .sort()57 .map(val => '/projects/' + val)58 .filter(val => _fs.existsSync(_ROOT + val + '/lychee.pkg'));59 console.log('');60 console.info('lychee.js ' + lychee.VERSION + ' Strainer');61 console.log('');62 console.log('Detected lychee.js Installation: "' + lychee.ROOT.lychee + '"');63 console.log('');64 console.log('Usage: lycheejs-strainer [Action] [Library/Project] [Flag]');65 console.log('');66 console.log('');67 console.log('Available Actions:');68 console.log('');69 console.log(' check Check a Project or Library and generate API Knowledge. ');70 console.log(' simulate Simulate a Project or Library. ');71 console.log(' transcribe Transcribe a Project or Library from API Knowledge into Code.');72 console.log('');73 console.log('Available Libraries:');74 console.log('');75 libraries.forEach(library => console.log(' ' + library));76 console.log('');77 console.log('Available Projects:');78 console.log('');79 projects.forEach(project => console.log(' ' + project));80 console.log('');81 console.log('Available Flags:');82 console.log('');83 console.log(' --debug Enable debug messages.');84 console.log('');85 console.log('Examples:');86 console.log('');87 console.log(' lycheejs-strainer check /libraries/lychee; ');88 console.log(' lycheejs-strainer simulate /libraries/lychee; ');89 console.log('');90 console.log(' lycheejs-strainer transcribe /projects/pong /projects/tmp;');91 console.log(' lycheejs-strainer transcribe /projects/tmp /projects/pong;');92 console.log('');93};94const _bootup = function(settings) {95 console.info('BOOTUP (' + process.pid + ')');96 lychee.ROOT.project = lychee.ROOT.lychee + '/libraries/strainer';97 lychee.init(null);98 lychee.pkg('build', 'node/main', environment => {99 lychee.init(environment, {100 debug: settings.debug === true,101 sandbox: settings.debug === true ? false : true102 }, sandbox => {103 if (sandbox !== null) {104 let lychee = sandbox.lychee;105 let strainer = sandbox.strainer;106 // Show more debug messages107 lychee.debug = settings.debug === true;108 // This allows using #MAIN in JSON files109 sandbox.MAIN = new strainer.Main(settings);110 sandbox.MAIN.bind('destroy', code => process.exit(code));111 sandbox.MAIN.init();112 const _on_process_error = function() {113 sandbox.MAIN.destroy();114 process.exit(1);115 };116 process.on('SIGHUP', _on_process_error);117 process.on('SIGINT', _on_process_error);118 process.on('SIGQUIT', _on_process_error);119 process.on('SIGABRT', _on_process_error);120 process.on('SIGTERM', _on_process_error);121 process.on('error', _on_process_error);122 process.on('exit', code => {});123 } else {124 console.error('BOOTUP FAILURE');125 process.exit(1);126 }127 });128 });129};130if (process.argv.includes('--autocomplete')) {131 let tmp1 = process.argv.indexOf('--autocomplete');132 let words = process.argv.slice(tmp1 + 1);133 let result = _print_autocomplete.apply(null, words);134 process.stdout.write(result.join(' '));135 process.exit(0);136 return;137}138const _SETTINGS = (function() {139 let args = process.argv.slice(2).filter(val => val !== '');140 let settings = {141 cwd: _CWD,142 action: null,143 library: null,144 project: null,145 debug: false146 };147 let action = args.find(val => /^(check|simulate|transcribe)$/g.test(val));148 let project = args.find(val => /^\/(libraries|projects)\/([A-Za-z0-9-_/]+)$/g.test(val));149 let debug_flag = args.find(val => /--([debug]{5})/g.test(val));150 if (action === 'check' || action === 'simulate') {151 settings.action = action;152 let path = args.find(val => val.includes('/'));153 if (project !== undefined) {154 try {155 let stat1 = _fs.lstatSync(_ROOT + project);156 let stat2 = _fs.lstatSync(_ROOT + project + '/lychee.pkg');157 if (stat1.isSymbolicLink()) {158 let tmp = _fs.realpathSync(_ROOT + project);159 let stat3 = _fs.lstatSync(tmp);160 let stat4 = _fs.lstatSync(tmp + '/lychee.pkg');161 if (stat3.isDirectory() && stat4.isFile()) {162 settings.project = project;163 }164 } else if (stat1.isDirectory()) {165 if (stat2.isFile()) {166 settings.project = project;167 }168 }169 } catch (err) {170 settings.project = null;171 }172 } else if (path !== undefined) {173 let project = path;174 try {175 let stat1 = _fs.lstatSync(project);176 let stat2 = _fs.lstatSync(project + '/lychee.pkg');177 if (stat1.isSymbolicLink()) {178 let tmp = _fs.realpathSync(_ROOT + project);179 let stat3 = _fs.lstatSync(tmp);180 let stat4 = _fs.lstatSync(tmp + '/lychee.pkg');181 if (stat3.isDirectory() && stat4.isFile()) {182 settings.project = project;183 }184 } else if (stat1.isDirectory()) {185 if (stat2.isFile()) {186 settings.project = project;187 }188 }189 } catch (err) {190 settings.project = null;191 }192 }193 } else if (action === 'transcribe') {194 settings.action = action;195 let paths = args.filter(val => /^\/(libraries|projects)\/([A-Za-z0-9-_/]+)$/g.test(val));196 if (paths.length === 2) {197 let library = paths[0];198 let project = paths[1];199 if (library !== undefined) {200 try {201 let stat1 = _fs.lstatSync(_ROOT + library);202 let stat2 = _fs.lstatSync(_ROOT + library + '/lychee.pkg');203 if (stat1.isSymbolicLink()) {204 let tmp = _fs.realpathSync(_ROOT + library);205 let stat3 = _fs.lstatSync(tmp);206 let stat4 = _fs.lstatSync(tmp + '/lychee.pkg');207 if (stat3.isDirectory() && stat4.isFile()) {208 settings.library = library;209 }210 } else if (stat1.isDirectory()) {211 if (stat2.isFile()) {212 settings.library = library;213 }214 }215 } catch (err) {216 settings.library = null;217 }218 }219 if (project !== undefined) {220 try {221 let stat1 = _fs.lstatSync(_ROOT + project);222 let stat2 = _fs.lstatSync(_ROOT + project + '/lychee.pkg');223 if (stat1.isDirectory() === false && stat2.isFile() === false) {224 settings.project = project;225 }226 } catch (err) {227 if (err.code === 'ENOENT') {228 settings.project = project;229 } else {230 settings.project = null;231 }232 }233 }234 }235 }236 if (debug_flag !== undefined) {237 settings.debug = true;238 }239 return settings;240})();241(function(settings) {242 /*243 * IMPLEMENTATION244 */245 let action = settings.action;246 let has_project = settings.project !== null;247 let has_library = settings.library !== null;248 if (action === 'check' && has_project) {249 _bootup({250 cwd: settings.cwd,251 action: settings.action,252 debug: settings.debug === true,253 project: settings.project254 });255 } else if (action === 'simulate' && has_project) {256 _bootup({257 cwd: settings.cwd,258 action: settings.action,259 debug: settings.debug === true,260 project: settings.project261 });262 } else if (action === 'transcribe' && has_project && has_library) {263 _bootup({264 cwd: settings.cwd,265 action: settings.action,266 debug: settings.debug === true,267 library: settings.library,268 project: settings.project269 });270 } else {271 console.error('PARAMETERS FAILURE');272 _print_help();273 process.exit(1);274 }...

Full Screen

Full Screen

static-files-api-service-spec.js

Source:static-files-api-service-spec.js Github

copy

Full Screen

1// Copyright 2016, EMC, Inc.2/* jshint node:true */3"use strict";4describe("Http.Services.Api.StaticFiles", function () {5 var path;6 var staticFilesApiService;7 var waterline;8 before("Http.Services.Api.StaticFiles before", function() {9 helper.setupInjector([10 helper.require("/lib/services/static-files-api-service.js")11 ]);12 staticFilesApiService = helper.injector.get("Http.Services.Api.StaticFiles");13 path = helper.injector.get('path');14 waterline = helper.injector.get('Services.Waterline');15 waterline.skus = {16 findOne:function() {}17 };18 this.sandbox = sinon.sandbox.create();19 });20 afterEach("Http.Services.Api.StaticFiles afterEach", function() {21 this.sandbox.restore();22 });23 describe("pairSkupackIds", function() {24 var nodeFs;25 before(function() {26 nodeFs = helper.injector.get('fs');27 sinon.stub(nodeFs, 'lstatAsync');28 sinon.stub(nodeFs, 'readdirAsync');29 this.sandbox.stub(waterline.skus, 'findOne');30 });31 beforeEach(function() {32 nodeFs.lstatAsync.reset();33 nodeFs.readdirAsync.reset();34 });35 after(function () {36 nodeFs.lstatAsync.restore();37 nodeFs.readdirAsync.restore();38 });39 it('should return an id:sku pair given valid directories and database', function() {40 nodeFs.readdirAsync.resolves(['567432']);41 nodeFs.lstatAsync.resolves({ isDirectory: function() { return true; }});42 waterline.skus.findOne.resolves({43 id: '567432',44 name: 'testSku'45 });46 return staticFilesApiService.pairSkupackIds([]).then(function(value) {47 expect(nodeFs.readdirAsync).to.have.been.called;48 expect(nodeFs.lstatAsync).to.have.been.called;49 expect(waterline.skus.findOne).to.have.been.called;50 expect(value).to.deep.equal({'567432': 'testSku'});51 });52 });53 it('returns {} when there is no sku data in the database', function() {54 nodeFs.readdirAsync.resolves(['123']);55 nodeFs.lstatAsync.resolves({ isDirectory: function() { return true; }});56 var stubFind = sinon.stub(waterline.skus, "findOne");57 stubFind.rejects(new Error('Error: no available sku in the db'));58 return staticFilesApiService.pairSkupackIds([]).then(function(value) {59 expect(nodeFs.readdirAsync).to.have.been.called;60 expect(nodeFs.lstatAsync).to.have.been.called;61 expect(waterline.skus.findOne).to.have.been.called;62 expect(value).to.deep.equal({});63 });64 });65 });66 describe("walkDirectory", function() {67 it('returns an array of file names following "static" in the path', function() {68 var dirPath = path.join("spec/mocks/static");69 var result = [ 70 { uri: 'found' },71 { uri: 'foundFile2' }72 ];73 return staticFilesApiService.walkDirectory(dirPath).then(function(value) {74 expect(value).to.deep.equal(result);75 });76 });77 it('returns an array of file names following "skupack.d" in the path', function() {78 var dirPath = "spec/mocks/skupack.d";79 var result = [80 {81 sku: "mocks",82 uri: "sku-id/static/found-2"83 },84 {85 sku: "mocks",86 uri: "sku-id/static/common/found-3"87 }88 ];89 return staticFilesApiService.walkDirectory(dirPath).then(function(value) {90 expect(value).to.deep.equal(result);91 });92 });93 it('returns [] when provided a bad path', function() {94 var dirPath;95 var result = [];96 return staticFilesApiService.walkDirectory(dirPath).then(function(value) {97 expect(value).to.deep.equal(result);98 });99 });100 });101 describe("getAllStaticFiles", function() {102 var nodeFs;103 before(function() {104 nodeFs = helper.injector.get('fs');105 sinon.stub(nodeFs, 'lstatAsync');106 sinon.stub(staticFilesApiService, 'pairSkupackIds');107 sinon.stub(staticFilesApiService, 'walkDirectory');108 });109 beforeEach(function() {110 nodeFs.lstatAsync.reset();111 });112 after(function () {113 nodeFs.lstatAsync.restore();114 });115 it('returns a single array of objects with static file data', function() {116 var result = [117 {118 "uri": "found"119 },120 {121 "uri": "foundFile2"122 },123 {124 "sku": "testSku",125 "uri": "found-2"126 },127 {128 "sku": "testSku",129 "uri": "common/found-3"130 }131 ];132 var pair = {133 '567432': 'testSku'134 };135 var walkFirst = [136 {137 uri: 'found'138 },139 {140 uri: 'foundFile2'141 }142 ];143 var walkSecond = [144 {145 sku: "567432",146 uri: "found-2"147 },148 {149 sku: "567432",150 uri: "common/found-3"151 }152 ];153 var walkThird = [];154 staticFilesApiService.pairSkupackIds.resolves(pair);155 staticFilesApiService.walkDirectory156 .onFirstCall().resolves(walkFirst)157 .onSecondCall().resolves(walkSecond)158 .onThirdCall().resolves(walkThird);159 return staticFilesApiService.getAllStaticFiles().then(function(value) {160 expect(value).to.deep.equal(result);161 });162 });163 it('returns [] given no valid dirs to walk or those dirs are empty', function() {164 nodeFs.lstatAsync.resolves({ isDirectory: function() { return false; }});165 staticFilesApiService.walkDirectory.resolves([]);166 return staticFilesApiService.getAllStaticFiles().then(function(value) {167 expect(value).to.deep.equal([]);168 });169 });170 });...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

...22 }23 }24 ),25 // test fs.lstat, fs.mkdir, fs.rmdir26 fs.lstat(path.join(__dirname, 'test-dir')).then(27 () => Promise.reject(),28 () => Promise.resolve(true)29 ).then(30 () => fs.mkdir(path.join(__dirname, 'test-dir', 'quick', 'brown', 'fox'))31 ).then(32 () => fs.lstat(path.join(__dirname, 'test-dir', 'quick', 'brown', 'fox'))33 ).then(34 () => fs.rmdir(path.join(__dirname, 'test-dir'))35 ).then(36 () => fs.lstat(path.join(__dirname, 'test-dir')).catch(37 err => err.code === 'ENOENT' ? Promise.resolve(true) : Promise.reject()38 )39 ),40 // test fs.lstatSync, fs.mkdirSync, fs.rmdirSync41 new Promise(42 (resolve, reject) => {43 try {44 fs.lstatSync(path.join(__dirname, 'test-dir-sync'));45 return reject();46 } catch (err) {47 // continue without error48 }49 fs.mkdirSync(path.join(__dirname, 'test-dir-sync', 'quick', 'brown', 'fox'));50 fs.lstatSync(path.join(__dirname, 'test-dir-sync', 'quick', 'brown', 'fox'));51 fs.rmdirSync(path.join(__dirname, 'test-dir-sync'));52 try {53 fs.lstatSync(path.join(__dirname, 'test-dir-sync'));54 return reject();55 } catch (err) {56 if (err.code !== 'ENOENT') {57 return reject();58 }59 }60 return resolve(true);61 }62 ),63 // test fs.lstat, fs.touchFile, fs.copyFile, fs.unlink, fs.rmdir64 fs.lstat(path.join(__dirname, 'test-file')).then(65 () => Promise.reject(),66 () => Promise.resolve(true)67 ).then(68 () => fs.lstat(path.join(__dirname, 'test-file', 'quick', 'brown', 'fox.file'))69 ).then(70 () => Promise.reject(),71 () => Promise.resolve(true)72 ).then(73 () => fs.touchFile(path.join(__dirname, 'test-file', 'quick', 'brown', 'fox.file'))74 ).then(75 () => fs.copyFile(path.join(__dirname, 'test-file', 'quick', 'brown', 'fox.file'), path.join(__dirname, 'test-file', 'quick', 'brown', 'fox.copy'))76 ).then(77 () => fs.copydir(path.join(__dirname, 'test-file', 'quick', 'brown'), path.join(__dirname, 'test-file', 'quick', 'beige'))78 ).then(79 () => fs.lstat(path.join(__dirname, 'test-file', 'quick', 'beige'))80 ).then(81 () => fs.unlink(path.join(__dirname, 'test-file', 'quick', 'brown', 'fox.copy'))82 ).then(83 () => fs.lstat(path.join(__dirname, 'test-file', 'quick', 'brown', 'fox.copy')).catch(84 err => err.code === 'ENOENT'85 )86 ).then(87 () => fs.rmdir(path.join(__dirname, 'test-file'))88 ).then(89 () => fs.lstat(path.join(__dirname, 'test-file')).catch(90 err => err.code === 'ENOENT'91 )92 ),93 // test fs.lstatSync, fs.touchFileSync, fs.copyFileSync, fs.copydir, fs.unlinkSync, fs.rmdirSync94 new Promise(95 (resolve, reject) => {96 try {97 fs.lstatSync(path.join(__dirname, 'test-file-sync'));98 return reject();99 } catch (err) {100 // continue without error101 }102 try {103 fs.lstatSync(path.join(__dirname, 'test-file-sync', 'quick', 'brown', 'fox.file'));...

Full Screen

Full Screen

unlink.js

Source:unlink.js Github

copy

Full Screen

1'use strict';2var3 unlink = require('../lib/enyo/lib/unlink'),4 link = require('../lib/enyo/lib/link');5describe('enyo unlink', function () {6 before(function () {7 return resetEnv().then(function () {8 return setupLinks();9 });10 });11 12 it('should throw an error if no target is specified without --unlink-all', function () {13 return getOpts({cwd: testProj}).then(function (opts) {14 return unlink(opts).should.eventually.be.rejected;15 });16 });17 18 it('should throw an error if --global set without --unlink-all and no target', function () {19 return getOpts({cwd: testProj, global: true}).then(function (opts) {20 return unlink(opts).should.eventually.be.rejected;21 });22 });23 24 it('should unlink the target library from a project', function () {25 return getOpts({cwd: testProj, target: 'test1'}).then(function (opts) {26 return link(opts);27 }).then(function () {28 return getOpts({cwd: testProj, target: 'test1'}).then(function (opts) {29 return unlink(opts).then(function () {30 return opts.env.get('libDir').then(function (libDir) {31 return fs.lstatAsync(path.join(opts.env.cwd, libDir, 'test1')).should.eventually.be.rejected;32 });33 });34 });35 });36 });37 38 it('should unlink all linked libraries in a project with --unlink-all', function () {39 return getOpts({cwd: testProj, target: 'test1,test2'}).then(function (opts) {40 return link(opts);41 }).then(function () {42 return getOpts({cwd: testProj, unlinkAll: true}).then(function (opts) {43 return unlink(opts).then(function () {44 return opts.env.get('libDir').then(function (libDir) {45 return all([46 fs.lstatAsync(path.join(opts.env.cwd, libDir, 'test1')).should.eventually.be.rejected,47 fs.lstatAsync(path.join(opts.env.cwd, libDir, 'test2')).should.eventually.be.rejected48 ]);49 });50 });51 });52 });53 });54 55 it('should remove the target linkable library from the user\'s environment with --global and target', function () {56 return getOpts({global: true, target: 'test1'}).then(function (opts) {57 return unlink(opts).then(function () {58 return fs.lstatAsync(path.join(opts.env.userLinks, 'test1')).should.eventually.be.rejected;59 });60 });61 });62 63 it('should remove all linked libraries in the user\'s environment with --global and --unlink-all', function () {64 return getOpts({global: true, unlinkAll: true}).then(function (opts) {65 return unlink(opts).then(function () {66 return all([67 fs.lstatAsync(path.join(opts.env.userLinks, 'test2')).should.eventually.be.rejected,68 fs.lstatAsync(path.join(opts.env.userLinks, 'test3')).should.eventually.be.rejected69 ]);70 });71 });72 });73 74 it('should save changes to projects with --save', function () {75 return resetEnv().then(function () {76 return setupLinks();77 }).then(function () {78 return getOpts({cwd: testProj, target: ['test1','test2','test3'], save: true}).then(function (opts) {79 return link(opts).then(function () {80 return all([81 resolve(opts.env.config.get('links')).should.eventually.be.an('array').and.contain('test1','test2','test3'),82 opts.env.get('libDir').then(function (libDir) {83 return all([84 fs.lstatAsync(path.join(opts.env.cwd, libDir, 'test1')).then(function (stat) {85 return stat.isSymbolicLink();86 }).should.eventually.be.true,87 fs.lstatAsync(path.join(opts.env.cwd, libDir, 'test2')).then(function (stat) {88 return stat.isSymbolicLink();89 }).should.eventually.be.true,90 fs.lstatAsync(path.join(opts.env.cwd, libDir, 'test3')).then(function (stat) {91 return stat.isSymbolicLink();92 }).should.eventually.be.true93 ]);94 })95 ]);96 });97 });98 }).then(function () {99 return getOpts({cwd: testProj, unlinkAll: true, save: true}).then(function (opts) {100 return unlink(opts).then(function () {101 return all([102 resolve(opts.env.config.get('links')).should.eventually.be.an('array').and.not.contain('test1','test2','test3'),103 opts.env.get('libDir').then(function (libDir) {104 return all([105 fs.lstatAsync(path.join(opts.env.cwd, libDir, 'test1')).should.eventually.be.rejected,106 fs.lstatAsync(path.join(opts.env.cwd, libDir, 'test2')).should.eventually.be.rejected,107 fs.lstatAsync(path.join(opts.env.cwd, libDir, 'test3')).should.eventually.be.rejected108 ]);109 })110 ]);111 });112 });113 });114 });...

Full Screen

Full Screen

copy_test.js

Source:copy_test.js Github

copy

Full Screen

1var grunt = require('grunt');2var fs = require('fs');3exports.copy = {4 main: function(test) {5 'use strict';6 test.expect(3);7 var actual = fs.readdirSync('tmp/copy_test_files').sort();8 var expected = fs.readdirSync('test/expected/copy_test_files').sort();9 test.deepEqual(expected, actual, 'should copy several files');10 actual = fs.readdirSync('tmp/copy_test_mix').sort();11 expected = fs.readdirSync('test/expected/copy_test_mix').sort();12 test.deepEqual(expected, actual, 'should copy a mix of folders and files');13 actual = fs.readdirSync('tmp/copy_test_v0.1.0').sort();14 expected = fs.readdirSync('test/expected/copy_test_v0.1.0').sort();15 test.deepEqual(expected, actual, 'should parse both dest and src templates');16 test.done();17 },18 flatten: function(test) {19 'use strict';20 test.expect(1);21 var actual = fs.readdirSync('tmp/copy_test_flatten').sort();22 var expected = fs.readdirSync('test/expected/copy_test_flatten').sort();23 test.deepEqual(expected, actual, 'should create a flat structure');24 test.done();25 },26 single: function(test) {27 'use strict';28 test.expect(1);29 var actual = grunt.file.read('tmp/single.js');30 var expected = grunt.file.read('test/expected/single.js');31 test.equal(expected, actual, 'should allow for single file copy');32 test.done();33 },34 mode: function(test) {35 'use strict';36 test.expect(1);37 test.equal(fs.lstatSync('tmp/mode.js').mode.toString(8).slice(-3), '444');38 test.done();39 },40 modeDir: function(test) {41 'use strict';42 test.expect(2);43 test.equal(fs.lstatSync('tmp/copy_test_modeDir/time_folder').mode.toString(8).slice(-3), '777');44 test.equal(fs.lstatSync('tmp/copy_test_modeDir/time_folder/sub_folder').mode.toString(8).slice(-3), '777');45 test.done();46 },47 process: function(test) {48 'use strict';49 test.expect(2);50 test.equal(fs.lstatSync('tmp/process/beep.wav').size, fs.lstatSync('test/fixtures/beep.wav').size);51 test.notEqual(fs.lstatSync('tmp/process/test2.js').size, fs.lstatSync('test/fixtures/test2.js').size);52 test.done();53 },54 timestamp: function(test) {55 'use strict';56 test.expect(4);57 test.equal(fs.lstatSync('tmp/copy_test_timestamp/sub_folder').mtime.getTime(), fs.lstatSync('test/fixtures/time_folder/sub_folder').mtime.getTime());58 test.equal(fs.lstatSync('tmp/copy_test_timestamp/test.js').mtime.getTime(), fs.lstatSync('test/fixtures/time_folder/test.js').mtime.getTime());59 test.notEqual(fs.lstatSync('tmp/copy_test_timestamp/test1.js').mtime.getTime(), fs.lstatSync('test/fixtures/time_folder/test.js').mtime.getTime());60 test.notEqual(fs.lstatSync('tmp/copy_test_timestamp/test_process.js').mtime.getTime(), fs.lstatSync('test/fixtures/time_folder/test_process.js').mtime.getTime());61 test.done();62 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1import test from 'ava'2import fs from 'fs-extra'3import path from 'path'4import dereference from '../'5test('objects to missing directory argument', t => {6 t.throws(() => dereference(), /Please specify a directory/)7})8const tmpDirPath = path.join(process.cwd(), 'tmp')9const dirPath = path.join(tmpDirPath, 'test')10const subDirPath = path.join(dirPath, 'sub')11const otherDirPath = path.join(tmpDirPath, 'other')12const symlinkedOtherDirPath = path.join(dirPath, 'link')13const binPath = path.join(tmpDirPath, '.bin')14const otherBinPath = path.join(otherDirPath, '.bin')15const files = {16 a: path.join(dirPath, 'a.txt'),17 b: path.join(dirPath, 'b.txt'),18 c: path.join(subDirPath, 'c.txt'),19 d: path.join(dirPath, 'd.txt'),20 e: path.join(subDirPath, 'e.txt'),21 f: path.join(dirPath, 'f.txt'),22 g: path.join(otherDirPath, 'g.txt'),23 h: path.join(otherDirPath, 'h.txt'),24 i: path.join(binPath, 'i.txt'),25 j: path.join(otherBinPath, 'j.txt')26}27test.before(() => {28 if (fs.existsSync(tmpDirPath)) {29 fs.removeSync(tmpDirPath)30 }31 fs.mkdirSync(tmpDirPath)32 fs.mkdirSync(dirPath)33 fs.mkdirSync(subDirPath)34 fs.mkdirSync(otherDirPath)35 fs.mkdirSync(binPath)36 fs.mkdirSync(otherBinPath)37 fs.writeFileSync(files.a, 'a')38 fs.writeFileSync(files.b, 'b')39 fs.writeFileSync(files.c, 'c')40 fs.writeFileSync(files.g, 'g')41 fs.symlinkSync(files.a, files.d)42 fs.symlinkSync(files.b, files.e)43 fs.symlinkSync(files.c, files.f)44 fs.symlinkSync(files.a, files.h)45 fs.symlinkSync(files.a, files.i)46 fs.symlinkSync(files.g, files.j)47 fs.symlinkSync(otherDirPath, symlinkedOtherDirPath)48})49test.after.always(() => {50 fs.removeSync(tmpDirPath)51})52test('should defereference symlinks', t => {53 t.truthy(fs.lstatSync(files.d).isSymbolicLink())54 t.truthy(fs.lstatSync(files.e).isSymbolicLink())55 t.truthy(fs.lstatSync(files.f).isSymbolicLink())56 t.truthy(fs.lstatSync(symlinkedOtherDirPath).isSymbolicLink())57 t.truthy(fs.lstatSync(files.h).isSymbolicLink())58 dereference(dirPath)59 t.is('a', fs.readFileSync(files.d, 'utf8'))60 t.is('b', fs.readFileSync(files.e, 'utf8'))61 t.is('c', fs.readFileSync(files.f, 'utf8'))62 t.is('g', fs.readFileSync(files.g, 'utf8'))63 t.is('a', fs.readFileSync(files.h, 'utf8'))64 t.falsy(fs.lstatSync(files.d).isSymbolicLink())65 t.falsy(fs.lstatSync(files.e).isSymbolicLink())66 t.falsy(fs.lstatSync(files.f).isSymbolicLink())67 t.falsy(fs.lstatSync(files.g).isSymbolicLink())68 t.falsy(fs.lstatSync(files.h).isSymbolicLink())69 t.falsy(fs.lstatSync(symlinkedOtherDirPath).isSymbolicLink())70 t.truthy(fs.lstatSync(files.i).isSymbolicLink())71 t.truthy(fs.lstatSync(files.j).isSymbolicLink())...

Full Screen

Full Screen

full.js

Source:full.js Github

copy

Full Screen

1"use strict";2let PixiPacker = require("../../index");3let path = require("path");4let expect = require("chai").expect;5let promisify = require("es6-promisify");6let rimraf = promisify(require("rimraf"));7let mkdirp = promisify(require("mkdirp"));8let fs = require("fs");9describe("Full run", function() {10 this.timeout(60000);11 let pixiPacker, config, tempPath, outputPath;12 before(() => {13 tempPath = path.join(__dirname, "../tmp");14 outputPath = path.join(__dirname, "../output");15 return Promise.all([16 rimraf(outputPath),17 rimraf(tempPath)18 ])19 .then(() => mkdirp(tempPath))20 .then(() => {21 config = require("../../example.js");22 pixiPacker = new PixiPacker(23 config,24 path.resolve(__dirname, "../.."),25 path.resolve(__dirname, outputPath),26 path.resolve(__dirname, tempPath)27 );28 return pixiPacker.process();29 });30 });31 after(() => {32 return Promise.all([33 rimraf(outputPath),34 rimraf(tempPath)35 ]);36 });37 it("creates an output directory", () => {38 expect(fs.lstatSync(outputPath).isDirectory()).to.equal(true);39 });40 it("creates an manifests", () => {41 expect(fs.lstatSync(outputPath + "/game_EN_web.json").isFile()).to.equal(true);42 expect(fs.lstatSync(outputPath + "/game_DE_web.json").isFile()).to.equal(true);43 expect(fs.lstatSync(outputPath + "/game_EN_web_retina.json").isFile()).to.equal(true);44 expect(fs.lstatSync(outputPath + "/game_DE_web_retina.json").isFile()).to.equal(true);45 expect(fs.lstatSync(outputPath + "/menu_EN_web.json").isFile()).to.equal(true);46 expect(fs.lstatSync(outputPath + "/menu_DE_web.json").isFile()).to.equal(true);47 expect(fs.lstatSync(outputPath + "/menu_EN_web_retina.json").isFile()).to.equal(true);48 expect(fs.lstatSync(outputPath + "/menu_DE_web_retina.json").isFile()).to.equal(true);49 });50 it("has the right resolution", () => {51 let manifest = JSON.parse(fs.readFileSync(outputPath + "/game_DE_web_retina.json", "utf8"));52 expect(manifest.resolution).to.equal(2);53 });54 it("creates all images", () => {55 let manifest = JSON.parse(fs.readFileSync(outputPath + "/game_DE_web_retina.json", "utf8"));56 expect(manifest.spritesheets.length).to.be.greaterThan(0);57 manifest.spritesheets.forEach(spritesheet => {58 expect(fs.lstatSync(outputPath + "/" + spritesheet.image).isFile()).to.equal(true);59 });60 });...

Full Screen

Full Screen

lsSync.js

Source:lsSync.js Github

copy

Full Screen

1const fs = require('fs')2const SLASH = process.platform === 'win32' ? '\'' : '/'3const RESULT = []4const getType = (path = '') => {5 if (fs.existsSync(path)) {6 if (fs.lstatSync(path).isFile()) return 'file'7 else if (fs.lstatSync(path).isDirectory()) return 'directory'8 else if (fs.lstatSync(path).isBlockDevice()) return 'block device'9 else if (fs.lstatSync(path).isCharacterDevice()) return 'character device'10 else if (fs.lstatSync(path).isSymbolicLink()) return 'symbolic link'11 else if (fs.lstatSync(path).isFIFO()) return 'FIFO'12 else if (fs.lstatSync(path).isSocket()) return 'socket'13 else return false14 } else {15 return false16 }17}18const getFileProperty = (_path = '') => {19 const byDotSlash = _path.split('.' + SLASH)20 const path = byDotSlash[byDotSlash.length - 1]21 const byDot = path.split('.')22 const ext = byDot.length > 1 ? byDot[byDot.length - 1] : false23 const extension = ext ? '.' + ext : false24 const bySlash = path.split(SLASH)25 const fileName = bySlash[bySlash.length - 1].includes('.') ? bySlash[bySlash.length - 1] : false26 const fileLocation = fileName ? _path.split(fileName)[0] : _path27 return {28 name: fileName,29 location: fileLocation,30 extension31 }32}33/**34 * lsSync35 * @param {String} dir root directory36 */37const lsSync = (dir = './') => {38 const allFiles = fs.readdirSync(dir)39 allFiles.forEach(file => {40 const _path = dir + SLASH + file41 const path = _path.replace(SLASH + SLASH, SLASH)42 if (fs.existsSync(path) && fs.lstatSync(path).isDirectory()) {43 lsSync(path, RESULT)44 }45 const type = getType(path)46 const fileProperty = getFileProperty(path)47 RESULT.push({48 path,49 type,50 directory: fileProperty.location,51 file: fileProperty.name,52 extension: fileProperty.extension53 })54 })55 return RESULT56}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', () => {2 it('does not do much!', () => {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', () => {2 it('Does not do much!', () => {3 expect(true).to.equal(true)4 })5 it('Reads a file', () => {6 cy.readFile('cypress/fixtures/example.json').then((json) => {7 cy.writeFile('cypress/fixtures/example.json', {...json, "foo": "bar"})8 })9 })10})11I am trying to read a file in cypress using cy.readFile() method. I am getting the following error:12I am trying to read a file in cypress using cy.readFile() method. I am getting the following error: Error: ENOENT: no such file or directory, open 'cypress/fixtures/example.json' I have added a file called example.json in cypress/fixtures folder. I have also tried to read the file from cypress/integration folder but still I am getting the same error. Can anyone please help me to resolve this issue?13I am trying to read a file in cypress using cy.readFile() method. I am getting the following error: Error: ENOENT: no such file or directory, open 'cypress/fixtures/example.json' I have added a file called example.json in cypress/fixtures folder. I have also tried to read the file from cypress/integration folder but still I am getting the same error. Can anyone please help me to resolve this issue?14I am trying to read a file in cypress using cy.readFile() method. I am getting the following error: Error: ENOENT: no such file or directory, open 'cypress/fixtures/example.json' I have added a file called example.json in cypress/fixtures folder. I have also tried to read the file from cypress/integration folder but still I am getting the same error. Can anyone please help me to resolve this issue?15I am trying to read a file in cypress using cy.readFile() method. I am getting the following error: Error: ENOENT: no such file or directory, open 'cypress/fixtures/example.json' I have added a

Full Screen

Using AI Code Generation

copy

Full Screen

1.lstat('/path/to/file')2.then((stats) => {3})4.stat('/path/to/file')5.then((stats) => {6})7.readdir('/path/to/dir')8.then((files) => {9})10.readFile('/path/to/file')11.then((content) => {12})13.writeFile('/path/to/file', 'content')14.then((content) => {15})16.unlink('/path/to/file')17.then((content) => {18})19.mkdir('/path/to/dir')20.then((content) => {21})22.rmdir('/path/to/dir')23.then((content) => {24})25.copy('/path/to/file', '/path/to/destination')26.then((content) => {27})28.move('/path/to/file', '/path/to/destination')29.then((content) => {30})31.ensureDir('/path/to/dir')32.then((content) => {33})34.emptyDir('/path/to/dir')35.then((content) => {36})37.readJson('/path/to/file')38.then((content) => {39})40.writeJson('/path/to/file', { name: 'John Doe' })41.then((content) => {42})43.outputJson('/path/to/file', { name: 'John Doe'

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', () => {3 cy.task('lstat', 'cypress/fixtures/test.js').then((stat) => {4 expect(stat.isFile()).to.be.true;5 });6 });7});8describe('test', () => {9 it('test', () => {10 cy.task('lstat', 'cypress/fixtures/test.txt').then((stat) => {11 expect(stat.isFile()).to.be.true;12 });13 });14});15describe('test', () => {16 it('test', () => {17 cy.task('lstat', 'cypress/fixtures/test2.txt').then((stat) => {18 expect(stat.isFile()).to.be.true;19 });20 });21});22describe('test', () => {23 it('test', () => {24 cy.task('lstat', 'cypress/fixtures/test3.txt').then((stat) => {25 expect(stat.isFile()).to.be.true;26 });27 });28});29describe('test', () => {30 it('test', () => {31 cy.task('lstat', 'cypress/fixtures/test4.txt').then((stat) => {32 expect(stat.isFile()).to.be.true;33 });34 });35});36describe('test', () => {37 it('test', () => {38 cy.task('lstat', 'cypress/fixtures/test5.txt').then((stat) => {39 expect(stat.isFile()).to.be.true;40 });41 });42});43describe('test', () => {44 it('test', () => {45 cy.task('lstat', 'cypress/fixtures/test6.txt').then((stat) => {46 expect(stat.isFile()).to.be.true;47 });48 });49});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Verify the file', () => {2 it('Check if file exists', () => {3 cy.task('lstat', 'cypress/fixtures/test.json')4 .its('isFile')5 .should('be.true')6 })7})8const lstat = require('fs').lstatSync9const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin')10module.exports = (on, config) => {11 on('task', {12 lstat: (path) => lstat(path),13 })14 addMatchImageSnapshotPlugin(on, config)15}16const lstat = require('fs').lstatSync17const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin')18module.exports = (on, config) => {19 on('task', {20 lstat: (path) => lstat(path),21 })22 addMatchImageSnapshotPlugin(on, config)23}24const lstat = require('fs').lstatSync25const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin')26module.exports = (on, config) => {27 on('task', {28 lstat: (path) => lstat(path),29 })30 addMatchImageSnapshotPlugin(on, config)31}32const lstat = require('fs').lstatSync33const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin')34module.exports = (on, config) => {35 on('task', {36 lstat: (path) => lstat(path),37 })38 addMatchImageSnapshotPlugin(on, config)39}40const lstat = require('fs').lstatSync41const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin')42module.exports = (on, config) => {43 on('task', {

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.task('getFileSize', 'cypress/integration/test.js').then((size) => {2 expect(size).to.be.greaterThan(0)3})4cy.task('getFileSize', 'cypress/integration/test.js').then((size) => {5 expect(size).to.be.greaterThan(0)6})7cy.task('getFileSize', 'cypress/integration/test.js').then((size) => {8 expect(size).to.be.greaterThan(0)9})10cy.task('getFileSize', 'cypress/integration/test.js').then((size) => {11 expect(size).to.be.greaterThan(0)12})13cy.task('getFileSize', 'cypress/integration/test.js').then((size) => {14 expect(size).to.be.greaterThan(0)15})16cy.task('getFileSize', 'cypress/integration/test.js').then((size) => {17 expect(size).to.be.greaterThan(0)18})19cy.task('getFileSize', 'cypress/integration/test.js').then((size) => {20 expect(size).to.be.greaterThan(0)21})22cy.task('getFileSize', 'cypress/integration/test.js').then((size) => {23 expect(size).to.be.greaterThan(0)24})25cy.task('getFileSize', 'cypress/integration/test.js').then((size) => {26 expect(size).to.be.greaterThan(0

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2const path = require('path');3let fileAttributes = fs.lstatSync('test.js');4console.log(fileAttributes);5console.log(fileAttributes.size);6console.log(fileAttributes.birthtime);7console.log(fileAttributes.mtime);8console.log(fileAttributes.atime);9console.log(fileAttributes.ino);10console.log(fileAttributes.mode);11console.log(fileAttributes.uid);12console.log(fileAttributes.gid);13console.log(fileAttributes.blksize);14console.log(fileAttributes.blocks);15console.log(fileAttributes.isFile());16console.log(fileAttributes.isDirectory());17console.log(fileAttributes.isSymbolicLink());18console.log(fileAttributes.isFIFO());19console.log(fileAttributes.isCharacterDevice());20console.log(fileAttributes.isBlockDevice());

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress 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