How to use execAsync method in Cypress

Best JavaScript code snippet using cypress

checkPNI.js

Source:checkPNI.js Github

copy

Full Screen

...25 var cmd = 'ip6tables -w -I FORWARD 1 -i ' + iface + ' -j DROP';26 var checkCmd = 'ip6tables -w -v -L FORWARD 1';27 var check = 'DROP all ' + iface;28 console.log(checkCmd + ' to check ' + check);29 execAsync(checkCmd).then(function (result) {30 console.log("indexOf:" + result.indexOf(check));31 if (result.indexOf(check) > 0) {32 console.log("Forward rule exists.");33 }34 else {35 execAsync(cmd);36 console.log(cmd);37 }38 }, function (err) {console.error(err);});39}40//ip6tables -D FORWARD -i eth1 -j DROP41function connDev(iface) {42 var cmd = 'ip6tables -w -D FORWARD -i ' + iface + ' -j DROP';43 var checkCmd = 'ip6tables -w -v -L FORWARD 1';44 var check = 'DROP all ' + iface;45 console.log(checkCmd + ' to check ' + check);46 execAsync(checkCmd).then(function (result) {47 console.log("indexOf:" + result.indexOf(check));48 if (result.indexOf(check) > 0) {49 execAsync(cmd);50 console.log(cmd);51 }52 else {53 console.log("Forward rule not exist.");54 }55 }, function (err) {console.error(err);});56}57function natRedirectPkt(iface, ipAddr, port) {58 var cmd = 'ip6tables -w -t nat -A PREROUTING -i ' + iface +59 ' -p tcp --dport ' + port + ' -j DNAT --to-destination ['60 + ipAddr + ']:' + port;61 var checkCmd = 'ip6tables -w -t nat -v -L PREROUTING';62 var check = 'to:[' + ipAddr + ']:' + port;63 console.log(checkCmd + ' to check ' + check);64 execAsync(checkCmd).then(function (result) {65 console.log("indexOf:" + result.indexOf(check));66 if (result.indexOf(check) > 0) {67 console.log("nat rule exists.");68 }69 else {70 execAsync(cmd);71 console.log(cmd);72 }73 }, function (err) {console.error(err);});74}75function natRecoverPkt(iface, ipAddr, port) {76 var cmd = 'ip6tables -w -t nat -D PREROUTING -i ' + iface +77 ' -p tcp --dport ' + port + ' -j DNAT --to-destination ['78 + ipAddr + ']:' + port;79 var checkCmd = 'ip6tables -w -t nat -v -L PREROUTING';80 var check = 'to:[' + ipAddr + ']:' + port;81 console.log(checkCmd + ' to check ' + check);82 execAsync(checkCmd).then(function (result) {83 console.log("indexOf:" + result.indexOf(check));84 if (result.indexOf(check) > 0) {85 execAsync(cmd);86 console.log(cmd);87 }88 else {89 console.log("nat rule not exist.");90 }91 }, function (err) {console.error(err);});92}93function natMasquerade(iface) {94 var cmd = 'iptables -w -t nat -A POSTROUTING --out-interface '95 + iface + ' -j MASQUERADE';96 var checkCmd = 'iptables -w -t nat -v -L POSTROUTING';97 var check = 'MASQUERADE all -- any ' + iface;98 console.log(checkCmd + ' to check ' + check);99 execAsync(checkCmd).then(function (result) {100 console.log("indexOf:" + result.indexOf(check));101 if (result.indexOf(check) > 0) {102 console.log("nat rule exists.");103 }104 else {105 execAsync(cmd);106 console.log(cmd);107 }108 }, function (err) {console.error(err);});109}110function natRmMasquerade(iface) {111 var cmd = 'iptables -w -t nat -D POSTROUTING --out-interface '112 + iface + ' -j MASQUERADE';113 var checkCmd = 'iptables -w -t nat -v -L POSTROUTING';114 var check = 'MASQUERADE all -- any ' + iface;115 console.log(checkCmd + ' to check ' + check);116 execAsync(checkCmd).then(function (result) {117 console.log("indexOf:" + result.indexOf(check));118 if (result.indexOf(check) > 0) {119 execAsync(cmd);120 console.log(cmd);121 }122 else {123 console.log("nat rule not exist.");124 }125 }, function (err) {console.error(err);});126}127function natRmDfltGw(ipAddr) {128 var cmd = 'route del default gw ' + ipAddr;129 var checkCmd = 'ip route';130 var check = 'default via ' + ipAddr;131 console.log(checkCmd + ' to check ' + check);132 execAsync(checkCmd).then(function (result) {133 console.log("indexOf:" + result.indexOf(check));134 if (result.indexOf(check) >= 0) {135 execAsync(cmd);136 console.log(cmd);137 }138 else {139 console.log("default gw " + ipAddr + " not exists.");140 }141 }, function (err) {console.error(err);});142}143function natAddDfltGw(ipAddr, dev) {144 var cmd = 'route add default gw ' + ipAddr + ' dev ' + dev;145 var checkCmd = 'ip route';146 var check = 'default via ' + ipAddr;147 console.log(checkCmd + ' to check ' + check);148 execAsync(checkCmd).then(function (result) {149 console.log("indexOf:" + result.indexOf(check));150 if (result.indexOf(check) >= 0) {151 console.log("default gw " + ipAddr + " exists.");152 }153 else {154 execAsync(cmd);155 console.log(cmd);156 }157 }, function (err) {console.error(err);});158}159function setDnsRoute(ipAddr, gw, dev) {160 var cmd = 'route add ' + ipAddr + ' gw ' + gw + ' dev ' + dev;161 var checkCmd = 'ip route';162 var check = ipAddr + ' via ' + gw;163 console.log(checkCmd + ' to check ' + check);164 execAsync(checkCmd).then(function (result) {165 console.log("indexOf:" + result.indexOf(check));166 if (result.indexOf(check) >= 0) {167 console.log("route " + ipAddr + " exists.");168 }169 else {170 execAsync(cmd);171 console.log(cmd);172 }173 }, function (err) {console.error(err);});174}175function rmDnsRoute(ipAddr) {176 var cmd = 'route del ' + ipAddr;177 var checkCmd = 'ip route';178 var check = ipAddr + ' via';179 console.log(checkCmd + ' to check ' + check);180 execAsync(checkCmd).then(function (result) {181 console.log("indexOf:" + result.indexOf(check));182 if (result.indexOf(check) >= 0) {183 execAsync(cmd);184 console.log(cmd);185 }186 else {187 console.log("route " + ipAddr + " not exists.");188 }189 }, function (err) {console.error(err);});190}191function pppoeMasquerade() {192 natMasquerade('ppp0');193}194function pppoeRmMasquerade() {195 natRmMasquerade('ppp0');196}197function pppoeRedirectPkt(ipAddr) {198 natRedirectPkt('eth1', ipAddr, '80');199 natRedirectPkt('eth1', ipAddr, '443');200 disconnDev('eth1');201}202function pppoeRmRedirectPkt(ipAddr) {203 natRecoverPkt('eth1', ipAddr, '80');204 natRecoverPkt('eth1', ipAddr, '443');205 connDev('eth1');206}207function pppoeSetRoute() {208 natRmDfltGw(oriGw);209 setDnsRoute(dnsFwdr, oriGw, 'eth0');210}211function pppoeRmRoute() {212 natAddDfltGw(oriGw, 'eth0');213 rmDnsRoute(dnsFwdr);214}215module.exports = {216 check:function(adminState,endSession){217 var adminEnable = "enable";218 var adminDisable = "disable";219 return execAsync("cat adminState.txt ").then(function (result) {220 var i = false;221 ifaces['eth1'].forEach(function(details){222 if (details.family=='IPv6' && i == false) 223 {224 i = true;225 eh1ip = details.address;226 console.log('eh1ip:'+eh1ip);227 }228 });229 console.log("result:"+ result);230 if(adminState == adminEnable)231 {232 if(result.indexOf(adminDisable) > 0 && endSession == false)233 {234 pppoeRedirectPkt(eh1ip);235 pppoeMasquerade();236 pppoeSetRoute();237 var writeData = '"admin-state": "enable","end-session": "false"';238 console.log("writeData :"+writeData);239 fs.writeFile('adminState.txt',writeData, function(err){240 if(err) throw err;241 console.log("write success.");242 });243 return true;244 }245 else if (result.indexOf(adminEnable) > 0 && endSession == true)246 {247 return execAsync('ps -ef|grep pppd').then(function (result) {248 console.log("indexOf:"+result.indexOf("call provider"));249 if (result.indexOf("call provider") > 0)250 {251 execAsync("poff -a");252 pppoeRedirectPkt(eh1ip);253 pppoeSetRoute();254 console.log("poff ok.");255 var writeData = '"admin-state": "enable","end-session": "true"';256 console.log("writeData :"+writeData);257 fs.writeFile('adminState.txt',writeData, function(err){258 if(err) throw err;259 console.log("write success.");260 261 }); 262 return true;263 }264 }, function (err) {265 console.error(err);266 return false;267 });268 269 }270 else271 {272 console.log("NO enable case");273 return false;274 }275 }276 else if(adminState == adminDisable)277 {278 if (result.indexOf(adminEnable) > 0 && endSession == false)279 {280 return execAsync('ps -ef|grep pppd').then(function (result) {281 console.log("indexOf:"+result.indexOf("call provider"));282 if (result.indexOf("call provider") > 0)283 {284 execAsync("poff -a");285 console.log("poff ok.");286 }287 pppoeRmRedirectPkt(eh1ip);288 pppoeRmMasquerade();289 pppoeRmRoute();290 var writeData = '"admin-state": "disable","end-session": "false"';291 console.log("writeData :"+writeData);292 fs.writeFile('adminState.txt',writeData, function(err){293 if(err) throw err;294 console.log("write success.");295 });296 return true;297 }, function (err) {298 console.error(err);...

Full Screen

Full Screen

checkPNI_ipv4.js

Source:checkPNI_ipv4.js Github

copy

Full Screen

...25 var cmd = 'iptables -w -I FORWARD 1 -i ' + iface + ' -j DROP';26 var checkCmd = 'iptables -w -v -L FORWARD 1';27 var check = 'DROP all -- ' + iface;28 console.log(checkCmd + ' to check ' + check);29 execAsync(checkCmd).then(function (result) {30 console.log("indexOf:" + result.indexOf(check));31 if (result.indexOf(check) > 0) {32 console.log("Forward rule exists.");33 }34 else {35 execAsync(cmd);36 console.log(cmd);37 }38 }, function (err) {console.error(err);});39}40//iptables -D FORWARD -i eth1 -j DROP41function connDev(iface) {42 var cmd = 'iptables -w -D FORWARD -i ' + iface + ' -j DROP';43 var checkCmd = 'iptables -w -v -L FORWARD 1';44 var check = 'DROP all -- ' + iface;45 console.log(checkCmd + ' to check ' + check);46 execAsync(checkCmd).then(function (result) {47 console.log("indexOf:" + result.indexOf(check));48 if (result.indexOf(check) > 0) {49 execAsync(cmd);50 console.log(cmd);51 }52 else {53 console.log("Forward rule not exist.");54 }55 }, function (err) {console.error(err);});56}57function natRedirectPkt(iface, ipAddr, port) {58 var cmd = 'iptables -w -t nat -A PREROUTING -i ' + iface +59 ' -p tcp --dport ' + port + ' -j DNAT --to-destination '60 + ipAddr + ':' + port;61 var checkCmd = 'iptables -w -t nat -v -L PREROUTING';62 var check = 'to:' + ipAddr + ':' + port;63 console.log(checkCmd + ' to check ' + check);64 execAsync(checkCmd).then(function (result) {65 console.log("indexOf:" + result.indexOf(check));66 if (result.indexOf(check) > 0) {67 console.log("nat rule exists.");68 }69 else {70 execAsync(cmd);71 console.log(cmd);72 }73 }, function (err) {console.error(err);});74}75function natRecoverPkt(iface, ipAddr, port) {76 var cmd = 'iptables -w -t nat -D PREROUTING -i ' + iface +77 ' -p tcp --dport ' + port + ' -j DNAT --to-destination '78 + ipAddr + ':' + port;79 var checkCmd = 'iptables -w -t nat -v -L PREROUTING';80 var check = 'to:' + ipAddr + ':' + port;81 console.log(checkCmd + ' to check ' + check);82 execAsync(checkCmd).then(function (result) {83 console.log("indexOf:" + result.indexOf(check));84 if (result.indexOf(check) > 0) {85 execAsync(cmd);86 console.log(cmd);87 }88 else {89 console.log("nat rule not exist.");90 }91 }, function (err) {console.error(err);});92}93function natMasquerade(iface) {94 var cmd = 'iptables -w -t nat -A POSTROUTING --out-interface '95 + iface + ' -j MASQUERADE';96 var checkCmd = 'iptables -w -t nat -v -L POSTROUTING';97 var check = 'MASQUERADE all -- any ' + iface;98 console.log(checkCmd + ' to check ' + check);99 execAsync(checkCmd).then(function (result) {100 console.log("indexOf:" + result.indexOf(check));101 if (result.indexOf(check) > 0) {102 console.log("nat rule exists.");103 }104 else {105 execAsync(cmd);106 console.log(cmd);107 }108 }, function (err) {console.error(err);});109}110function natRmMasquerade(iface) {111 var cmd = 'iptables -w -t nat -D POSTROUTING --out-interface '112 + iface + ' -j MASQUERADE';113 var checkCmd = 'iptables -w -t nat -v -L POSTROUTING';114 var check = 'MASQUERADE all -- any ' + iface;115 console.log(checkCmd + ' to check ' + check);116 execAsync(checkCmd).then(function (result) {117 console.log("indexOf:" + result.indexOf(check));118 if (result.indexOf(check) > 0) {119 execAsync(cmd);120 console.log(cmd);121 }122 else {123 console.log("nat rule not exist.");124 }125 }, function (err) {console.error(err);});126}127function natRmDfltGw(ipAddr) {128 var cmd = 'route del default gw ' + ipAddr;129 var checkCmd = 'ip route';130 var check = 'default via ' + ipAddr;131 console.log(checkCmd + ' to check ' + check);132 execAsync(checkCmd).then(function (result) {133 console.log("indexOf:" + result.indexOf(check));134 if (result.indexOf(check) >= 0) {135 execAsync(cmd);136 console.log(cmd);137 }138 else {139 console.log("default gw " + ipAddr + " not exists.");140 }141 }, function (err) {console.error(err);});142}143function natAddDfltGw(ipAddr, dev) {144 var cmd = 'route add default gw ' + ipAddr + ' dev ' + dev;145 var checkCmd = 'ip route';146 var check = 'default via ' + ipAddr;147 console.log(checkCmd + ' to check ' + check);148 execAsync(checkCmd).then(function (result) {149 console.log("indexOf:" + result.indexOf(check));150 if (result.indexOf(check) >= 0) {151 console.log("default gw " + ipAddr + " exists.");152 }153 else {154 execAsync(cmd);155 console.log(cmd);156 }157 }, function (err) {console.error(err);});158}159function setDnsRoute(ipAddr, gw, dev) {160 var cmd = 'route add ' + ipAddr + ' gw ' + gw + ' dev ' + dev;161 var checkCmd = 'ip route';162 var check = ipAddr + ' via ' + gw;163 console.log(checkCmd + ' to check ' + check);164 execAsync(checkCmd).then(function (result) {165 console.log("indexOf:" + result.indexOf(check));166 if (result.indexOf(check) >= 0) {167 console.log("route " + ipAddr + " exists.");168 }169 else {170 execAsync(cmd);171 console.log(cmd);172 }173 }, function (err) {console.error(err);});174}175function rmDnsRoute(ipAddr) {176 var cmd = 'route del ' + ipAddr;177 var checkCmd = 'ip route';178 var check = ipAddr + ' via';179 console.log(checkCmd + ' to check ' + check);180 execAsync(checkCmd).then(function (result) {181 console.log("indexOf:" + result.indexOf(check));182 if (result.indexOf(check) >= 0) {183 execAsync(cmd);184 console.log(cmd);185 }186 else {187 console.log("route " + ipAddr + " not exists.");188 }189 }, function (err) {console.error(err);});190}191function pppoeMasquerade() {192 natMasquerade('ppp0');193}194function pppoeRmMasquerade() {195 natRmMasquerade('ppp0');196}197function pppoeRedirectPkt(ipAddr) {198 natRedirectPkt('eth1', ipAddr, '80');199 natRedirectPkt('eth1', ipAddr, '443');200 disconnDev('eth1');201}202function pppoeRmRedirectPkt(ipAddr) {203 natRecoverPkt('eth1', ipAddr, '80');204 natRecoverPkt('eth1', ipAddr, '443');205 connDev('eth1');206}207function pppoeSetRoute() {208 natRmDfltGw(oriGw);209 setDnsRoute(dnsFwdr, oriGw, 'eth0');210}211function pppoeRmRoute() {212 natAddDfltGw(oriGw, 'eth0');213 rmDnsRoute(dnsFwdr);214}215module.exports = {216 check:function(adminState,endSession){217 var adminEnable = "enable";218 var adminDisable = "disable";219 return execAsync("cat adminState.txt ").then(function (result) {220 var i = false;221 ifaces['eth1'].forEach(function(details){222 if (details.family=='IPv4' && i == false) 223 {224 i = true;225 eh1ip = details.address;226 console.log('eh1ip:'+eh1ip);227 }228 });229 console.log("result:"+ result);230 if(adminState == adminEnable)231 {232 if(result.indexOf(adminDisable) > 0 && endSession == false)233 {234 pppoeRedirectPkt(eh1ip);235 pppoeMasquerade();236 pppoeSetRoute();237 var writeData = '"admin-state": "enable","end-session": "false"';238 console.log("writeData :"+writeData);239 fs.writeFile('adminState.txt',writeData, function(err){240 if(err) throw err;241 console.log("write success.");242 });243 return true;244 }245 else if (result.indexOf(adminEnable) > 0 && endSession == true)246 {247 return execAsync('ps -ef|grep pppd').then(function (result) {248 console.log("indexOf:"+result.indexOf("call provider"));249 if (result.indexOf("call provider") > 0)250 {251 execAsync("poff -a");252 pppoeRedirectPkt(eh1ip);253 pppoeSetRoute();254 console.log("poff ok.");255 var writeData = '"admin-state": "enable","end-session": "true"';256 console.log("writeData :"+writeData);257 fs.writeFile('adminState.txt',writeData, function(err){258 if(err) throw err;259 console.log("write success.");260 261 }); 262 return true;263 }264 }, function (err) {265 console.error(err);266 return false;267 });268 269 }270 else271 {272 console.log("NO enable case");273 return false;274 }275 }276 else if(adminState == adminDisable)277 {278 if (result.indexOf(adminEnable) > 0 && endSession == false)279 {280 return execAsync('ps -ef|grep pppd').then(function (result) {281 console.log("indexOf:"+result.indexOf("call provider"));282 if (result.indexOf("call provider") > 0)283 {284 execAsync("poff -a");285 console.log("poff ok.");286 }287 pppoeRmRedirectPkt(eh1ip);288 pppoeRmMasquerade();289 pppoeRmRoute();290 var writeData = '"admin-state": "disable","end-session": "false"';291 console.log("writeData :"+writeData);292 fs.writeFile('adminState.txt',writeData, function(err){293 if(err) throw err;294 console.log("write success.");295 });296 return true;297 }, function (err) {298 console.error(err);...

Full Screen

Full Screen

mongo.provider.helper.js

Source:mongo.provider.helper.js Github

copy

Full Screen

...51 .select(documentFields)52 .skip(pagerOpts.perPage * (pagerOpts.page-1))53 .limit(pagerOpts.perPage)54 .sort( sortOpts )55 .execAsync(), Model.count(queryOpts).execAsync(),56 function (dataList, count) {57 return {58 dataList:dataList,59 totalItems:count,60 currentPage:pagerOpts.page61 };62 });63 };6465 providerHelper.getAllWithoutDocumentFieldsPagination = function (Model, queryOpts, pagerOpts) {6667 return join(Model68 .find(queryOpts)69 .skip(pagerOpts.perPage * (pagerOpts.page-1))70 .limit(pagerOpts.perPage)71 .sort({ addedOn: 'desc' })72 .execAsync(), Model.count(queryOpts).execAsync(),73 function (dataList, count) {74 return {75 dataList:dataList,76 totalItems:count,77 currentPage:pagerOpts.page78 };79 });80 };8182 providerHelper.getAllWithDocumentFieldsNoPagination = function (Model, queryOpts, documentFields, sortField) {83 return Model84 .find(queryOpts)85 .select(documentFields)86 .sort(sortField)87 .execAsync();88 };8990 providerHelper.getLatestData = function (Model, queryOpts, documentFields, sortOpts, limitOpts) {91 return Model92 .find(queryOpts)93 .select(documentFields)94 .sort(sortOpts)95 .limit(limitOpts)96 .execAsync();97 };9899100 providerHelper.getAllWithoutDocumentFieldsNoPagination = function (Model, queryOpts) {101 return Model102 .find(queryOpts)103 .sort({ addedOn: -1 })104 .execAsync();105 };106107 providerHelper.getAllWithFieldsPaginationPopulation = function (Model, queryOpts, pagerOpts, documentFields, populationPath, populationFields, populationQueryOpts) {108109 return join(Model.find(queryOpts)110 .select(documentFields)111 .populate({112 path: populationPath,113 match: populationQueryOpts,114 select: populationFields115 })116 .skip(pagerOpts.perPage * (pagerOpts.page-1))117 .limit(pagerOpts.perPage)118 .sort({ addedOn: -1 })119 .execAsync(), Model.count(queryOpts).execAsync(),120 function (dataList, count) {121 return {122 dataList:dataList,123 totalItems:count,124 currentPage:pagerOpts.page125 };126 });127 };128129 providerHelper.getAllWithFieldsPaginationPopulationMy = function (Model, queryOpts, pagerOpts, documentFields) {130131 return join(Model.find(queryOpts)132 .select(documentFields)133 .skip(pagerOpts.perPage * (pagerOpts.page-1))134 .limit(pagerOpts.perPage)135 .sort({ addedOn: -1 })136 .execAsync(), Model.count(queryOpts).execAsync(),137 function (dataList, count) {138 return {139 dataList:dataList,140 totalItems:count,141 currentPage:pagerOpts.page142 };143 });144 };145146 providerHelper.getAllWithFieldsPaginationMultiPopulation = function (Model, queryOpts, pagerOpts, documentFields, firstPopulation, secondPopulation, firstPopulationFields, populationQueryOpts, secondPopulationFields) {147148 return join(Model.find(queryOpts)149 .populate({150 path: firstPopulation,151 match: populationQueryOpts,152 select: firstPopulationFields153 })154 .populate({155 path: secondPopulation,156 select: secondPopulationFields157 })158 .select(documentFields)159 .skip(pagerOpts.perPage * (pagerOpts.page-1))160 .limit(pagerOpts.perPage)161 .sort({ addedOn: -1 })162 .execAsync(), Model.count(queryOpts).execAsync(),163 function (dataList, count) {164 return {165 dataList:dataList,166 totalItems:count,167 currentPage:pagerOpts.page168 };169 });170 };171172 providerHelper.getAllWithoutFieldsPaginationMultiPopulation = function (Model, queryOpts, documentFields, firstPopulation, secondPopulation, firstPopulationFields, populationQueryOpts, secondPopulationFields) {173174 return Model.find(queryOpts)175 .populate({176 path: firstPopulation,177 match: populationQueryOpts,178 select: firstPopulationFields179 })180 .populate({181 path: secondPopulation,182 select: secondPopulationFields183 })184 .select(documentFields)185 .sort({ addedOn: -1 })186 .execAsync();187 };188189 providerHelper.getAllWithFieldsPopulation = function (Model, queryOpts, documentFields, populationPath, populationFields, populationQueryOpts, sortOpts) {190 return Model.find(queryOpts)191 .select(documentFields)192 .populate({193 path: populationPath,194 match: populationQueryOpts,195 select: populationFields,196 options: { sort: sortOpts }197198 })199 .execAsync();200 };201202 providerHelper.getByIdWithPopulation = function (Model, queryOpts, populationPath, populationQueryOpts, sortOpts, populationFields, documentFields) {203 return Model.findById(queryOpts)204 .select(documentFields)205 .populate({206 path: populationPath,207 match: populationQueryOpts,208 select: populationFields,209 options: { sort: sortOpts }210 })211 .execAsync();212 };213214 providerHelper.getByIdWithMultiplePopulation = function (Model, queryOpts, firstPopulation, secondPopulation, documentFields, firstPopulationField, secondPopulationField) {215 return Model.findById(queryOpts)216 .select(documentFields)217 .populate({218 path: firstPopulation,219 select: firstPopulationField220 })221 .populate({222 path: secondPopulation,223 select: secondPopulationField224 })225 .execAsync();226 };227228 providerHelper.checkForDuplicateEntry=function (Model, queryOpts) {229 return Model.count(queryOpts)230 .execAsync();231 };232233 providerHelper.getDistinctValuesInArray = function (Model, queryfield, queryOpts) {234 return Model.distinct(queryfield, queryOpts)235 .execAsync();236 };237238 providerHelper.removeModelData = function (Model, queryOpts) {239 return Model.remove(queryOpts)240 .execAsync();241 };242243 providerHelper.saveModelToEmbeddedDocument = function (Model, embeddedDocChildSchema, parentId) {244 return Model.findByIdAndUpdate(245 parentId,246 {247 $push: embeddedDocChildSchema248 },249 {250 safe: true,251 upsert: true,252 new : true253 })254 .execAsync();255 };256257 providerHelper.getAllEmbeddedDocumentsWithDocumentFieldsPagination = function (Model, queryOpts, pagerOpts, documentFields, sortParam, groupOpts, countProjectFields, unWindField) {258259 return join( Model.aggregate(260 {261 $unwind:unWindField262 },263 {264 $match:queryOpts265 },{266 $project:documentFields267 },268 {269 $sort:sortParam270 },{271 $skip:pagerOpts.perPage * (pagerOpts.page-1)272 },{273 $limit:pagerOpts.perPage274 },{275 $group:groupOpts276 }277 ).execAsync(), Model.aggregate(278 {279 $match:queryOpts280 },281 {282 $project:countProjectFields283 }284 ).execAsync(),285 function (dataList, lstCount) {286 var _totalItems = 0;287 if(lstCount.length > 0){288 _totalItems = lstCount[0].count;289 }290 return {291 dataList:dataList,292 totalItems:_totalItems,293 currentPage:pagerOpts.page294 };295 });296 };297298299 providerHelper.getEmbeddedDocumentsWithoutPagination = function (Model, queryOpts, documentFields, unWindField, sortParam, groupOpts) {300301 return Model.aggregate(302 {303 $unwind:unWindField304 },305 {306 $match:queryOpts307 },308 {309 $sort:sortParam310 },{311 $project:documentFields312 },{313 $group:groupOpts314 }315 ).execAsync();316317 };318319320 providerHelper.removeEmbeddedDocument = function (Model, embeddedDocChildSchema, parentId) {321 return Model.findByIdAndUpdate(322 parentId,323 {324 $pull: embeddedDocChildSchema325 },326 {327 safe: true,328 upsert: true,329 new : true330 })331 .execAsync();332 };333334335336 providerHelper.updateModelData = function (Model, queryOpts, updateOpts, multiOpts) {337 return Model.update(queryOpts, updateOpts, {multi: multiOpts})338 .execAsync();339 };340341 providerHelper.findByIdAndUpdate = function (Model, _parentId, pushSchema) {342 return Model.findByIdAndUpdate(343 _parentId,344 {345 $push: pushSchema346 },347 {348 safe: true,349 upsert: true,350 new : true351 })352 .execAsync();353 };354 ...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

...23 return os.tmpdir() + '/' + this.stagingBranch();24 };25};26utils.getRepoRoot = function getRepoRoot() {27 return execAsync('git rev-parse --show-toplevel')28 .then(function (stdout) {29 return stdout.trim();30 });31};32utils.isCurrentBranch = function isCurrentBranch(which) {33 return execAsync('git rev-parse --abbrev-ref HEAD')34 .then(function (stdout) {35 return stdout.trim() === which ? true : false;36 });37};38utils.hasUncommittedChanges = function hasUncommittedChanges() {39 return execAsync('git status --porcelain --untracked-files=no')40 .then(function (stdout) {41 return stdout.trim().length !== 0 ? true : false;42 });43};44utils.isWorkingDirClean = function isWorkingDirClean(rootDir) {45 return execAsync('git -C ' + rootDir + ' clean -xdn')46 .then(function (stdout) {47 return stdout.trim().length === 0 ? true : false;48 });49};50utils.tracksRemote = function tracksRemote(which) {51 return execAsync('git remote')52 .then(function (stdout) {53 var re = new RegExp('^' + which + '$', 'm');54 return re.test(stdout) ? true : false;55 });56};57utils.fetchRemote = function fetchRemote(which) {58 return execAsync('git fetch --prune ' + which)59 .then(function (stdout) {60 console.log(stdout);61 });62};63utils.tryPackageFolder = function tryPackageFolder(folder) {64 return access(folder + '/package.json', fs.R_OK);65};66utils.folderIsInRepo = function folderIsInRepo(folder, repoRoot) {67 return execAsync('git -C ' + folder + ' rev-parse --show-toplevel')68 .then(function (stdout) {69 return stdout.trim() === repoRoot ? true : false;70 });71};72utils.getPackageInfo = function getPackageInfo(packageFolder) {73 return readFile(packageFolder + '/package.json', 'utf-8')74 .then(function (data) {75 var pkg = JSON.parse(data);76 return {77 name: pkg.name,78 version: pkg.version79 };80 });81};82utils.localBranchExists = function localBranchExists(name) {83 return execAsync('git for-each-ref --format=%(refname:short) refs/heads/')84 .then(function (stdout) {85 var re = new RegExp('^' + name + '$', 'm');86 return re.test(stdout) ? true : false;87 });88};89utils.remoteBranchExists = function remoteBranchExists(remoteName, branchName) {90 return execAsync('git for-each-ref --format=%(refname:short) refs/remotes/')91 .then(function (stdout) {92 var re = new RegExp('^' + remoteName + '/' + branchName + '$', 'm');93 return re.test(stdout) ? true : false;94 });95};96utils.getTrackedFiles = function getTrackedFiles(folder) {97 return execAsync('git -C ' + folder + ' ls-tree -r HEAD --name-only')98 .then(function (stdout) {99 return stdout.trim().split('\n');100 });101};102utils.createCleanDir = function createCleanDir(path) {103 return remove(path)104 .then(function () {105 return mkdir(path);106 });107};108utils.copyFiles = function copyFiles(fileList, src, dst) {109 return Promise.map(fileList, function (file) {110 return copy(src + '/' + file, dst + '/' + file);111 });112};113utils.copyDir = function copyDir(srcDir, dstDir) {114 return copy(srcDir, dstDir);115};116utils.checkoutBranch = function checkoutBranch(name) {117 return execAsync('git checkout ' + name);118};119utils.checkoutOrphanBranch = function checkoutOrphanBranch(name) {120 return execAsync('git checkout --orphan ' + name)121 .then(function () {122 return execAsync('git rm -rf .')123 .catch(function (err) {124 // it's okay if there aren't any files to 'git rm'...125 if (!err.toString().search(/pathspec '\.' did not match any files/)) {126 throw err;127 }128 });129 });130};131utils.commitFiles = function commitFiles(message) {132 return execAsync('git add .')133 .then(function () {134 return execAsync('git commit -m "' + message + '"');135 });136};137utils.pushToRemote = function pushToRemote(remoteName, branchName) {138 return execAsync('git push ' + remoteName + ' ' + branchName);139};140utils.getTarballUrl = function getTarballUrl(remoteName, branchName) {141 return execAsync('git config --get remote.' + remoteName + '.url')142 .then(function (stdout) {143 return stdout.trim().replace(/\.git$/, '') + '/tarball/' + branchName;144 });145};146utils.deleteBranch = function deleteBranch(which) {147 return execAsync('git branch -D ' + which);...

Full Screen

Full Screen

client.js

Source:client.js Github

copy

Full Screen

1/*2 * Copyright 2012 Research In Motion Limited.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16var root = __dirname + "/../../../../",17 apiDir = root + "ext/bbm.platform/",18 _ID = require(apiDir + "/manifest").namespace,19 client = null,20 mockedWebworks = {21 execSync: jasmine.createSpy(),22 execAsync: jasmine.createSpy(),23 event: { once : jasmine.createSpy(),24 isOn : jasmine.createSpy() }25 };26describe("bbm.platform", function () {27 beforeEach(function () {28 GLOBAL.window = {29 webworks: mockedWebworks30 };31 client = require(apiDir + "/client");32 });33 afterEach(function () {34 delete GLOBAL.window;35 client = null;36 delete require.cache[require.resolve(apiDir + "/client")];37 });38 describe("bbm.platform.register", function () {39 it("registers an application", function () {40 var options = { uuid : "blah" };41 client.register(options);42 expect(mockedWebworks.execAsync).toHaveBeenCalledWith(_ID, "register", { "options" : options });43 });44 });45 describe("bbm.platform.self", function () {46 it("getDisplayPicture calls execAsync", function () {47 client.self.getDisplayPicture(function (img) { });48 expect(mockedWebworks.execAsync).toHaveBeenCalledWith(_ID, "self/getDisplayPicture", { "eventId" : "bbm.self.displayPicture" });49 });50 it("setStatus calls execAsync", function () {51 client.self.setStatus("available", "Hello");52 expect(mockedWebworks.execAsync).toHaveBeenCalledWith(_ID, "self/setStatus", { "status" : "available", "statusMessage" : "Hello" });53 });54 it("setPersonalMessage calls execAsync", function () {55 client.self.setPersonalMessage("Hello World");56 expect(mockedWebworks.execAsync).toHaveBeenCalledWith(_ID, "self/setPersonalMessage", { "personalMessage" : "Hello World" });57 });58 it("setDisplayPicture calls execAsync", function () {59 client.self.setDisplayPicture("/tmp/avatar.gif");60 expect(mockedWebworks.execAsync).toHaveBeenCalledWith(_ID, "self/setDisplayPicture", { "displayPicture" : "/tmp/avatar.gif" });61 });62 });63 describe("bbm.platform.users", function () {64 it("inviteToDownload calls execAsync", function () {65 client.users.inviteToDownload();66 expect(mockedWebworks.execAsync).toHaveBeenCalledWith(_ID, "users/inviteToDownload");67 });68 });...

Full Screen

Full Screen

posting.service.js

Source:posting.service.js Github

copy

Full Screen

...5// ! 유저 + 제목, 제목 + 내용, 등등 추후 고려6exports.getPostingsList = async(body) => {7 try {8 let queryStatement = makeQueryStatement(body);9 const response = await execAsync(queryStatement);10 if(response instanceof Error) return {error: response};11 return {data: response}12 } catch (error) {13 console.log(`srv_err : ${error.message} [getPostingList]`)14 return new Error(error.message)15 }16}17exports.deletePosting = async body => {18 try {19 const queryStatement = `DELETE FROM ${schema}.POSTING WHERE POSTINGID = ${body.postingId}`20 const response = await execAsync(queryStatement);21 if(response instanceof Error) return response;22 return {success:true, message: "글삭제 성공"}23 } catch (error) {24 console.log(`srv_err : ${error.message} [deletePosting]`)25 return new Error(error.message)26 }27}28exports.modifyPosting = async (body) => {29 try {30 const queryStatement = `UPDATE ${schema}.POSTING SET TITLE = '${body.title}' , CONTENT = '${body.content}' WHERE POSTINGID = ${body.postingId}`31 const response = await execAsync(queryStatement);32 if(response instanceof Error) return response;33 return {success:true, message: "글수정 성공"}34 } catch (error) {35 console.log(`srv_err : ${error.message} [modifyPosting]`)36 return new Error(error.message)37 }38}39exports.writeNewPosting = async (body) => {40 try {41 const queryStatement = `INSERT INTO ${schema}.POSTING (USERID, TITLE, CONTENT) VALUES ('${body.userId}', '${body.title}', '${body.content}')`;42 const response = await execAsync(queryStatement);43 if(response instanceof Error) return response;44 return {success:true, message: "글쓰기 성공"}45 } catch (error) {46 console.log(`srv_err : ${error.message} [writeNewPosting]`)47 return new Error(error.message)48 }49}50const makeQueryStatement = ({userId, title}) => {51 let stringBuilder = new StringBuilder();52 let condition;53 if(userId) condition = `WHERE USERID = '${userId}'`54 if(title) condition = `WHERE TITLE LIKE '%${title}%'`55 stringBuilder.append(`SELECT * FROM ${schema}.POSTING`);56 stringBuilder.spacer();...

Full Screen

Full Screen

cli.test.js

Source:cli.test.js Github

copy

Full Screen

...4const execAsync = Promise.promisify(exec);5const iexecPath = DRONE ? 'iexec' : 'node ../src/iexec.js';6test('iexec init', () => {7 process.chdir('test');8 return expect(execAsync(`${iexecPath} init --force`)).resolves.not.toBe(1);9});10test('iexec wallet create', () => expect(execAsync(`${iexecPath} wallet create --force`)).resolves.not.toBe(1));11test(12 'iexec wallet encrypt',13 () => expect(14 execAsync(`${iexecPath} wallet encrypt --password toto --force`),15 ).resolves.not.toBe(1),16 10000,17);18test(19 'iexec wallet decrypt',20 () => expect(21 execAsync(`${iexecPath} wallet decrypt --password toto --force`),22 ).resolves.not.toBe(1),23 10000,24);25test(26 'iexec wallet show',27 () => expect(execAsync(`${iexecPath} wallet show`)).resolves.not.toBe(1),28 10000,29);30test('iexec account login', () => expect(execAsync(`${iexecPath} account login --force`)).resolves.not.toBe(1));31test(32 'iexec account show',33 () => expect(execAsync(`${iexecPath} account show`)).resolves.not.toBe(1),34 10000,35);36test('iexec app init', () => expect(execAsync(`${iexecPath} app init`)).resolves.not.toBe(1));37test('iexec order init --buy', () => expect(execAsync(`${iexecPath} order init --buy`)).resolves.not.toBe(1));38test('iexec registry validate app', () => expect(execAsync(`${iexecPath} registry validate app`)).resolves.not.toBe(1));39test('iexec app count', () => expect(execAsync(`${iexecPath} app count`)).resolves.not.toBe(1));40test('iexec dataset init', () => expect(execAsync(`${iexecPath} dataset init`)).resolves.not.toBe(1));41test('iexec workerpool init', () => expect(execAsync(`${iexecPath} workerpool init`)).resolves.not.toBe(1));42test('iexec category init', () => expect(execAsync(`${iexecPath} category init`)).resolves.not.toBe(1));43test('iexec order init --sell', () => expect(execAsync(`${iexecPath} order init --sell`)).resolves.not.toBe(1));44test('iexec order init --buy', () => expect(execAsync(`${iexecPath} order init --buy`)).resolves.not.toBe(1));45test('iexec order count', () => expect(execAsync(`${iexecPath} order count`)).resolves.not.toBe(1));46test('iexec workerpool count', () => expect(execAsync(`${iexecPath} app count`)).resolves.not.toBe(1));47test('iexec orderbook show', () => expect(execAsync(`${iexecPath} orderbook show`)).resolves.not.toBe(1));...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...21 if (fs.existsSync(targetDir)) {22 throw new Error('目录已存在');23 }24 console.log(__dirname, 'rendering...');25 // await execAsync("rm -rf .init-tmp");26 // await execAsync("mkdir .init-tmp");27 // renderDir()28 await renderDir(29 // `${process.cwd()}/.init-tmp`,30 __dirname,31 'template',32 `${process.cwd()}/${projectName}`,33 {34 prompts: [35 {36 type: 'string',37 name: 'name',38 default: projectName,39 required: true,40 message: '名称',41 validate(v) {42 if (/^[a-z][A-z0-9-]*$/.test(v)) {43 return true;44 }45 return '输入不合法';46 },47 },48 {49 type: 'string',50 name: 'description',51 default: 'description',52 message: '描述',53 },54 ],55 },56 );57 // todo 这个文件不太灵58 // await fs.copySync(__dirname + '.gitignore', `${targetDir}/.gitignore`);59 await execAsync(`cp ${__dirname}/template/.gitignore ${targetDir}/.gitignore`);60 // todo 这个link不太灵61 await execAsync(`ln -s ../CHANGELOG.md changelog.md`, { cwd: `${targetDir}/website` });62 await execAsync('rm -rf .git', { cwd: targetDir });63 try {64 await execAsync('git init -b main', { cwd: targetDir });65 } catch (error) {66 await execAsync('git init && git checkout -b main', { cwd: targetDir });67 }68 await execAsync("git add . && git commit -nam 'init'", { cwd: targetDir });69 await execAsync('rm -rf .init-tmp');70 console.log('✨ done');71}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const execAsync = require('util').promisify(require('child_process').exec)2describe('My First Test', () => {3 it('Visits the Kitchen Sink', () => {4 cy.contains('type').click()5 cy.url().should('include', '/commands/actions')6 cy.get('.action-email')7 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add("execAsync", (command) => {2 return cy.task("execAsync", command);3});4const { exec } = require("child_process");5module.exports = (on, config) => {6 on("task", {7 execAsync(command) {8 return new Promise((resolve, reject) => {9 exec(command, (error, stdout, stderr) => {10 if (error) {11 reject(error);12 } else {13 resolve(stdout);14 }15 });16 });17 },18 });19};20describe("test", () => {21 it("test", () => {22 cy.execAsync("code --version").then((version) => {23 expect(version).to.be.a("string");24 });25 });26});27Contributions are welcome. Please make sure to read the [Contributing Guide](

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add('execAsync', (command) => {2 return cy.task('execAsync', command);3});4const execa = require('execa');5module.exports = (on, config) => {6 on('task', {7 execAsync(command) {8 return execa.shell(command)9 .then(({ stdout, stderr }) => {10 console.log('stdout:', stdout);11 console.log('stderr:', stderr);12 return stdout;13 })14 }15 })16};17it('should run command', () => {18 cy.execAsync('ls -l')19});20* **Sandeep Kumar** - *Initial work* - [SandeepKumar](

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add('execAsync', (cmd) => {2 return cy.task('execAsync', cmd);3});4Cypress.Commands.add('execAsync', (cmd) => {5 return cy.task('execAsync', cmd);6});7Cypress.Commands.add('execAsync', (cmd) => {8 return cy.task('execAsync', cmd);9});10Cypress.Commands.add('execAsync', (cmd) => {11 return cy.task('execAsync', cmd);12});13Cypress.Commands.add('execAsync', (cmd) => {14 return cy.task('execAsync', cmd);15});16Cypress.Commands.add('execAsync', (cmd) => {17 return cy.task('execAsync', cmd);18});19Cypress.Commands.add('execAsync', (cmd) => {20 return cy.task('execAsync', cmd);21});22Cypress.Commands.add('execAsync', (cmd) => {23 return cy.task('execAsync', cmd);24});25Cypress.Commands.add('execAsync', (cmd) => {26 return cy.task('execAsync', cmd);27});28Cypress.Commands.add('execAsync', (cmd) => {29 return cy.task('execAsync', cmd);30});31Cypress.Commands.add('execAsync', (cmd) => {32 return cy.task('execAsync', cmd);33});34Cypress.Commands.add('execAsync', (cmd) => {35 return cy.task('execAsync', cmd);36});37Cypress.Commands.add('execAsync', (cmd) => {38 return cy.task('execAsync', cmd);39});40Cypress.Commands.add('execAsync', (cmd) => {41 return cy.task('execAsync', cmd);42});43Cypress.Commands.add('execAsync', (cmd) => {44 return cy.task('execAsync', cmd);

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', () => {2 it('Does not do much!', () => {3 cy.execAsync('node cypress/support/exec.js').then((result) => {4 console.log(result.stdout);5 expect(result.stdout).to.contain('Hello World');6 })7 })8})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.execAsync('node cypress/support/test.js')4 })5})6const { exec } = require('child_process');7exec('npm run test', (err, stdout, stderr) => {8 if (err) {9 console.error(err)10 } else {11 console.log(`stdout: ${stdout}`);12 console.log(`stderr: ${stderr}`);13 }14});15[MIT](

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("test", () => {2 it("test", () => {3 cy.execAsync("node test1.js").then((result) => {4 console.log(result);5 });6 });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { execAsync } = require('@shelex/cypress-exec');2it('test', () => {3 execAsync('ls -la');4});5const { execAsync } = require('@shelex/cypress-exec');6it('test', () => {7 execAsync('ls -la', {timeout: 5000, failOnNonZeroExit: false});8});9const { execAsync } = require('@shelex/cypress-exec');10it('test', () => {11 execAsync('ls -la', {timeout: 5000, failOnNonZeroExit: false}, (result) => {12 });13});14const { execAsync } = require('@shelex/cypress-exec');15it('test', () => {16 execAsync('ls -la', {timeout: 5000, failOnNonZeroExit: false}, (result) => {17 }, (error) => {18 });19});20const { execAsync } = require('@shelex/cypress-exec');21it('test', () => {22 execAsync('ls -la', {timeout: 5000, failOnNonZeroExit: false}, (result) => {23 }, (error) => {24 }, (stdout) => {25 });26});

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