How to use fs.readdir method in Cypress

Best JavaScript code snippet using cypress

readdir.spec.js

Source:readdir.spec.js Github

copy

Full Screen

1var sinon = require('sinon');2var should = require('should');3var readdir = require(process.cwd() + '/lib/readdir');4var fs = require('fs');5describe ('readdir', function() {6 describe ('#getTreeSync', function() {7 it ('should contain #getTreeSync method', function() {8 readdir.getTreeSync.should.be.instanceOf(Function);9 });10 it ('should throw when no directory is defined', function() {11 (function() {12 readdir.getTreeSync();13 }).should.throw('No directory defined');14 });15 it ('should throw when no directory is null', function() {16 (function() {17 readdir.getTreeSync(null);18 }).should.throw('No directory defined');19 });20 it ('should ask for given directory', sinon.test(function() {21 this.stub(fs, 'readdirSync').returns([]);22 readdir.getTreeSync('something');23 fs.readdirSync.called.should.be.ok;24 }));25 it ('should return an object', sinon.test(function() {26 this.stub(fs, 'readdirSync').returns([ 'hello' ]);27 this.stub(fs, 'statSync').returns({ isDirectory : function() { return false; } });28 readdir.getTreeSync('something').should.have.type('object');29 }));30 it ('should validate the file if the validation function is defined', sinon.test(function() {31 var spy = sinon.stub().returns(false);32 this.stub(fs, 'readdirSync').returns([ 'hello' ]);33 readdir.getTreeSync('something', spy);34 spy.called.should.be.ok;35 }));36 it ('should ask for statSync', sinon.test(function() {37 this.stub(fs, 'readdirSync').returns([ 'hello' ]);38 this.stub(fs, 'statSync').returns({ isDirectory : function() { return false; } });39 readdir.getTreeSync('something');40 fs.statSync.called.should.be.ok;41 }));42 it ('should return an object with tree and files keys', sinon.test(function() {43 this.stub(fs, 'readdirSync').returns([ 'hello' ]);44 this.stub(fs, 'statSync').returns({ isDirectory : function() { return false; } });45 readdir.getTreeSync('something').tree.should.be.ok;46 readdir.getTreeSync('something').files.should.be.ok;47 }));48 it ('should return an a tree object that contain an array of objects', sinon.test(function() {49 this.stub(fs, 'readdirSync').returns([ 'hello' ]);50 this.stub(fs, 'statSync').returns({ isDirectory : function() { return false; } });51 readdir.getTreeSync('something').tree[0].should.have.type('object');52 }));53 it ('should return an files array that contains direct file names', sinon.test(function() {54 this.stub(fs, 'readdirSync').returns([ 'hello' ]);55 this.stub(fs, 'statSync').returns({ isDirectory : function() { return false; } });56 readdir.getTreeSync('something').files.should.eql([ 'something/hello' ]);57 }));58 it ('should return recursive results', sinon.test(function() {59 var calls = 0;60 this.stub(fs, 'readdirSync').returns([ 'wat', 'test' ]);61 this.stub(fs, 'statSync').returns({ isDirectory: function() { return ++calls === 1; } });62 var result = readdir.getTreeSync('something');63 result.tree.should.eql([ {64 name : 'wat',65 target : 'something/wat',66 children : [67 { name: 'wat', target: 'something/wat/wat' },68 { name: 'test', target: 'something/wat/test' }69 ]70 }, {71 name : 'test',72 target : 'something/test'73 }]);74 result.files.should.eql([ 'something/wat/wat', 'something/wat/test', 'something/test' ]);75 }));76 });77 describe ('#getFilesSync', function() {78 it ('should contain #getFilesSync method', function() {79 readdir.getFilesSync.should.be.instanceOf(Function);80 });81 it ('should throw when no directory is defined', function() {82 (function() {83 readdir.getFilesSync();84 }).should.throw('No directory defined');85 });86 it ('should throw when directory is null', function() {87 (function() {88 readdir.getFilesSync(null);89 }).should.throw('No directory defined');90 });91 it ('should ask for readdirSync with the given directory', sinon.test(function() {92 this.stub(fs, 'readdirSync').returns([]);93 readdir.getFilesSync('some-place');94 fs.readdirSync.args[0].should.eql(['some-place']);95 }));96 it ('should return the data received', sinon.test(function() {97 this.stub(fs, 'readdirSync').returns([ 'something' ]);98 this.stub(fs, 'statSync').returns({ isDirectory: function() { return false; } });99 readdir.getFilesSync('some-place').should.eql(['some-place/something']);100 }));101 it ('should call the validate method on each file', sinon.test(function() {102 var spy = sinon.spy();103 this.stub(fs, 'readdirSync').returns([ 'something', 'wat' ]);104 readdir.getFilesSync('some-place', spy);105 spy.calledTwice.should.be.ok;106 }));107 it ('should exclude files that do not pass validate', sinon.test(function() {108 this.stub(fs, 'readdirSync').returns([ 'something', 'wat' ]);109 this.stub(fs, 'statSync').returns({ isDirectory: function() { return false; } });110 var files = readdir.getFilesSync('some-place', function(val) {111 return val === 'wat';112 });113 files.should.eql([ 'some-place/wat' ]);114 }));115 it ('should exclude files that start with . with recursive', sinon.test(function() {116 this.stub(fs, 'readdirSync').returns([ 'something', '.wat' ]);117 this.stub(fs, 'statSync').returns({ isDirectory: function() { return false; } });118 var files = readdir.getFilesSync('some-place', function(val) {119 return !new RegExp('^\\.').test(val);120 });121 files.should.eql([ 'some-place/something' ]);122 }));123 it ('should ask for sync stat is for each file', sinon.test(function() {124 this.stub(fs, 'readdirSync').returns([ 'something', 'wat' ]);125 this.stub(fs, 'statSync').returns({ isDirectory: function() { return false; } });126 readdir.getFilesSync('some-place');127 fs.statSync.calledTwice.should.be.ok;128 }));129 it ('should ask for dir listing and stat again if isDirectory returns true', sinon.test(function() {130 var calls = 0;131 this.stub(fs, 'readdirSync').returns([ 'wat' ]);132 this.stub(fs, 'statSync').returns({ isDirectory: function() { return ++calls === 1; } });133 readdir.getFilesSync('some-place');134 fs.readdirSync.calledTwice.should.be.ok;135 fs.statSync.calledTwice.should.be.ok;136 }));137 it ('should ask for validation rule for each recursive step', sinon.test(function() {138 var calls = 0;139 var spy = sinon.spy();140 this.stub(fs, 'readdirSync').returns([ 'wat' ]);141 this.stub(fs, 'statSync').returns({ isDirectory: function() { return ++calls === 1; } });142 readdir.getFilesSync('some-place', function() {143 spy();144 return true;145 });146 spy.calledTwice.should.be.ok;147 }));148 it ('should return recursive results', sinon.test(function() {149 var calls = 0;150 this.stub(fs, 'readdirSync').returns([ 'wat', 'herro' ]);151 this.stub(fs, 'statSync').returns({ isDirectory: function() { return ++calls === 1; } });152 readdir.getFilesSync('some-place').should.eql([ 'some-place/wat/wat', 'some-place/wat/herro', 'some-place/herro' ]);153 }));154 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...7router.get('/', function(req, res, next) {8 res.render('index', { title: 'Twitch Odyssey' });9});10router.get('/foreground_lair', function(req, res, next) {11 fs.readdir(__dirname + '/../public/thumbnails', function (err, files) {12 if (err) throw err;13 res.render('foreground_lair.html', { title: 'Layerz.tv', files: files });14 });15});16router.get('/background_lair', function(req, res, next) {17 fs.readdir(__dirname + '/../public/foreground', function (err, files) {18 if (err) throw err;19 res.render('background_lair.html', { title: 'Layerz.tv', files: files });20 });21});22router.get('/multilayer_lair', function(req, res, next) {23 var foregroundFiles = [];24 var backgroundFiles = [];25 var midgroundFiles = [];26 async.parallel ( [27 function(callback) {28 fs.readdir(__dirname + '/../public/foreground_thumbs', function (err, foregrounds) {29 if (err) throw err;30 console.log("foregrounds: ", foregrounds);31 foregroundFiles = foregrounds;32 callback();33 }); 34 },35 function(callback) {36 fs.readdir(__dirname + '/../public/background_thumbs', function (err, backgrounds) {37 if (err) throw err;38 console.log("backgrounds: ", backgrounds);39 backgroundFiles = backgrounds;40 callback();41 });42 },43 function(callback) {44 fs.readdir(__dirname + '/../public/midground_thumbs', function (err, midgrounds) {45 if (err) throw err;46 console.log("midgrounds: ", midgrounds);47 midgroundFiles = midgrounds;48 callback();49 });50 }51 ], function (error, results) {52 res.render('multilayer_lair.html', { title: 'Layerz.tv', foregrounds: foregroundFiles, backgrounds: backgroundFiles, midgrounds: midgroundFiles });53 });54});55router.get('/philly', function(req, res, next) {56 fs.readdir(__dirname + '/../public/thumbnails', function (err, files) {57 if (err) throw err;58 res.render('philly.html', { title: 'Twitch Odyssey', files: files });59 });60 });61router.get('/files', function (req, res) {62 fs.readdir(__dirname + '/../public/uploaded/files', function (err, files) {63 if (err) throw err;64 res.render('files.html', {files: files });65 });66});67router.get('/content', function (req, res) {68 fs.readdir(__dirname + '/../public/uploaded/files', function (err, files) {69 if (err) throw err;70 res.render('content.html', {files: files });71 });72});73router.get('/foreground', function (req, res) {74 fs.readdir(__dirname + '/../public/foregrounds/files', function (err, files) {75 if (err) throw err;76 res.render('foreground.html', {title: 'Foreground', files: files });77 });78});79router.get('/background', function (req, res) {80 fs.readdir(__dirname + '/../public/backgrounds/files', function (err, files) {81 if (err) throw err;82 res.render('background.html', {files: files });83 });84});85router.get('/webcam', function (req, res) {86 res.render('webcam.html');87});88router.get('/midground', function (req, res) {89 fs.readdir(__dirname + '/../public/midgrounds/files', function (err, files) {90 if (err) throw err;91 res.render('midground.html', {files: files });92 });93});94router.get('/audio', function (req, res) {95 fs.readdir(__dirname + '/../public/audio/files', function (err, files) {96 if (err) throw err;97 res.render('audio.html', {files: files });98 });99});100router.get('/homer', function (req, res) {101 fs.readdir(__dirname + '/../public/uploaded/files', function (err, files) {102 if (err) throw err;103 // console.log(files);104 res.render('homer.html', {files: files });105 });106});107router.get('/control', function (req, res) {108 res.render('control.html');109});110router.get('/instructions', function (req, res) {111 res.render('instructions.html');112});113router.get('/theatre', function (req, res) {114 res.render('index.html');115});116router.get('/couch', function (req, res) {117 res.render('couch.html');118});119// router.get('/chat', function (req, res) {120// res.render('chat.html');121// });122router.get('/chat', function (req, res) {123 fs.readdir(__dirname + '/../public/uploaded/files', function (err, files) {124 if (err) throw err;125 // console.log(files);126 res.render('chat.html', {files: files });127 });128});129router.get('/streamOnly', function (req, res) {130 fs.readdir(__dirname + '/../public/uploaded/files', function (err, files) {131 if (err) throw err;132 // console.log(files);133 res.render('streamOnly.html', {files: files });134 });135});136router.get('/mobile', function (req, res) {137 fs.readdir(__dirname + '/../public/thumbnails', function (err, files) {138 if (err) throw err;139 // console.log(files);140 res.render('mobile.html', {files: files });141 });142});...

Full Screen

Full Screen

help.js

Source:help.js Github

copy

Full Screen

...7 if (cooldown.has(message.author.id)) {8 message.channel.send('<:gloock:488829272664965130> - Wait **5** seconds to use this command again.')9 } else {1011fs.readdir('./comandos/admin', (err, files) => {12 const admin = [];13 files.forEach(file => admin.push('kf.' + file.replace('.js', '')));1415fs.readdir('./comandos/fun', (err, files) => {16 const FUN = [];17 files.forEach(file => FUN.push('kf.' + file.replace('.js', '')));181920fs.readdir('./comandos/games', (err, files) => {21 const games = [];22 files.forEach(file => games.push('kf.' + file.replace('.js', '')));2324fs.readdir('./comandos/image', (err, files) => {25 const image = [];26 files.forEach(file => image.push('kf.' + file.replace('.js', '')));272829fs.readdir('./comandos/info', (err, files) => {30 const info = [];31 files.forEach(file => info.push('kf.' + file.replace('.js', '')));323334fs.readdir('./comandos/music', (err, files) => {35 const music = [];36 files.forEach(file => music.push('kf.' + file.replace('.js', '')));373839fs.readdir('./comandos/nsfw', (err, files) => {40 const nsfw = [];41 files.forEach(file => nsfw.push('kf.' + file.replace('.js', '')));4243fs.readdir('./comandos/util', (err, files) => {44 const util = [];45 files.forEach(file => util.push('kf.' + file.replace('.js', '')));464748let adminc = fs.readdirSync('./comandos/admin');49let aquantity = adminc.length;5051let utilc = fs.readdirSync('./comandos/util');52let uquantity = utilc.length;5354let fun = fs.readdirSync('./comandos/fun');55let funquantity = fun.length;5657let gamesc = fs.readdirSync('./comandos/games'); ...

Full Screen

Full Screen

file-loader-spec.js

Source:file-loader-spec.js Github

copy

Full Screen

1// Copyright 2015, EMC, Inc.2'use strict';3describe('FileLoader', function () {4 var FileLoader;5 var fs;6 helper.before();7 before(function () {8 FileLoader = helper.injector.get('FileLoader');9 fs = helper.injector.get('fs');10 this.subject = new FileLoader();11 sinon.stub(fs, 'writeFileAsync');12 sinon.stub(fs, 'readFileAsync');13 sinon.stub(fs, 'readdirAsync');14 sinon.stub(fs, 'statAsync');15 });16 beforeEach(function() {17 fs.writeFileAsync.reset();18 fs.readFileAsync.reset();19 fs.readdirAsync.reset();20 fs.statAsync.reset();21 });22 helper.after(function () {23 fs.writeFileAsync.restore();24 fs.readFileAsync.restore();25 fs.readdirAsync.restore();26 fs.statAsync.restore();27 });28 describe('put', function () {29 it('should write the contents to the specified file', function () {30 fs.writeFileAsync.resolves('put');31 return this.subject.put('filename', 'contents').then(function (contents) {32 fs.writeFileAsync.should.have.been.calledWith('filename', 'contents');33 contents.should.equal('put');34 });35 });36 });37 describe('get', function () {38 it('should get the contents for the specified file', function () {39 fs.readFileAsync.resolves('get');40 return this.subject.get('filename').then(function (contents) {41 fs.readFileAsync.should.have.been.calledWith('filename');42 contents.should.equal('get');43 });44 });45 });46 describe('getAll', function () {47 it(48 'should return a promise fulfilled with the file basename to contents in an object',49 function () {50 fs.readFileAsync.resolves('getAll');51 fs.readdirAsync.resolves(['foo.txt']);52 fs.statAsync.resolves({ isDirectory: function() { return false; } });53 return this.subject.getAll('/tmp').then(function (files) {54 fs.readdirAsync.should.have.been.calledWith('/tmp');55 files['foo.txt'].should.have.property('path')56 .and.to.equal('/tmp/foo.txt');57 files['foo.txt'].should.have.property('contents')58 .and.to.equal('getAll');59 });60 }61 );62 it(63 'should skip directories when recursive is disabled',64 function () {65 fs.readFileAsync.resolves('getAll');66 fs.readdirAsync.resolves(['foo']);67 fs.statAsync.resolves({ isDirectory: function() { return true; } });68 return this.subject.getAll('/tmp').then(function () {69 fs.readdirAsync.should.have.been.calledWith('/tmp');70 fs.readFileAsync.should.not.have.been.called;71 });72 }73 );74 it(75 'should not skip directories when recursive is enabled',76 function () {77 fs.readFileAsync.resolves('getAll');78 fs.readdirAsync.withArgs('/tmp').resolves(['foo']);79 fs.readdirAsync.withArgs('/tmp/foo').resolves([]);80 fs.statAsync.resolves({ isDirectory: function() { return true; } });81 return this.subject.getAll('/tmp', true).then(function () {82 fs.readdirAsync.should.have.been.calledWith('/tmp');83 fs.readdirAsync.should.have.been.calledWith('/tmp/foo');84 fs.readFileAsync.should.not.have.been.called;85 });86 }87 );88 });...

Full Screen

Full Screen

resource-extractor.test.js

Source:resource-extractor.test.js Github

copy

Full Screen

1const fs = require("fs");2const path = require("path");3const resourceExtractor = require("../../../lib/utils/resource-extractor");4jest.mock("fs");5afterAll(() => {6 jest.unmock("fs");7 jest.restoreAllMocks();8});9describe("Testing path listing", () => {10 let readDirMock;11 let statMock;12 beforeEach(() => {13 readDirMock = jest.fn();14 statMock = jest.fn();15 fs.readdirSync = readDirMock;16 fs.statSync = statMock;17 fs.readdirSync.mockReturnValue(["foo", "bar"]);18 fs.statSync.mockImplementation(path => ({19 isDirectory: () => false20 }));21 });22 afterEach(() => {23 jest.restoreAllMocks();24 fs.statSync.mockRestore();25 fs.readdirSync.mockRestore();26 });27 it("should have a method for listing synchronously", () => {28 expect(typeof resourceExtractor.listPathSync === "function");29 });30 it("should return an empty array when directory is not given", () => {31 expect(resourceExtractor.listPathSync()).toEqual([]);32 });33 it("should return an empty array when pattern is not given", () => {34 expect(resourceExtractor.listPathSync("foo")).toEqual([]);35 });36 it("should return an empty array when no files are matched with the given pattern", () => {37 expect(resourceExtractor.listPathSync("foo", "coco")).toEqual([]);38 });39 it("should return an array with file paths that match with pattern", () => {40 fs.readdirSync.mockReturnValue(["foo.coco", "bar", "zed.coco"]);41 expect(resourceExtractor.listPathSync("foo", "coco").length).toEqual(2);42 });43 it("should call recursevly when some path is a directory", () => {44 fs.readdirSync45 .mockReturnValueOnce(["foo", "bar_dir_", "zed"])46 .mockReturnValue(["foo", "bar", "zed"]);47 fs.statSync.mockImplementation(dir => ({48 isDirectory: () => {49 const splitted = dir.split(path.sep);50 const last = splitted[splitted.length - 1];51 return last.includes("_dir_");52 }53 }));54 resourceExtractor.listPathSync("foo", "coco");55 expect(fs.readdirSync).toHaveBeenCalledTimes(2);56 });57 it("should not call recursevly when none path is a directory", () => {58 fs.readdirSync59 .mockReturnValueOnce(["foo", "bar", "zed"])60 .mockReturnValue(["foo", "bar", "zed"]);61 fs.statSync.mockImplementation(dir => ({62 isDirectory: () => {63 const splitted = dir.split(path.sep);64 const last = splitted[splitted.length - 1];65 return last.includes("_dir_");66 }67 }));68 resourceExtractor.listPathSync("foo", "coco");69 expect(fs.readdirSync).toHaveBeenCalledTimes(1);70 });71});72describe("Testing async use", () => {73 let readDirMock;74 let statMock;75 beforeEach(() => {76 readDirMock = jest.fn();77 statMock = jest.fn();78 fs.readdirSync = readDirMock;79 fs.statSync = statMock;80 fs.readdirSync.mockReturnValue(["foo", "bar"]);81 fs.statSync.mockImplementation(path => ({82 isDirectory: () => false83 }));84 });85 afterEach(() => {86 jest.restoreAllMocks();87 fs.statSync.mockRestore();88 fs.readdirSync.mockRestore();89 });90 it("should have a method for listing asynchronously", () => {91 expect(typeof resourceExtractor.listPath === "function");92 });93 it("should return a promise calling sync method with given params", async () => {94 const p1 = "foo";95 const p2 = "bar";96 const spy = jest.spyOn(resourceExtractor, "listPathSync");97 await resourceExtractor.listPath(p1, p2);98 await expect(spy).toHaveBeenCalled();99 });...

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

foo-tests.js

Source:foo-tests.js Github

copy

Full Screen

1'use strict'2/*3 * These examples demonstrate how to use proxyquire with Sinon.JS (<http://sinonjs.org/>).4 * Run these tests with mocha (<http://visionmedia.github.com/mocha/>).5 * e.g., mocha foo-tests.js6 */7var proxyquire = require('../..')8var sinon = require('sinon')9var assert = require('assert')10var fs = require('fs')11var path = require('path')12var foo13// Stubbing return values14describe('when path.extname(file) returns ".markdown"', function () {15 var extnameStub16 var file = 'somefile'17 before(function () {18 extnameStub = sinon.stub(path, 'extname')19 foo = proxyquire('./foo', { path: { extname: extnameStub } })20 extnameStub.withArgs(file).returns('.markdown')21 })22 after(function () {23 path.extname.restore()24 })25 it('extnameAllCaps returns ".MARKDOWN"', function () {26 assert.strictEqual(foo.extnameAllCaps(file), '.MARKDOWN')27 })28})29// Stubbing callbacks30describe('when fs.readdir calls back with ["file1", "file2"]', function () {31 var readdirStub32 before(function () {33 readdirStub = sinon.stub(fs, 'readdir')34 foo = proxyquire('./foo', { fs: { readdir: readdirStub } })35 readdirStub.withArgs('../simple').yields(null, ['file1', 'file2'])36 })37 after(function () {38 fs.readdir.restore()39 })40 it('filesAllCaps calls back with ["FILE1", "FILE2"]', function (done) {41 foo.filesAllCaps('../simple', function (err, files) {42 assert.strictEqual(err, null)43 assert.strictEqual(files[0], 'FILE1')44 assert.strictEqual(files[1], 'FILE2')45 done()46 })47 })48})49describe('when fs.readdir returns an error', function () {50 var readdirError,51 readdirStub52 before(function () {53 readdirStub = sinon.stub(fs, 'readdir')54 foo = proxyquire('./foo', { fs: { readdir: readdirStub } })55 readdirError = new Error('some error')56 readdirStub.withArgs('../simple').yields(readdirError, null)57 })58 after(function () {59 fs.readdir.restore()60 })61 it('filesAllCaps calls back with that error', function (done) {62 foo.filesAllCaps('../simple', function (err, files) {63 assert.strictEqual(err, readdirError)64 assert.strictEqual(files, null)65 done()66 })67 })68})69// Spying70describe('when calling filesAllCaps with "../simple"', function () {71 var readdirSpy72 before(function () {73 readdirSpy = sinon.spy(fs, 'readdir')74 foo = proxyquire('./foo', { fs: { readdir: readdirSpy } })75 })76 after(function () {77 fs.readdir.restore()78 })79 it('calls fs.readdir with "../simple"', function (done) {80 foo.filesAllCaps('../simple', function (err, files) {81 assert.ifError(err)82 assert(fs.readdir.calledOnce)83 assert.strictEqual(fs.readdir.getCall(0).args[0], '../simple')84 done()85 })86 })...

Full Screen

Full Screen

bootstrap.js

Source:bootstrap.js Github

copy

Full Screen

1"use strict";2const path = require('path');3const fs = require('fs');4const Bootstrap = {};5const widgetLoader = require('widget-loader'); 6Bootstrap.initBookshelf = function (config) {7 console.log("✔ Initializing bookshelf...");8 return require('./core/bookshelf')(config);9};10Bootstrap.initServer = function (App) {11 console.log("✔ Initializing server...");12 return require('./server')(App);13};14Bootstrap.loadModels = function (config) {15 console.log("✔ Loading models...");16 let modelsDir = config.modelsDir || path.join(config.rootDir, 'models');17 if (!(fs.existsSync(modelsDir) && fs.readdirSync(modelsDir).length)) {18 return null;19 }20 fs.existsSync(modelsDir) && fs.readdirSync(modelsDir).forEach( (m) => {21 require(`${modelsDir}/${m}`);22 });23};24Bootstrap.loadCollections = function (config) {25 console.log("✔ Loading collections...");26 let collectionsDir = config.collectionsDir || path.join(config.rootDir, 'collections');27 if (!(fs.existsSync(collectionsDir) && fs.readdirSync(collectionsDir).length)) {28 return null;29 }30 fs.existsSync(collectionsDir) && fs.readdirSync(collectionsDir).forEach( (m) => {31 require(`${collectionsDir}/${m}`);32 });33};34Bootstrap.loadControllers = function (config) {35 console.log("✔ Loading controllers...");36 let controllersDir = path.join(config.rootDir, 'controllers');37 if (!(fs.existsSync(controllersDir) && fs.readdirSync(controllersDir).length)) {38 return null;39 }40 fs.existsSync(controllersDir) && fs.readdirSync(controllersDir).forEach( (m) => {41 if(!fs.lstatSync(`${controllersDir}/${m}`).isDirectory() )42 require(`${controllersDir}/${m}`);43 });44};45Bootstrap.loadPlugins = function (config) {46 console.log("✔ Loading plugins...");47 let pluginsDir = /*config.pluginsDir ||*/ path.join(config.rootDir, 'splugins');48 let plugins = {};49 if (!(fs.existsSync(pluginsDir) && fs.readdirSync(pluginsDir).length)) {50 return null;51 }52 fs.existsSync(pluginsDir) && fs.readdirSync(pluginsDir).forEach( (m) => {53 let plugin = require(`${pluginsDir}/${m}`)(config);54 if (plugins.hasOwnProperty(plugin.name)) {55 return new Error('Plugin property name already defined.');56 }57 plugins[plugin.name] = plugin;58 });59 return plugins;60};61Bootstrap.loadRoutes = function (config) {62 console.log("✔ Loading routes...");63 let routesDir = config.routesDir || path.join(config.rootDir, 'routes');64 if (!(fs.existsSync(routesDir) && fs.readdirSync(routesDir).length)) {65 return null;66 }67 fs.existsSync(routesDir) && fs.readdirSync(routesDir).forEach( (m) => {68 require(`${routesDir}/${m}`);69 });70};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {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', function() {2 it('Does not do much!', function() {3 cy.get('input').type('test')4 cy.get('button').click()5 })6})7{8 "env": {9 },10 "reporterOptions": {11 },12 "component": {13 "testFiles": "**/*.spec.{js,jsx,ts,tsx}"14 }15}16Cypress.Commands.add('uploadFile', { prevSubject: true }, (subject, fileName, fileType = '') => {17 cy.log('Upload file: ' + fileName + ' with type: ' + fileType)18 return cy.get(subject).then(subject => {19 .fixture(fileName, 'base64')20 .then(Cypress.Blob.base64StringToBlob)21 .then(blob => {

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Read Files', () => {2 it('Read Files', () => {3 cy.readFile('test.json').then((data) => {4 cy.log(data)5 })6 })7})8{9}10{11 "env": {

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Read all files in the fixtures folder', function(){2 it('Read all files in the fixtures folder', function(){3 cy.readFile('cypress/fixtures')4 })5})6describe('Read all files in the fixtures folder', function(){7 it('Read all files in the fixtures folder', function(){8 cy.readFile('cypress/fixtures')9 })10})11describe('Read all files in the fixtures folder', function(){12 it('Read all files in the fixtures folder', function(){13 cy.readFile('cypress/fixtures')14 })15})16describe('Read all files in the fixtures folder', function(){17 it('Read all files in the fixtures folder', function(){18 cy.readFile('cypress/fixtures')19 })20})21describe('Read all files in the fixtures folder', function(){22 it('Read all files in the fixtures folder', function(){23 cy.readFile('cypress/fixtures')24 })25})26describe('Read all files in the fixtures folder', function(){27 it('Read all files in the fixtures folder', function(){28 cy.readFile('

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs')2describe('test', () => {3 it('test', () => {4 fs.readdir('./cypress/fixtures', (err, files) => {5 files.forEach(file => {6 cy.log(file)7 })8 })9 })10})11const fs = require('fs')12describe('test', () => {13 it('test', () => {14 fs.readdir('./cypress/fixtures', (err, files) => {15 files.forEach(file => {16 cy.log(file)17 cy.readFile('./cypress/fixtures/' + file).then((data) => {18 cy.log(data)19 })20 })21 })22 })23})24Cypress: How to use the cy.writeFile() method25Cypress: How to use the cy.readFile() method26Cypress: How to use the cy.fixture() method27Cypress: How to use the cy.intercept() method28Cypress: How to use the cy.wait() method29Cypress: How to use the cy.wrap() method30Cypress: How to use the cy.get() method31Cypress: How to use the cy.contains() method32Cypress: How to use the cy.visit() method33Cypress: How to use the cy.request() method34Cypress: How to use the cy.exec() method35Cypress: How to use the cy.task() method

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("Test file", () => {2 it("Test file contents", () => {3 cy.readFile("test.txt").then((text) => {4 cy.log(text);5 });6 cy.writeFile("test.txt", "Hello World");7 cy.readFile("test.txt").then((text) => {8 cy.log(text);9 });10 cy.writeFile("test.txt", "Hello World");11 cy.readFile("test.txt").then((text) => {12 cy.log(text);13 });14 cy.writeFile("test.txt", "Hello World");15 cy.readFile("test.txt").then((text) => {16 cy.log(text);17 });18 });19});20describe("Test file", () => {21 it("Test file contents", () => {22 cy.readFile("test.txt").then((text) => {23 cy.log(text);24 });25 cy.writeFile("test.txt", "Hello World");26 cy.readFile("test.txt").then((text) => {27 cy.log(text);28 });29 cy.writeFile("test.txt", "Hello World");30 cy.readFile("test.txt").then((text) => {31 cy.log(text);32 });33 cy.writeFile("test.txt", "Hello World");34 cy.readFile("test.txt").then((text) => {35 cy.log(text);36 });37 });38});39describe("Test file", () => {40 it("Test file contents", () => {41 cy.readFile("test.txt").then

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