Best JavaScript code snippet using cypress
test-x1-index.js
Source: test-x1-index.js
1/* eslint-disable brace-style */2/* eslint-disable no-path-concat */3'use strict';4var fs = require('fs');5var path = require('path');6var windows = process.platform === 'win32';7var theRequireContentA = './test-z-asset-A.css';8var theRequireContentB = 'test-z-asset-B.css';9function firstLowerCase (s) {10 return s.slice(0, 1).toLowerCase() + s.slice(1);11}12function firstUpperCase (s) {13 return s.slice(0, 1).toUpperCase() + s.slice(1);14}15console.log([16 fs.readFileSync(path.join(__dirname, theRequireContentA)),17 fs.readFileSync(__dirname + path.sep + theRequireContentB),18 fs.readFileSync(__dirname + '/' + theRequireContentB),19 windows ? fs.readFileSync(__dirname + '/\\' + theRequireContentB) : '',20 windows ? fs.readFileSync(__dirname + '\\' + theRequireContentB) : '',21 windows ? fs.readFileSync(__dirname + '\\/' + theRequireContentB) : '',22 fs.readFileSync(firstLowerCase(path.join(__dirname, theRequireContentA))),23 fs.readFileSync(firstLowerCase(__dirname + path.sep + theRequireContentB)),24 fs.readFileSync(firstLowerCase(__dirname + '/' + theRequireContentB)),25 windows ? fs.readFileSync(firstLowerCase(__dirname + '/\\' + theRequireContentB)) : '',26 windows ? fs.readFileSync(firstLowerCase(__dirname + '\\' + theRequireContentB)) : '',27 windows ? fs.readFileSync(firstLowerCase(__dirname + '\\/' + theRequireContentB)) : '',28 fs.readFileSync(firstUpperCase(path.join(__dirname, theRequireContentA))),29 fs.readFileSync(firstUpperCase(__dirname + path.sep + theRequireContentB)),30 fs.readFileSync(firstUpperCase(__dirname + '/' + theRequireContentB)),31 windows ? fs.readFileSync(firstUpperCase(__dirname + '/\\' + theRequireContentB)) : '',32 windows ? fs.readFileSync(firstUpperCase(__dirname + '\\' + theRequireContentB)) : '',33 windows ? fs.readFileSync(firstUpperCase(__dirname + '\\/' + theRequireContentB)) : '',34 //35 fs.readdirSync(__dirname).length > 0,36 fs.readdirSync(path.dirname(__dirname)).length > 0,37 fs.readdirSync(path.dirname(path.dirname(__dirname))).length > 0,38 fs.readdirSync(firstLowerCase(__dirname)).length > 0,39 fs.readdirSync(firstLowerCase(path.dirname(__dirname))).length > 0,40 fs.readdirSync(firstLowerCase(path.dirname(path.dirname(__dirname)))).length > 0,41 fs.readdirSync(firstUpperCase(__dirname)).length > 0,42 fs.readdirSync(firstUpperCase(path.dirname(__dirname))).length > 0,43 fs.readdirSync(firstUpperCase(path.dirname(path.dirname(__dirname)))).length > 0,44 //45 fs.existsSync(path.join(__dirname, theRequireContentA)),46 fs.existsSync(__dirname + path.sep + theRequireContentB),47 fs.existsSync(__dirname + '/' + theRequireContentB),48 windows ? fs.existsSync(__dirname + '/\\' + theRequireContentB) : '',49 windows ? fs.existsSync(__dirname + '\\' + theRequireContentB) : '',50 windows ? fs.existsSync(__dirname + '\\/' + theRequireContentB) : '',51 fs.existsSync(firstLowerCase(path.join(__dirname, theRequireContentA))),52 fs.existsSync(firstLowerCase(__dirname + path.sep + theRequireContentB)),53 fs.existsSync(firstLowerCase(__dirname + '/' + theRequireContentB)),54 windows ? fs.existsSync(firstLowerCase(__dirname + '/\\' + theRequireContentB)) : '',55 windows ? fs.existsSync(firstLowerCase(__dirname + '\\' + theRequireContentB)) : '',56 windows ? fs.existsSync(firstLowerCase(__dirname + '\\/' + theRequireContentB)) : '',57 fs.existsSync(firstUpperCase(path.join(__dirname, theRequireContentA))),58 fs.existsSync(firstUpperCase(__dirname + path.sep + theRequireContentB)),59 fs.existsSync(firstUpperCase(__dirname + '/' + theRequireContentB)),60 windows ? fs.existsSync(firstUpperCase(__dirname + '/\\' + theRequireContentB)) : '',61 windows ? fs.existsSync(firstUpperCase(__dirname + '\\' + theRequireContentB)) : '',62 windows ? fs.existsSync(firstUpperCase(__dirname + '\\/' + theRequireContentB)) : '',63 //64 fs.existsSync(path.join(__dirname, theRequireContentA + '-no-such')),65 fs.existsSync(__dirname + path.sep + theRequireContentB + '-no-such'),66 fs.existsSync(__dirname + '/' + theRequireContentB + '-no-such'),67 windows ? fs.existsSync(__dirname + '/\\' + theRequireContentB + '-no-such') : '',68 windows ? fs.existsSync(__dirname + '\\' + theRequireContentB + '-no-such') : '',69 windows ? fs.existsSync(__dirname + '\\/' + theRequireContentB + '-no-such') : '',70 fs.existsSync(firstLowerCase(path.join(__dirname, theRequireContentA + '-no-such'))),71 fs.existsSync(firstLowerCase(__dirname + path.sep + theRequireContentB + '-no-such')),72 fs.existsSync(firstLowerCase(__dirname + '/' + theRequireContentB + '-no-such')),73 windows ? fs.existsSync(firstLowerCase(__dirname + '/\\' + theRequireContentB + '-no-such')) : '',74 windows ? fs.existsSync(firstLowerCase(__dirname + '\\' + theRequireContentB + '-no-such')) : '',75 windows ? fs.existsSync(firstLowerCase(__dirname + '\\/' + theRequireContentB + '-no-such')) : '',76 fs.existsSync(firstUpperCase(path.join(__dirname, theRequireContentA + '-no-such'))),77 fs.existsSync(firstUpperCase(__dirname + path.sep + theRequireContentB + '-no-such')),78 fs.existsSync(firstUpperCase(__dirname + '/' + theRequireContentB + '-no-such')),79 windows ? fs.existsSync(firstUpperCase(__dirname + '/\\' + theRequireContentB + '-no-such')) : '',80 windows ? fs.existsSync(firstUpperCase(__dirname + '\\' + theRequireContentB + '-no-such')) : '',81 windows ? fs.existsSync(firstUpperCase(__dirname + '\\/' + theRequireContentB + '-no-such')) : '',82 //83 fs.accessSync(path.join(__dirname, theRequireContentA)),84 fs.accessSync(__dirname + path.sep + theRequireContentB),85 fs.accessSync(__dirname + '/' + theRequireContentB),86 windows ? fs.accessSync(__dirname + '/\\' + theRequireContentB) : '',87 windows ? fs.accessSync(__dirname + '\\' + theRequireContentB) : '',88 windows ? fs.accessSync(__dirname + '\\/' + theRequireContentB) : '',89 fs.accessSync(firstLowerCase(path.join(__dirname, theRequireContentA))),90 fs.accessSync(firstLowerCase(__dirname + path.sep + theRequireContentB)),91 fs.accessSync(firstLowerCase(__dirname + '/' + theRequireContentB)),92 windows ? fs.accessSync(firstLowerCase(__dirname + '/\\' + theRequireContentB)) : '',93 windows ? fs.accessSync(firstLowerCase(__dirname + '\\' + theRequireContentB)) : '',94 windows ? fs.accessSync(firstLowerCase(__dirname + '\\/' + theRequireContentB)) : '',95 fs.accessSync(firstUpperCase(path.join(__dirname, theRequireContentA))),96 fs.accessSync(firstUpperCase(__dirname + path.sep + theRequireContentB)),97 fs.accessSync(firstUpperCase(__dirname + '/' + theRequireContentB)),98 windows ? fs.accessSync(firstUpperCase(__dirname + '/\\' + theRequireContentB)) : '',99 windows ? fs.accessSync(firstUpperCase(__dirname + '\\' + theRequireContentB)) : '',100 windows ? fs.accessSync(firstUpperCase(__dirname + '\\/' + theRequireContentB)) : '',101 //102 fs.statSync(path.join(__dirname, theRequireContentA)).mode,103 fs.statSync(__dirname + path.sep + theRequireContentB).mode,104 fs.statSync(__dirname + '/' + theRequireContentB).mode,105 windows ? fs.statSync(__dirname + '/\\' + theRequireContentB).mode : '',106 windows ? fs.statSync(__dirname + '\\' + theRequireContentB).mode : '',107 windows ? fs.statSync(__dirname + '\\/' + theRequireContentB).mode : '',108 fs.statSync(firstLowerCase(path.join(__dirname, theRequireContentA))).mode,109 fs.statSync(firstLowerCase(__dirname + path.sep + theRequireContentB)).mode,110 fs.statSync(firstLowerCase(__dirname + '/' + theRequireContentB)).mode,111 windows ? fs.statSync(firstLowerCase(__dirname + '/\\' + theRequireContentB)).mode : '',112 windows ? fs.statSync(firstLowerCase(__dirname + '\\' + theRequireContentB)).mode : '',113 windows ? fs.statSync(firstLowerCase(__dirname + '\\/' + theRequireContentB)).mode : '',114 fs.statSync(firstUpperCase(path.join(__dirname, theRequireContentA))).mode,115 fs.statSync(firstUpperCase(__dirname + path.sep + theRequireContentB)).mode,116 fs.statSync(firstUpperCase(__dirname + '/' + theRequireContentB)).mode,117 windows ? fs.statSync(firstUpperCase(__dirname + '/\\' + theRequireContentB)).mode : '',118 windows ? fs.statSync(firstUpperCase(__dirname + '\\' + theRequireContentB)).mode : '',119 windows ? fs.statSync(firstUpperCase(__dirname + '\\/' + theRequireContentB)).mode : '',120 //121 fs.statSync(path.join(__dirname, theRequireContentA)).birthtime.getYear(),122 fs.statSync(__dirname + path.sep + theRequireContentB).birthtime.getYear(),123 fs.statSync(__dirname + '/' + theRequireContentB).birthtime.getYear(),124 windows ? fs.statSync(__dirname + '/\\' + theRequireContentB).birthtime.getYear() : '',125 windows ? fs.statSync(__dirname + '\\' + theRequireContentB).birthtime.getYear() : '',126 windows ? fs.statSync(__dirname + '\\/' + theRequireContentB).birthtime.getYear() : '',127 fs.statSync(firstLowerCase(path.join(__dirname, theRequireContentA))).birthtime.getYear(),128 fs.statSync(firstLowerCase(__dirname + path.sep + theRequireContentB)).birthtime.getYear(),129 fs.statSync(firstLowerCase(__dirname + '/' + theRequireContentB)).birthtime.getYear(),130 windows ? fs.statSync(firstLowerCase(__dirname + '/\\' + theRequireContentB)).birthtime.getYear() : '',131 windows ? fs.statSync(firstLowerCase(__dirname + '\\' + theRequireContentB)).birthtime.getYear() : '',132 windows ? fs.statSync(firstLowerCase(__dirname + '\\/' + theRequireContentB)).birthtime.getYear() : '',133 fs.statSync(firstUpperCase(path.join(__dirname, theRequireContentA))).birthtime.getYear(),134 fs.statSync(firstUpperCase(__dirname + path.sep + theRequireContentB)).birthtime.getYear(),135 fs.statSync(firstUpperCase(__dirname + '/' + theRequireContentB)).birthtime.getYear(),136 windows ? fs.statSync(firstUpperCase(__dirname + '/\\' + theRequireContentB)).birthtime.getYear() : '',137 windows ? fs.statSync(firstUpperCase(__dirname + '\\' + theRequireContentB)).birthtime.getYear() : '',138 windows ? fs.statSync(firstUpperCase(__dirname + '\\/' + theRequireContentB)).birthtime.getYear() : '',139 //140 fs.statSync(path.join(__dirname, theRequireContentA)).isFile(),141 fs.statSync(__dirname + path.sep + theRequireContentB).isFile(),142 fs.statSync(__dirname + '/' + theRequireContentB).isFile(),143 windows ? fs.statSync(__dirname + '/\\' + theRequireContentB).isFile() : '',144 windows ? fs.statSync(__dirname + '\\' + theRequireContentB).isFile() : '',145 windows ? fs.statSync(__dirname + '\\/' + theRequireContentB).isFile() : '',146 fs.statSync(firstLowerCase(path.join(__dirname, theRequireContentA))).isFile(),147 fs.statSync(firstLowerCase(__dirname + path.sep + theRequireContentB)).isFile(),148 fs.statSync(firstLowerCase(__dirname + '/' + theRequireContentB)).isFile(),149 windows ? fs.statSync(firstLowerCase(__dirname + '/\\' + theRequireContentB)).isFile() : '',150 windows ? fs.statSync(firstLowerCase(__dirname + '\\' + theRequireContentB)).isFile() : '',151 windows ? fs.statSync(firstLowerCase(__dirname + '\\/' + theRequireContentB)).isFile() : '',152 fs.statSync(firstUpperCase(path.join(__dirname, theRequireContentA))).isFile(),153 fs.statSync(firstUpperCase(__dirname + path.sep + theRequireContentB)).isFile(),154 fs.statSync(firstUpperCase(__dirname + '/' + theRequireContentB)).isFile(),155 windows ? fs.statSync(firstUpperCase(__dirname + '/\\' + theRequireContentB)).isFile() : '',156 windows ? fs.statSync(firstUpperCase(__dirname + '\\' + theRequireContentB)).isFile() : '',157 windows ? fs.statSync(firstUpperCase(__dirname + '\\/' + theRequireContentB)).isFile() : '',158 //159 fs.statSync(path.join(__dirname, theRequireContentA)).isDirectory(),160 fs.statSync(__dirname + path.sep + theRequireContentB).isDirectory(),161 fs.statSync(__dirname + '/' + theRequireContentB).isDirectory(),162 windows ? fs.statSync(__dirname + '/\\' + theRequireContentB).isDirectory() : '',163 windows ? fs.statSync(__dirname + '\\' + theRequireContentB).isDirectory() : '',164 windows ? fs.statSync(__dirname + '\\/' + theRequireContentB).isDirectory() : '',165 fs.statSync(firstLowerCase(path.join(__dirname, theRequireContentA))).isDirectory(),166 fs.statSync(firstLowerCase(__dirname + path.sep + theRequireContentB)).isDirectory(),167 fs.statSync(firstLowerCase(__dirname + '/' + theRequireContentB)).isDirectory(),168 windows ? fs.statSync(firstLowerCase(__dirname + '/\\' + theRequireContentB)).isDirectory() : '',169 windows ? fs.statSync(firstLowerCase(__dirname + '\\' + theRequireContentB)).isDirectory() : '',170 windows ? fs.statSync(firstLowerCase(__dirname + '\\/' + theRequireContentB)).isDirectory() : '',171 fs.statSync(firstUpperCase(path.join(__dirname, theRequireContentA))).isDirectory(),172 fs.statSync(firstUpperCase(__dirname + path.sep + theRequireContentB)).isDirectory(),173 fs.statSync(firstUpperCase(__dirname + '/' + theRequireContentB)).isDirectory(),174 windows ? fs.statSync(firstUpperCase(__dirname + '/\\' + theRequireContentB)).isDirectory() : '',175 windows ? fs.statSync(firstUpperCase(__dirname + '\\' + theRequireContentB)).isDirectory() : '',176 windows ? fs.statSync(firstUpperCase(__dirname + '\\/' + theRequireContentB)).isDirectory() : '',177 //178 fs.lstatSync(path.join(__dirname, theRequireContentA)).mode,179 fs.lstatSync(__dirname + path.sep + theRequireContentB).mode,180 fs.lstatSync(__dirname + '/' + theRequireContentB).mode,181 windows ? fs.lstatSync(__dirname + '/\\' + theRequireContentB).mode : '',182 windows ? fs.lstatSync(__dirname + '\\' + theRequireContentB).mode : '',183 windows ? fs.lstatSync(__dirname + '\\/' + theRequireContentB).mode : '',184 fs.lstatSync(firstLowerCase(path.join(__dirname, theRequireContentA))).mode,185 fs.lstatSync(firstLowerCase(__dirname + path.sep + theRequireContentB)).mode,186 fs.lstatSync(firstLowerCase(__dirname + '/' + theRequireContentB)).mode,187 windows ? fs.lstatSync(firstLowerCase(__dirname + '/\\' + theRequireContentB)).mode : '',188 windows ? fs.lstatSync(firstLowerCase(__dirname + '\\' + theRequireContentB)).mode : '',189 windows ? fs.lstatSync(firstLowerCase(__dirname + '\\/' + theRequireContentB)).mode : '',190 fs.lstatSync(firstUpperCase(path.join(__dirname, theRequireContentA))).mode,191 fs.lstatSync(firstUpperCase(__dirname + path.sep + theRequireContentB)).mode,192 fs.lstatSync(firstUpperCase(__dirname + '/' + theRequireContentB)).mode,193 windows ? fs.lstatSync(firstUpperCase(__dirname + '/\\' + theRequireContentB)).mode : '',194 windows ? fs.lstatSync(firstUpperCase(__dirname + '\\' + theRequireContentB)).mode : '',195 windows ? fs.lstatSync(firstUpperCase(__dirname + '\\/' + theRequireContentB)).mode : '',196 //197 fs.realpathSync(path.join(__dirname, theRequireContentA)).mode,198 fs.realpathSync(__dirname + path.sep + theRequireContentB).mode,199 fs.realpathSync(__dirname + '/' + theRequireContentB).mode,200 windows ? fs.realpathSync(__dirname + '/\\' + theRequireContentB).mode : '',201 windows ? fs.realpathSync(__dirname + '\\' + theRequireContentB).mode : '',202 windows ? fs.realpathSync(__dirname + '\\/' + theRequireContentB).mode : '',203 fs.realpathSync(firstLowerCase(path.join(__dirname, theRequireContentA))).mode,204 fs.realpathSync(firstLowerCase(__dirname + path.sep + theRequireContentB)).mode,205 fs.realpathSync(firstLowerCase(__dirname + '/' + theRequireContentB)).mode,206 windows ? fs.realpathSync(firstLowerCase(__dirname + '/\\' + theRequireContentB)).mode : '',207 windows ? fs.realpathSync(firstLowerCase(__dirname + '\\' + theRequireContentB)).mode : '',208 windows ? fs.realpathSync(firstLowerCase(__dirname + '\\/' + theRequireContentB)).mode : '',209 fs.realpathSync(firstUpperCase(path.join(__dirname, theRequireContentA))).mode,210 fs.realpathSync(firstUpperCase(__dirname + path.sep + theRequireContentB)).mode,211 fs.realpathSync(firstUpperCase(__dirname + '/' + theRequireContentB)).mode,212 windows ? fs.realpathSync(firstUpperCase(__dirname + '/\\' + theRequireContentB)).mode : '',213 windows ? fs.realpathSync(firstUpperCase(__dirname + '\\' + theRequireContentB)).mode : '',214 windows ? fs.realpathSync(firstUpperCase(__dirname + '\\/' + theRequireContentB)).mode : ''...
test_ftp.js
Source: test_ftp.js
1/*2 * Copyright (c) 2013-2014 Tim Burgess. All rights reserved.3 * 4 * @author Tim Burgess <info@tim-burgess.com>5 * @license Tim Burgess 20146 */7/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4,8maxerr: 50, node: true, white: true, evil: true */9/*globals HOST:true,PORT:true,USER:true,PWD:true,LOCALROOT:true,REMOTEROOT:true,ftp:true,emit:true,_domainManager:true,connect*/10 11 var assert = require("assert"),12 fs = require("fs"),13 util = require("util"),14 events = require("events"),15 rimraf = require("rimraf");16 17 18 function MockDomainManager() {19 this._eventCount = 0;20 }21 util.inherits(MockDomainManager, events.EventEmitter);22 MockDomainManager.prototype.emitEvent = function(domainName, eventName, parameters) {23 if (parameters)24 console.log("[%s] %s", eventName, parameters);25 else26 console.log("[%s]", eventName);27 if (eventName !== 'error') {28 this.emit(eventName);29 }30 ++this._eventCount;31 };32 // load ftp settings33 var config = require('./config.json');34 35 // load node-side36 var ftpsync = require("../core.js");37 38 // mock domainmanager for event capture39 var _domainManager = new MockDomainManager();40 var opts = {41 // we don't set connect option as ftp should be the default42 host: config.host,43 port: 21,44 user: config.user,45 pwd: config.pwd,46 privateKey: config.privateKey,47 passphrase: config.passphrase48// debug: console.log49 };50 var localRoot = "";51 // directory where ftp server puts you at login52 var LOCALPREFIX = config.localprefix;53 54 // the remote root directory is located locally, so we use fs55 // and LOCALPATH for asserting presence & size of test files 56 var LOCALPATH;57 58 // before each test, rm -rf ftptest59 describe('FTP-Sync', function() {60 beforeEach(function(done) {61 rimraf.sync(LOCALPREFIX + '/ftptest');62 done();63 });64 65 describe('FTP test:', function() {66 it('sync file changes', function(done) {67 68 localRoot = "./testdata/test1";69 opts.remoteRoot = "ftptest/public_html";70 LOCALPATH = LOCALPREFIX + '/' + opts.remoteRoot;71 // create public_html dir72 fs.mkdirSync(LOCALPREFIX + '/ftptest');73 fs.mkdirSync(LOCALPATH);74 ftpsync.connect(opts, localRoot, _domainManager);75 // wait for disconnect and then assert files exist76 _domainManager.once('disconnected', function() {77 // assert file state78 stats = fs.statSync(LOCALPATH + '/bin.py');79 assert.equal(stats.size, 220);80 stats = fs.statSync(LOCALPATH + '/index.html');81 assert.equal(stats.size, 136);82 stats = fs.statSync(LOCALPATH + '/re.py');83 assert.equal(stats.size, 444);84 localRoot = "./testdata/test1A";85 ftpsync.connect(opts, localRoot, _domainManager);86 _domainManager.once('disconnected', function() {87 // assert file state88 stats = fs.statSync(LOCALPATH + '/bin.py');89 assert.equal(stats.size, 220);90 stats = fs.statSync(LOCALPATH + '/foo.html');91 assert.equal(stats.size, 72);92 stats = fs.statSync(LOCALPATH + '/index.html');93 assert.equal(stats.size, 165);94 stats = fs.statSync(LOCALPATH + '/re.py');95 assert.equal(stats.size, 444);96 done();97 });98 });99 });100 101 it('sync dir and file changes', function(done) {102 localRoot = "./testdata/test2";103 opts.remoteRoot = "ftptest/public_html";104 LOCALPATH = LOCALPREFIX + '/' + opts.remoteRoot;105 // create public_html dir106 fs.mkdirSync(LOCALPREFIX + '/ftptest');107 fs.mkdirSync(LOCALPATH);108 ftpsync.connect(opts, localRoot, _domainManager);109 // wait for disconnect and then assert files exist110 _domainManager.once('disconnected', function() {111 // assert file state112 stats = fs.statSync(LOCALPATH + '/bin.py');113 assert.equal(stats.size, 220);114 stats = fs.statSync(LOCALPATH + '/index.html');115 assert.equal(stats.size, 136);116 // check for presence of subdir and file inside117 stats = fs.statSync(LOCALPATH + '/code');118 assert(stats.isDirectory);119 stats = fs.statSync(LOCALPATH + '/code/re.py');120 assert.equal(stats.size, 444);121 done();122 });123 });124 125 it('sync directory structure to ftp root', function(done) {126 localRoot = "./testdata/test3";127 opts.remoteRoot = ".";128 LOCALPATH = LOCALPREFIX;129 ftpsync.connect(opts, localRoot, _domainManager);130 // wait for disconnect and then assert files exist131 _domainManager.once('disconnected', function() {132 // check for presence of subdir and file inside133 stats = fs.statSync(LOCALPATH + '/ftptest');134 assert(stats.isDirectory);135 stats = fs.statSync(LOCALPATH + '/ftptest/application');136 assert(stats.isDirectory);137 stats = fs.statSync(LOCALPATH + '/ftptest/application/cache');138 assert(stats.isDirectory);139 stats = fs.statSync(LOCALPATH + '/ftptest/application/cache/index.html');140 assert.equal(stats.size, 136);141 stats = fs.statSync(LOCALPATH + '/ftptest/application/views');142 assert(stats.isDirectory);143 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix');144 assert(stats.isDirectory);145 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix/bogus.php');146 assert.equal(stats.size, 444);147 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix/some_long_filename.php');148 assert.equal(stats.size, 220);149 done();150 });151 });152 it('sync directory structure to empty string remoteroot', function(done) {153 localRoot = "./testdata/test3";154 opts.remoteRoot = "";155 LOCALPATH = LOCALPREFIX;156 ftpsync.connect(opts, localRoot, _domainManager);157 // wait for disconnect and then assert files exist158 _domainManager.once('disconnected', function() {159 // check for presence of subdir and file inside160 stats = fs.statSync(LOCALPATH + '/ftptest');161 assert(stats.isDirectory);162 stats = fs.statSync(LOCALPATH + '/ftptest/application');163 assert(stats.isDirectory);164 stats = fs.statSync(LOCALPATH + '/ftptest/application/cache');165 assert(stats.isDirectory);166 stats = fs.statSync(LOCALPATH + '/ftptest/application/cache/index.html');167 assert.equal(stats.size, 136);168 stats = fs.statSync(LOCALPATH + '/ftptest/application/views');169 assert(stats.isDirectory);170 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix');171 assert(stats.isDirectory);172 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix/bogus.php');173 assert.equal(stats.size, 444);174 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix/some_long_filename.php');175 assert.equal(stats.size, 220);176 done();177 });178 });179 it('sync directory structure to null remoteroot', function(done) {180 localRoot = "./testdata/test3";181 opts.remoteRoot = null;182 LOCALPATH = LOCALPREFIX;183 ftpsync.connect(opts, localRoot, _domainManager);184 // wait for disconnect and then assert files exist185 _domainManager.once('disconnected', function() {186 // check for presence of subdir and file inside187 stats = fs.statSync(LOCALPATH + '/ftptest');188 assert(stats.isDirectory);189 stats = fs.statSync(LOCALPATH + '/ftptest/application');190 assert(stats.isDirectory);191 stats = fs.statSync(LOCALPATH + '/ftptest/application/cache');192 assert(stats.isDirectory);193 stats = fs.statSync(LOCALPATH + '/ftptest/application/cache/index.html');194 assert.equal(stats.size, 136);195 stats = fs.statSync(LOCALPATH + '/ftptest/application/views');196 assert(stats.isDirectory);197 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix');198 assert(stats.isDirectory);199 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix/bogus.php');200 assert.equal(stats.size, 444);201 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix/some_long_filename.php');202 assert.equal(stats.size, 220);203 done();204 });205 });206 it('sync directory structure to undefined remoteroot', function(done) {207 localRoot = "./testdata/test3";208 opts.remoteRoot = undefined;209 LOCALPATH = LOCALPREFIX;210 ftpsync.connect(opts, localRoot, _domainManager);211 // wait for disconnect and then assert files exist212 _domainManager.once('disconnected', function() {213 // check for presence of subdir and file inside214 stats = fs.statSync(LOCALPATH + '/ftptest');215 assert(stats.isDirectory);216 stats = fs.statSync(LOCALPATH + '/ftptest/application');217 assert(stats.isDirectory);218 stats = fs.statSync(LOCALPATH + '/ftptest/application/cache');219 assert(stats.isDirectory);220 stats = fs.statSync(LOCALPATH + '/ftptest/application/cache/index.html');221 assert.equal(stats.size, 136);222 stats = fs.statSync(LOCALPATH + '/ftptest/application/views');223 assert(stats.isDirectory);224 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix');225 assert(stats.isDirectory);226 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix/bogus.php');227 assert.equal(stats.size, 444);228 stats = fs.statSync(LOCALPATH + '/ftptest/application/views/generix/some_long_filename.php');229 assert.equal(stats.size, 220);230 done();231 });232 });233 }); ...
settings_spec.js
Source: settings_spec.js
...83 await fs.writeFile( path.join(userDir,".config.nodes.json"),JSON.stringify({a:1}),"utf8");84 await fs.writeFile( path.join(userDir,".config.users.json"),JSON.stringify({b:2}),"utf8");85 await fs.writeFile( path.join(userDir,".config.projects.json"),JSON.stringify({c:3}),"utf8");86 await fs.writeFile( path.join(userDir,".config.runtime.json"),JSON.stringify({_credentialSecret:"foo"}),"utf8");87 const fsStatNodes = await fs.stat(path.join(userDir,".config.nodes.json"))88 const fsStatUsers = await fs.stat(path.join(userDir,".config.users.json"))89 const fsStatProjects = await fs.stat(path.join(userDir,".config.projects.json"))90 const fsStatRuntime = await fs.stat(path.join(userDir,".config.runtime.json"))91 return localfilesystemSettings.init({userDir:userDir}).then(function() {92 return new Promise(res => {93 setTimeout(function() {94 res();95 },10)96 });97 }).then(() => {98 return localfilesystemSettings.saveSettings({99 nodes:{d:4},100 _credentialSecret: "bar",101 users:{b:2},102 projects: {c:3}103 })104 }).then(async function() {105 const newFsStatNodes = await fs.stat(path.join(userDir,".config.nodes.json"))106 const newFsStatUsers = await fs.stat(path.join(userDir,".config.users.json"))107 const newFsStatProjects = await fs.stat(path.join(userDir,".config.projects.json"))108 const newFsStatRuntime = await fs.stat(path.join(userDir,".config.runtime.json"))109 // Not changed110 newFsStatUsers.mtimeMs.should.eql(fsStatUsers.mtimeMs);111 newFsStatProjects.mtimeMs.should.eql(fsStatProjects.mtimeMs);112 // Changed113 newFsStatNodes.mtimeMs.should.not.eql(fsStatNodes.mtimeMs);114 newFsStatRuntime.mtimeMs.should.not.eql(fsStatRuntime.mtimeMs);115 })116 });...
rebuild.js
Source: rebuild.js
1const t = require('tap')2const fs = require('fs')3const { resolve } = require('path')4const { fake: mockNpm } = require('../../fixtures/mock-npm')5let result = ''6const config = {7 global: false,8}9const npm = mockNpm({10 globalDir: '',11 config,12 prefix: '',13 output: (...msg) => {14 result += msg.join('\n')15 },16})17const Rebuild = require('../../../lib/commands/rebuild.js')18const rebuild = new Rebuild(npm)19t.afterEach(() => {20 npm.prefix = ''21 config.global = false22 npm.globalDir = ''23 result = ''24})25t.test('no args', async t => {26 const path = t.testdir({27 node_modules: {28 a: {29 'package.json': JSON.stringify({30 name: 'a',31 version: '1.0.0',32 bin: 'cwd',33 scripts: {34 preinstall: "node -e \"require('fs').writeFileSync('cwd', '')\"",35 },36 }),37 },38 b: {39 'package.json': JSON.stringify({40 name: 'b',41 version: '1.0.0',42 bin: 'cwd',43 scripts: {44 preinstall: "node -e \"require('fs').writeFileSync('cwd', '')\"",45 },46 }),47 },48 },49 })50 const aBuildFile = resolve(path, 'node_modules/a/cwd')51 const bBuildFile = resolve(path, 'node_modules/b/cwd')52 const aBinFile = resolve(path, 'node_modules/.bin/a')53 const bBinFile = resolve(path, 'node_modules/.bin/b')54 t.throws(() => fs.statSync(aBuildFile))55 t.throws(() => fs.statSync(bBuildFile))56 t.throws(() => fs.statSync(aBinFile))57 t.throws(() => fs.statSync(bBinFile))58 npm.prefix = path59 await rebuild.exec([])60 t.ok(() => fs.statSync(aBuildFile))61 t.ok(() => fs.statSync(bBuildFile))62 t.ok(() => fs.statSync(aBinFile))63 t.ok(() => fs.statSync(bBinFile))64 t.equal(65 result,66 'rebuilt dependencies successfully',67 'should output success msg'68 )69})70t.test('filter by pkg name', async t => {71 const path = t.testdir({72 node_modules: {73 a: {74 'index.js': '',75 'package.json': JSON.stringify({76 name: 'a',77 version: '1.0.0',78 bin: 'index.js',79 }),80 },81 b: {82 'index.js': '',83 'package.json': JSON.stringify({84 name: 'b',85 version: '1.0.0',86 bin: 'index.js',87 }),88 },89 },90 })91 npm.prefix = path92 const aBinFile = resolve(path, 'node_modules/.bin/a')93 const bBinFile = resolve(path, 'node_modules/.bin/b')94 t.throws(() => fs.statSync(aBinFile))95 t.throws(() => fs.statSync(bBinFile))96 await rebuild.exec(['b'])97 t.throws(() => fs.statSync(aBinFile), 'should not link a bin')98 t.ok(() => fs.statSync(bBinFile), 'should link filtered pkg bin')99})100t.test('filter by pkg@<range>', async t => {101 const path = t.testdir({102 node_modules: {103 a: {104 'index.js': '',105 'package.json': JSON.stringify({106 name: 'a',107 version: '1.0.0',108 bin: 'index.js',109 }),110 node_modules: {111 b: {112 'index.js': '',113 'package.json': JSON.stringify({114 name: 'b',115 version: '2.0.0',116 bin: 'index.js',117 }),118 },119 },120 },121 b: {122 'index.js': '',123 'package.json': JSON.stringify({124 name: 'b',125 version: '1.0.0',126 bin: 'index.js',127 }),128 },129 },130 })131 npm.prefix = path132 const bBinFile = resolve(path, 'node_modules/.bin/b')133 const nestedBinFile = resolve(path, 'node_modules/a/node_modules/.bin/b')134 await rebuild.exec(['b@2'])135 t.throws(() => fs.statSync(bBinFile), 'should not link b bin')136 t.ok(() => fs.statSync(nestedBinFile), 'should link filtered pkg bin')137})138t.test('filter by directory', async t => {139 const path = t.testdir({140 node_modules: {141 a: {142 'index.js': '',143 'package.json': JSON.stringify({144 name: 'a',145 version: '1.0.0',146 bin: 'index.js',147 }),148 },149 b: {150 'index.js': '',151 'package.json': JSON.stringify({152 name: 'b',153 version: '1.0.0',154 bin: 'index.js',155 }),156 },157 },158 })159 npm.prefix = path160 const aBinFile = resolve(path, 'node_modules/.bin/a')161 const bBinFile = resolve(path, 'node_modules/.bin/b')162 t.throws(() => fs.statSync(aBinFile))163 t.throws(() => fs.statSync(bBinFile))164 await rebuild.exec(['file:node_modules/b'])165 t.throws(() => fs.statSync(aBinFile), 'should not link a bin')166 t.ok(() => fs.statSync(bBinFile), 'should link filtered pkg bin')167})168t.test('filter must be a semver version/range, or directory', async t => {169 await t.rejects(170 rebuild.exec(['git+ssh://github.com/npm/arborist']),171 /`npm rebuild` only supports SemVer version\/range specifiers/,172 'should throw type error'173 )174})175t.test('global prefix', async t => {176 const globalPath = t.testdir({177 lib: {178 node_modules: {179 a: {180 'index.js': '',181 'package.json': JSON.stringify({182 name: 'a',183 version: '1.0.0',184 bin: 'index.js',185 }),186 },187 },188 },189 })190 config.global = true191 npm.globalDir = resolve(globalPath, 'lib', 'node_modules')192 await rebuild.exec([])193 t.ok(() => fs.statSync(resolve(globalPath, 'lib/node_modules/.bin/a')))194 t.equal(195 result,196 'rebuilt dependencies successfully',197 'should output success msg'198 )...
test.js
Source: test.js
1'use strict';2/* eslint-env mocha */3var fs = require('fs');4var assert = require('assert');5var hashes = {6 'test/fixtures/file.png': 'test/tmp/file.26365248.png',7 'test/fixtures/cfgfile.png': 'test/tmp/cfgfile.da63.png',8 'test/fixtures/math.js': 'test/tmp/withSourceMaps/math.6272e937.js',9 'test/fixtures/math.js.map': 'test/tmp/withSourceMaps/math.6272e937.js.map',10 'test/fixtures/physics.js': 'test/tmp/withSourceMaps/physics.28cb15fd.js',11 'test/fixtures/styles.css': 'test/tmp/withSourceMaps/styles.a6aa2292.css',12 'test/fixtures/styles.css.map': 'test/tmp/withSourceMaps/styles.a6aa2292.css.map',13 'test/fixtures/more-styles.css': 'test/tmp/withSourceMaps/more-styles.dce8e0e5.css',14 'test/fixtures/inline.js': 'test/tmp/withSourceMaps/inline.8b435ef2.js',15 'test/fixtures/another.png': 'test/tmp/another-processed-92279d3f.png'16};17it('should revision files based on content', function () {18 var file = 'test/fixtures/file.png';19 var original = fs.statSync(file).size;20 var revisioned = fs.statSync(hashes[file]).size;21 assert(revisioned === original);22});23it('should accept options', function () {24 var file = 'test/fixtures/cfgfile.png';25 var original = fs.statSync(file).size;26 var revisioned = fs.statSync(hashes[file]).size;27 assert(revisioned === original);28});29it('should allow a dest directory option', function () {30 var file = 'test/fixtures/file.png';31 var original = fs.statSync(file).size;32 var revisioned = fs.statSync(hashes[file]).size;33 assert(revisioned === original);34});35it('should allow sources defined with expand', function () {36 var file = 'test/fixtures/file.png';37 var original = fs.statSync(file).size;38 var revisioned = fs.statSync(hashes[file]).size;39 assert(revisioned === original);40});41it('should use same revision as .js source for the .map', function () {42 var file = 'test/fixtures/math.js.map';43 var original = fs.statSync(file).size;44 var revisioned = fs.statSync(hashes[file]).size;45 assert(revisioned === original);46});47it('should point the .js sourceMappingURL to the revisioned .map', function () {48 var file = 'test/fixtures/math.js';49 var map = 'math.6272e937.js.map';50 var revisioned = fs.readFileSync(hashes[file], {encoding: 'utf8'});51 assert(revisioned.indexOf('//# sourceMappingURL=' + map) !== -1);52});53it('should revision .js file ok without any .map', function () {54 var file = 'test/fixtures/physics.js';55 var original = fs.statSync(file).size;56 var revisioned = fs.statSync(hashes[file]).size;57 assert(revisioned === original);58});59it('should use same revision as .css source for the .map', function () {60 var file = 'test/fixtures/styles.css.map';61 var original = fs.statSync(file).size;62 var revisioned = fs.statSync(hashes[file]).size;63 assert(revisioned === original);64});65it('should point the .css sourceMappingURL to the revisioned .map', function () {66 var file = 'test/fixtures/styles.css';67 var map = 'styles.a6aa2292.css.map';68 var revisioned = fs.readFileSync(hashes[file], {encoding: 'utf8'});69 assert(revisioned.indexOf('/*# sourceMappingURL=' + map) !== -1);70});71it('should revision .css file ok without any .map', function () {72 var file = 'test/fixtures/more-styles.css';73 var original = fs.statSync(file).size;74 var revisioned = fs.statSync(hashes[file]).size;75 assert(revisioned === original);76});77it('should ignore inline base64-encoded sourcemaps', function () {78 var file = 'test/fixtures/inline.js';79 var original = fs.statSync(file).size;80 var revisioned = fs.statSync(hashes[file]).size;81 assert(revisioned === original);82});83it('should allow a filename processing function', function () {84 var file = 'test/fixtures/another.png';85 var original = fs.statSync(file).size;86 var revisioned = fs.statSync(hashes[file]).size;87 assert(revisioned === original);...
chmod.js
Source: chmod.js
1var shell = require('..');2var assert = require('assert'),3 path = require('path'),4 fs = require('fs');5shell.config.silent = true;6//7// Invalids8//9shell.chmod('blah'); // missing args10assert.ok(shell.error());11shell.chmod('893', 'resources/chmod'); // invalid permissions - mode must be in octal12assert.ok(shell.error());13//14// Valids15//16// Test files - the bitmasking is to ignore the upper bits.17shell.chmod('755', 'resources/chmod/file1');18assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('755', 8));19shell.chmod('644', 'resources/chmod/file1');20assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8));21shell.chmod('o+x', 'resources/chmod/file1');22assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('007', 8), parseInt('005', 8));23shell.chmod('644', 'resources/chmod/file1');24shell.chmod('+x', 'resources/chmod/file1');25assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('755', 8));26shell.chmod('644', 'resources/chmod/file1');27// Test setuid28shell.chmod('u+s', 'resources/chmod/file1');29assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('4000', 8), parseInt('4000', 8));30shell.chmod('u-s', 'resources/chmod/file1');31assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8));32// according to POSIX standards at http://linux.die.net/man/1/chmod,33// setuid is never cleared from a directory unless explicitly asked for.34shell.chmod('u+s', 'resources/chmod/c');35shell.chmod('755', 'resources/chmod/c');36assert.equal(fs.statSync('resources/chmod/c').mode & parseInt('4000', 8), parseInt('4000', 8));37shell.chmod('u-s', 'resources/chmod/c');38// Test setgid39shell.chmod('g+s', 'resources/chmod/file1');40assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('2000', 8), parseInt('2000', 8));41shell.chmod('g-s', 'resources/chmod/file1');42assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8));43// Test sticky bit44shell.chmod('+t', 'resources/chmod/file1');45assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('1000', 8), parseInt('1000', 8));46shell.chmod('-t', 'resources/chmod/file1');47assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8));48assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('1000', 8), 0);49// Test directories50shell.chmod('a-w', 'resources/chmod/b/a/b');51assert.equal(fs.statSync('resources/chmod/b/a/b').mode & parseInt('777', 8), parseInt('555', 8));52shell.chmod('755', 'resources/chmod/b/a/b');53// Test recursion54shell.chmod('-R', 'a+w', 'resources/chmod/b');55assert.equal(fs.statSync('resources/chmod/b/a/b').mode & parseInt('777', 8), parseInt('777', 8));56shell.chmod('-R', '755', 'resources/chmod/b');57assert.equal(fs.statSync('resources/chmod/b/a/b').mode & parseInt('777', 8), parseInt('755', 8));58// Test symbolic links w/ recursion - WARNING: *nix only59fs.symlinkSync('resources/chmod/b/a', 'resources/chmod/a/b/c/link', 'dir');60shell.chmod('-R', 'u-w', 'resources/chmod/a/b');61assert.equal(fs.statSync('resources/chmod/a/b/c').mode & parseInt('700', 8), parseInt('500', 8));62assert.equal(fs.statSync('resources/chmod/b/a').mode & parseInt('700', 8), parseInt('700', 8));63shell.chmod('-R', 'u+w', 'resources/chmod/a/b');64fs.unlinkSync('resources/chmod/a/b/c/link');...
test-fs-truncate.js
Source: test-fs-truncate.js
...47});48function testTruncate(cb) {49 fs.writeFile(filename, data, function(er) {50 if (er) return cb(er);51 fs.stat(filename, function(er, stat) {52 if (er) return cb(er);53 assert.equal(stat.size, 1024 * 16);54 fs.truncate(filename, 1024, function(er) {55 if (er) return cb(er);56 fs.stat(filename, function(er, stat) {57 if (er) return cb(er);58 assert.equal(stat.size, 1024);59 fs.truncate(filename, function(er) {60 if (er) return cb(er);61 fs.stat(filename, function(er, stat) {62 if (er) return cb(er);63 assert.equal(stat.size, 0);64 cb();65 });66 });67 });68 });69 });70 });71}72function testFtruncate(cb) {73 fs.writeFile(filename, data, function(er) {74 if (er) return cb(er);75 fs.stat(filename, function(er, stat) {76 if (er) return cb(er);77 assert.equal(stat.size, 1024 * 16);78 fs.open(filename, 'w', function(er, fd) {79 if (er) return cb(er);80 fs.ftruncate(fd, 1024, function(er) {81 if (er) return cb(er);82 fs.stat(filename, function(er, stat) {83 if (er) return cb(er);84 assert.equal(stat.size, 1024);85 fs.ftruncate(fd, function(er) {86 if (er) return cb(er);87 fs.stat(filename, function(er, stat) {88 if (er) return cb(er);89 assert.equal(stat.size, 0);90 fs.close(fd, cb);91 });92 });93 });94 });95 });96 });97 });...
main.js
Source: main.js
1/*!2 * æ件æè¿°3 * @author ydr.me4 * @create 2015-05-04 02:465 */6'use strict';7var co = require('co');8var fs = require('fs');9var path = require('path');10var expect = require('chai').expect;11var po = require('../index.js');12describe('main', function () {13 it('fs.stat exist file', function (done) {14 var fsStat = po(fs.stat, fs);15 co(function* () {16 return yield fsStat(path.join(__dirname, './main.js'));17 }).then(function (stat) {18 expect(stat).to.not.be.undefined;19 done();20 }).catch(function (err) {21 expect(err).to.be.undefined;22 done();23 });24 });25 it('fs.stat no context', function (done) {26 var fsStat = po(fs.stat);27 co(function* () {28 return yield fsStat(path.join(__dirname, './main.js'));29 }).then(function (stat) {30 expect(stat).to.not.be.undefined;31 done();32 }).catch(function (err) {33 expect(err).to.be.undefined;34 done();35 });36 });37 it('fs.stat not exist fie', function (done) {38 var fsStat = po(fs.stat, fs);39 co(function* () {40 return yield fsStat(path.join(__dirname, './main.js'));41 }).then(function (stat) {42 expect(stat).to.be.undefined;43 done();44 }).catch(function (err) {45 expect(err).to.not.be.undefined;46 done();47 });48 });49 it('fs.stat2 not a function', function (done) {50 var fsStat2 = po(fs.stat2, fs);51 co(function* () {52 return yield fsStat2(path.join(__dirname, './main.js'));53 }).then(function (stat) {54 expect(stat).to.be.undefined;55 done();56 }).catch(function (err) {57 expect(err).to.not.be.undefined;58 done();59 });60 });...
Using AI Code Generation
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('
Using AI Code Generation
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('
Using AI Code Generation
1const fs = require('fs')2describe('My First Test', () => {3 it('Does not do much!', () => {4 expect(true).to.equal(true)5 })6 it('write file', () => {7 fs.stat('test.txt', (err, stats) => {8 if (err) {9 return console.error(err)10 }11 console.log(stats)12 console.log(`stats: ${JSON.stringify(stats)}`)13 })14 })15})16Platform: win32 (10.0.19042)17Browser: Electron 87 (headless)18 (Tests Finished)19 - 1 of 2 failed (100%) (0 seconds)20 (Tests Finished)21 - 1 of 2 failed (100%) (0 seconds)22 (Tests Finished)23 - 1 of 2 failed (100%) (0 seconds)24 (Tests Finished)25 - 1 of 2 failed (100%) (0 seconds)26 (Tests Finished)27 - 1 of 2 failed (100%) (0 seconds)
Using AI Code Generation
1describe('Cypress fs.stat', () => {2 it('should be able to read file', () => {3 cy.readFile('test.txt', { encoding: 'utf-8' }).then((value) => {4 cy.log(value);5 });6 });7});8{9 "env": {10 }11}12{13 "scripts": {14 }15}16describe('Cypress fs.stat', () => {17 it('should be able to read file', () => {18 cy.readFile(Cypress.env('file'), { encoding: 'utf-8' }).then((value) => {19 cy.log(value);20 });21 });22});23describe('Cypress fs.stat', () => {24 it('should be able to read file', () => {25 cy.readFile(Cypress.env('file'), { encoding: 'utf-8' }).then((value) => {26 cy.writeFile('test2.txt', value);27 });28 });29});30describe('Cypress fs.stat', () => {31 it('should be able to read file', () => {32 cy.readFile(Cypress.env('file'), { encoding: 'utf-8' }).then((value) => {33 cy.writeFile('test2.txt', value).then(() => {34 cy.readFile('test2.txt', { encoding: 'utf-8' }).then((value2) => {35 cy.log(value2);36 });37 });38 });39 });40});41describe('Cypress fs.stat', () => {42 it('should be able to read file', () => {43 cy.readFile(Cypress.env('file'), { encoding: 'utf-8' }).then((value)
Using AI Code Generation
1describe('File Upload', function(){2 it('File Upload', function(){3 cy.get('#main > iframe').then(function($iframe){4 const body = $iframe.contents().find('body')5 cy.wrap(body).find('#myFile').then(function($el){6 cy.log(fileName)7 cy.wrap($el).attachFile(fileName)8 cy.wait(5000)9 })10 })11 })12})13Cypress.Commands.add('attachFile', { prevSubject: 'element' }, (subject, fileName, fileType) => {14 cy.log('attachFile', fileName, fileType)15 cy.fixture(fileName, 'base64')16 .then(Cypress.Blob.base64StringToBlob)17 .then(blob => {18 const testFile = new File([blob], fileName, { type: fileType })19 const dataTransfer = new DataTransfer()20 dataTransfer.items.add(testFile)21 cy.wrap(subject).trigger('change', { force: true })22 })23})24import './commands'25{26 "testFiles": "**/*.{feature,features}"27}28{
Using AI Code Generation
1describe('File exists in cypress/fixtures folder', () => {2 it('file exists', () => {3 cy.task('readFileMaybe', 'test.json').then((file) => {4 expect(file).to.be.a('string')5 })6 })7})8const fs = require('fs')9module.exports = (on, config) => {10 on('task', {11 readFileMaybe (fileName) {12 try {13 const file = fs.readFileSync(`cypress/fixtures/${fileName}`)14 } catch (err) {15 }16 },17 })18}19describe('File exists in cypress/fixtures folder', () => {20 it('file exists', () => {21 cy.task('readFileMaybe', 'test.json').then((file) => {22 expect(file).to.be.a('string')23 })24 })25})26const fs = require('fs')27module.exports = (on, config) => {28 on('task', {29 readFileMaybe (fileName) {30 try {31 const file = fs.readFileSync(`cypress/fixtures/${fileName}`)32 } catch (err) {33 }34 },35 })36}37describe('File exists in cypress/fixtures folder', () => {38 it('file exists', () => {39 cy.task('readFileMaybe', 'test.json').then((file) => {40 expect(file).to.be.a('string')41 })42 })43})44const fs = require('fs')45module.exports = (on, config) => {
Cypress does not always executes click on element
How to get current date using cy.clock()
.type() method in cypress when string is empty
Cypress route function not detecting the network request
How to pass files name in array and then iterating for the file upload functionality in cypress
confused with cy.log in cypress
why is drag drop not working as per expectation in cypress.io?
Failing wait for request in Cypress
How to Populate Input Text Field with Javascript
Is there a reliable way to have Cypress exit as soon as a test fails?
2022 here and tested with cypress version: "6.x.x"
until "10.x.x"
You could use { force: true }
like:
cy.get("YOUR_SELECTOR").click({ force: true });
but this might not solve it ! The problem might be more complex, that's why check below
My solution:
cy.get("YOUR_SELECTOR").trigger("click");
Explanation:
In my case, I needed to watch a bit deeper what's going on. I started by pin the click
action like this:
Then watch the console, and you should see something like:
Now click on line Mouse Events
, it should display a table:
So basically, when Cypress executes the click
function, it triggers all those events but somehow my component behave the way that it is detached the moment where click event
is triggered.
So I just simplified the click by doing:
cy.get("YOUR_SELECTOR").trigger("click");
And it worked ????
Hope this will fix your issue or at least help you debug and understand what's wrong.
Check out the latest blogs from LambdaTest on this topic:
When it comes to web automation testing, the first automation testing framework that comes to mind undoubtedly has to be the Selenium framework. Selenium automation testing has picked up a significant pace since the creation of the framework way back in 2004.
We just raised $45 million in a venture round led by Premji Invest with participation from existing investors. Here’s what we intend to do with the money.
Find element by Text in Selenium is used to locate a web element using its text attribute. The text value is used mostly when the basic element identification properties such as ID or Class are dynamic in nature, making it hard to locate the web element.
We are nearing towards the end of 2019, where we are witnessing the introduction of more aligned JavaScript engines from major browser vendors. Which often strikes a major question in the back of our heads as web-developers or web-testers, and that is, whether cross browser testing is still relevant? If all the major browser would move towards a standardized process while configuring their JavaScript engines or browser engines then the chances of browser compatibility issues are bound to decrease right? But does that mean that we can simply ignore cross browser testing?
Web products of top-notch quality can only be realized when the emphasis is laid on every aspect of the product. This is where web automation testing plays a major role in testing the features of the product inside-out. A majority of the web testing community (including myself) have been using the Selenium test automation framework for realizing different forms of web testing (e.g., cross browser testing, functional testing, etc.).
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.
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.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!