Best JavaScript code snippet using mocha
FileManager.js
Source:FileManager.js
...57 xhr.responseType = "blob";58 xhr.addEventListener('load', function(evt) {59 if(evt.target.status == 200) {60 // .OK61 onCompletion(evt.target.response, null);62 } else if(evt.target.status == 404) {63 // .notFound64 var err = Object.freeze({ message : "Failed to find file"});65 onCompletion(null, err);66 } else if(evt.target.status == 400) {67 // .badRequest68 var err = Object.freeze({ message : "Server responsed with bad request"});69 onCompletion(null, err);70 } else if(evt.traget.status == 500) {71 // .internalServerError72 var err = Object.freeze({ message : "Server responsed with internal server error"});73 onCompletion(null, err);74 } else if(evt.target.status == 401) {75 // .unauthorized76 var err = Object.freeze({ message : "Server responsed with unauthorized request"});77 onCompletion(null, err);78 } else {79 // .unknown error80 var err = Object.freeze({ message : "Unknown error occured"});81 onCompletion(null, err);82 }83 });84 xhr.send();85 }86 /*87 ** Request server to get contents of text file88 ** 89 ** parameters90 ** -fileIds : id of the file91 ** -onCompletion : callback function (Blob data, error)92 **93 */94 loadFileTextWithId(fileId, onCompletion) {95 var xhr = new XMLHttpRequest();96 xhr.open('GET', Secretary.urlForFileId(fileId));97 xhr.responseType = "text";98 xhr.addEventListener('load', function(evt) {99 if(evt.target.status == 200) {100 // .OK101 onCompletion(evt.target.response, null);102 } else if(evt.target.status == 404) {103 // .notFound104 var err = Object.freeze({ message : "Failed to find file"});105 onCompletion(null, err);106 } else if(evt.target.status == 400) {107 // .badRequest108 var err = Object.freeze({ message : "Server responsed with bad request"});109 onCompletion(null, err);110 } else if(evt.traget.status == 500) {111 // .internalServerError112 var err = Object.freeze({ message : "Server responsed with internal server error"});113 onCompletion(null, err);114 } else if(evt.target.status == 401) {115 // .unauthorized116 var err = Object.freeze({ message : "Server responsed with unauthorized request"});117 onCompletion(null, err);118 } else {119 // .unknown error120 var err = Object.freeze({ message : "Unknown error occured"});121 onCompletion(null, err);122 }123 });124 xhr.send();125 }126 /*127 ** Request server to get contents of the file in the folder128 ** 129 ** parameters130 ** -folderId : id of folder to find file131 ** -fileName : name of the file to find in the folder132 ** -onCompletion : callback function (file as text?, error)133 ** 134 ** errorType135 ** 1 : server error136 ** 2 : file does not exist137 ** 3 : invalid location138 **139 */140 loadFileInFolder(folderId, fileName, onCompletion) {141 if(!onCompletion)142 return;143 var req = new RequestServer('FileInFolder');144 req.addData('Folder', folderId);145 req.addData('File', fileName)146 req.addEventListener('load', function(response, responseErr) {147 if(responseErr) {148 var err = Object.freeze({ type : 1,149 message : "Failed to load file with following error from server",150 detail : responseErr.detail });151 onCompletion(null, err);152 return;153 }154 if(response.DataBlockStatus == 0) {155 if(response.FileInFolder.status == 0) {156 // file found157 Secretary.loadFileWithId(response.FileInFolder.file.id, onCompletion);158 } else if(response.FileInFolder.status == 1) {159 // 404 not found!160 var err = Object.freeze({ type : 2,161 message : "File does not exist" });162 }163 }164 });165 req.send();166 }167 /*168 ** Request server to get list in folder169 ** 170 ** parameters171 ** -folder : DeskFile folder to list files172 ** -onCompletion : callback function (fileList, locationData, error)173 ** 174 ** errorType175 ** 1 : server error176 **177 */178 listInFolder(folder, onCompletion) {179 if(!onCompletion)180 return;181 if(folder.owner != Secretary.currentUser.id && this.isHomeFolder(folder)) {182 this.requestRemoteDrive(folder.owner, onCompletion);183 return;184 }185 var req = new RequestServer('FileList');186 req.addData('Path', folder.path);187 if(folder.id != null && folder.id != -1) {188 req.addData('Location', folder.id);189 }190 req.addEventListener('load', function(response, responseErr) {191 if(responseErr) {192 let err = Object.freeze({ type : 1,193 message : "Failed to load list data with following error from server",194 detail : responseErr.detail });195 onCompletion(null, null, err);196 return;197 }198 if(response.DataBlockStatus != 0) {199 let err = Object.freeze({ type : 1,200 message : "Failed to load list data with data with following error from server",201 detail : "Server returned DataBlockStatus = " + response.DataBlockStatus + " with datablock 'FileList'" });202 onCompletion(null, null, err);203 return;204 }205 if(!response.FileList.Location) {206 let err = Object.freeze({ type : 1,207 message : "Failed to load list data with following error from server",208 detail : responseErr.detail });209 onCompletion(null, null, err);210 return;211 }212 response = response.FileList;213 var files = new Array();214 if(folder.id == 0) {215 // home folder216 // add networks and trash217 files.push(this.trashcan);218 files.push(this.networkFolder);219 }220 var location = DeskFile.initWithFile(response.Location);221 if(location.path == null)222 location.path = folder.path;223 var path = folder.path ? folder.path : location.path;224 if(path) {225 if(path[path.length - 1] == "/") {226 path = path.slice(0, path.length - 1);227 }228 }229 for (var i = 0; i < response.FileList.length; i++) {230 var file = DeskFile.initWithFile(response.FileList[i]);231 if(path)232 file.path = path + "/" + file.name;233 files.push(file);234 }235 onCompletion(files, location, null);236 }.bind(this));237 req.send();238 }239 /*240 ** get DeskFile by Path241 ** 242 ** parameters243 ** -path : path of the file244 ** -onCompletion : callback function (DeskFile file, error)245 ** 246 ** errorType247 ** 1 : server error248 ** 2 : unauthorized249 ** 3 : file does not exist250 **251 */252 getFileByPath(path, onCompletion) {253 if(!onCompletion)254 return;255 var req = new RequestServer('FileByPath');256 req.addData('Path', path);257 req.addEventListener('load', function(response, responseErr) {258 if(responseErr) {259 let err = Object.freeze({ type : 1,260 message : "Failed to get file with following error from server",261 detail : responseErr.detail });262 onCompletion(null, err);263 return;264 }265 if(response.DataBlockStatus != 0) {266 let err = Object.freeze({ type : 1,267 message : "Failed to get file with data with following error from server",268 detail : "Server returned DataBlockStatus = " + response.DataBlockStatus + " with datablock 'FileByPath'" });269 onCompletion(null, err);270 return;271 }272 response = response.FileByPath;273 if(response.Error) {274 var errorCode = response.Error275 if(errorCode == 1) { // file does not exist276 let err = Object.freeze({ type : 3,277 message : "File does not exist"});278 onCompletion(null, err);279 return;280 }281 if(errorCode == 2) { // database error282 let err = Object.freeze({ type : 1,283 message : "Failed to add new folder with database error from server"});284 onCompletion(null, err);285 return;286 }287 if(errorCode == 3) { // permission is not given to view list288 let err = Object.freeze({ type : 2,289 message : "Unauthorized request"});290 onCompletion(null, err);291 return;292 }293 }294 var file = DeskFile.initWithFile(response.File);295 file.path = path;296 onCompletion(file, null);297 }.bind(this));298 req.send();299 }300 /*301 ** Request server to make new folder in a folder302 ** 303 ** parameters304 ** -folder : DeskFile folder where the new folder will be created305 ** -folderName : name of the folder to create306 ** -onCompletion : callback function (addedFolderId, error)307 ** 308 ** errorType309 ** 1 : server error310 ** 2 : folder name in use311 ** 3 : invalid location312 **313 */314 addFolder(folder, folderName, onCompletion) {315 if(!onCompletion)316 return;317 var req = new RequestServer('AddDirectory');318 if(folder.id == 2) {319 var err = Object.freeze({ type : 3,320 message : "Can not create folder in this location" });321 onCompletion(null, err);322 return;323 }324 req.addData('Name', folderName);325 req.addData('Location', folder.id);326 req.addEventListener('load', function(response, responseErr) {327 if(responseErr) {328 let err = Object.freeze({ type : 1,329 message : "Failed to add new folder with following error from server",330 detail : responseErr.detail });331 onCompletion(null, err);332 return;333 }334 if(response.DataBlockStatus != 0) {335 let err = Object.freeze({ type : 1,336 message : "Failed to add new folder with following error from server",337 detail : "Server returned DataBlockStatus = " + response.DataBlockStatus + " with datablock 'AddDirectory'" });338 onCompletion(null, err);339 return;340 }341 response = response.AddDirectory;342 if(response.UpdateResult == 1) { // already same name exist343 let err = Object.freeze({ type : 2,344 message : "'" + folderName + "'ì´ë¦ì´ ì´ë¯¸ ì¬ì©ì¤ ì
ëë¤."});345 onCompletion(null, err);346 return;347 }348 if(response.UpdateResult == 2) { // database error349 let err = Object.freeze({ type : 1,350 message : "Failed to add new folder with database error from server"});351 onCompletion(null, err);352 return;353 }354 onCompletion(response.FolderId, null);355 }.bind(this));356 req.send();357 }358 /*359 ** Request server to get list in remote location360 ** 361 ** parameters362 ** -userId : id of the owner of the drive to access363 ** -onCompletion : callback function (fileList, locationData, error)364 ** 365 ** errorType366 ** 1 : server error367 ** 2 : unauthorized368 ** 3 : invalid location369 **370 */371 requestRemoteDrive(userId, onCompletion) {372 if(!onCompletion)373 return;374 var req = new RequestServer('RemoteDrive');375 req.addData('UserId', userId);376 req.addEventListener('load', function(response, responseErr) {377 if(responseErr) {378 let err = Object.freeze({ type : 1,379 message : "Failed to load list data with following error from server",380 detail : responseErr.detail });381 onCompletion(null, null, err);382 return;383 }384 if(response.DataBlockStatus != 0) {385 let err = Object.freeze({ type : 1,386 message : "Failed to load list data with following error from server",387 detail : "Server returned DataBlockStatus = " + response.DataBlockStatus + " with datablock 'RemoteDrive'" });388 onCompletion(null, null, err);389 return;390 }391 response = response.RemoteDrive;392 if(response.UpdateResult == 1) { // remote location does not exist393 let err = Object.freeze({ type : 2,394 message : "Unauthorized request"});395 onCompletion(null, null, err);396 return;397 }398 if(response.UpdateResult == 2) { // database error399 let err = Object.freeze({ type : 1,400 message : "Failed to load list data with database error from server"});401 onCompletion(null, null, err);402 return;403 }404 if(response.UpdateResult == 3) { // permission is not given to view list405 let err = Object.freeze({ type : 2,406 message : "Unauthorized request"});407 onCompletion(null, null, err);408 return;409 }410 var location = DeskFile.initWithFile(response.Location);411 location.path = this.networkFolder.path + "/" + location.name;412 var files = new Array();413 for (var i = 0; i < response.FileList.length; i++) {414 var file = DeskFile.initWithFile(response.FileList[i]);415 file.path = location.path + "/" + file.name;416 files.push(file);417 }418 onCompletion(files, location, null);419 }.bind(this));420 req.send();421 }422 /*423 ** Upload files to the server424 ** 425 ** parameters426 ** -files : HTML file objects (Array)427 ** -onCompletion : callback function (file, error) // call back function will be called for each file428 ** -onProgress : callback function (file, loaded, total) // call back function will be called when progress updates for each file429 ** 430 ** errorType431 ** 1 : server error432 ** 2 : unauthorized433 ** 3 : invalid location434 **435 */436 uploadFiles(htmlFileObjects, location, onCompletion, onProgress, altNames) {437 if(!onCompletion)438 return;439 var names = new Array();440 for(var i = 0; i < htmlFileObjects.length; i++) {441 if(htmlFileObjects[i].size >= 4294967296) { // 4GB files442 // can't upload file bigger than 4GB443 } else {444 if(altNames) {445 names.push(altNames[i]);446 } else {447 names.push(htmlFileObjects[i].name);448 }449 }450 }451 // request server to get place to upload the files452 var req = new RequestServer('FileUploadRequest');453 req.addData('Location', location);454 req.addData('Names[]', names);455 req.addEventListener('load', function(response, responseErr) {456 if(responseErr) {457 let err = Object.freeze({ type : 1,458 message : "Failed to add new folder with following error from server",459 detail : responseErr.detail });460 onCompletion(null, err);461 return;462 }463 if(response.DataBlockStatus != 0) {464 var err = Object.freeze({ type : 1,465 message : "Failed to add new folder with following error from server",466 detail : "Server returned DataBlockStatus = " + response.DataBlockStatus + " with datablock 'FileUploadRequest'" });467 onCompletion(null, err);468 return;469 }470 response = response.FileUploadRequest;471 var errors = new Array();472 for(var i = 0; i < response.fileIds.length; i++) {473 if(response.fileIds[i] < 0) { // name already exist474 var err = Object.freeze({ type : 2,475 message : "'" + names[i] + "'ì´ë¦ì´ ì´ë¯¸ ì¬ì©ì¤ ì
ëë¤. ì
ë¡ëì ì¤í¨íììµëë¤."});476 onCompletion(null, err);477 } else {478 var file = new DeskFileUpload(response.fileIds[i], names[i]);479 file.location = location;480 file.size = htmlFileObjects[i].size;481 if(file.size < 1000000000) // file approximately less than 1GB482 Secretary.uploadFile(htmlFileObjects[i], file, onCompletion, onProgress);483 else484 Secretary.uploadBigFile(htmlFileObjects[i], file, onCompletion, onProgress);485 }486 }487 }.bind(this));488 req.send();489 }490 /*491 ** Rename given file492 ** 493 ** parameters494 ** -file : DeskFile Object495 ** -name : new name for the file496 ** -onCompletion : callback function (error)497 ** 498 ** errorType499 ** 1 : server error500 ** 2 : file name in use501 **502 */503 renameFile(file, name, onCompletion) {504 if(!onCompletion)505 return;506 var req = new RequestServer('RenameFile');507 req.addData('Name', name);508 req.addData('File', file.id);509 req.addData('Type', file.type);510 req.addEventListener('load', function(response, responseErr) {511 if(responseErr) {512 let err = Object.freeze({ type : 1,513 message : "Failed to add new folder with following error from server",514 detail : responseErr.detail });515 onCompletion(err);516 return;517 }518 if(response.DataBlockStatus != 0) {519 let err = Object.freeze({ type : 1,520 message : "Failed to add new folder with following error from server",521 detail : "Server returned DataBlockStatus = " + response.DataBlockStatus + " with datablock 'RenameFile'" });522 onCompletion(err);523 return;524 }525 response = response.RenameFile;526 if(response.UpdateResult == 1) { // already same name exist527 let err = Object.freeze({ type : 2,528 message : "'" + folderName + "'ì´ë¦ì´ ì´ë¯¸ ì¬ì©ì¤ ì
ëë¤."});529 onCompletion(err);530 return;531 }532 onCompletion(null);533 }.bind(this));534 req.send();535 }536 /*537 ** Make blank file538 ** 539 ** parameters540 ** -name : name for the file541 ** -folder : folder to make blank file542 ** -onCompletion : callback function (addedDeskFile, error)543 ** 544 ** errorType545 ** 1 : server error546 ** 2 : file name in use547 **548 */549 touch(name, folder, onCompletion) {550 if(!onCompletion)551 return;552 var req = new RequestServer('AddBlankFile');553 req.addData('Name', name);554 req.addData('Location', folder.id);555 req.addEventListener('load', function(response, responseErr) {556 if(responseErr) {557 var err = Object.freeze({ type : 1,558 message : "Failed to add new folder with following error from server",559 detail : responseErr.detail });560 onCompletion(null, err);561 return;562 }563 if(response.DataBlockStatus != 0) {564 var err = Object.freeze({ type : 1,565 message : "Failed to add new folder with following error from server",566 detail : "Server returned DataBlockStatus = " + response.DataBlockStatus + " with datablock 'AddBlankFile'" });567 onCompletion(null, err);568 return;569 }570 response = response.AddBlankFile;571 if(response.UpdateResult == 1) { // already same name exist572 var err = Object.freeze({ type : 2,573 message : "'" + name + "'ì´ë¦ì´ ì´ë¯¸ ì¬ì©ì¤ ì
ëë¤."});574 onCompletion(null, err);575 return;576 }577 var file = new DeskFile(response.FileId, name, 'BIN');578 onCompletion(file ,null);579 }.bind(this));580 req.send();581 }582 /*583 ** Copy files584 ** 585 ** parameters586 ** -files : array of DeskFile objects to copy587 ** -folder : folder to paste the copy588 ** -onCompletion : callback function (conflictedFiles, error)589 ** 590 ** errorType591 ** 1 : server error592 ** 2 : invalid location593 **594 */595 copyFiles(files, folder, onCompletion) {596 if(!onCompletion)597 return;598 var req = new RequestServer('CopyFiles');599 var fileIds = new Array();600 for (var i = 0; i < files.length; i++) {601 fileIds.push(files[i].id);602 }603 req.addData('FileList[]', fileIds);604 req.addData('Location', folder.id);605 req.addEventListener('load', function(response, responseErr) {606 if(responseErr) {607 let err = Object.freeze({ type : 1,608 message : "Failed to copy files with following error from server",609 detail : responseErr.detail });610 onCompletion(null, err);611 return;612 }613 if(response.DataBlockStatus != 0) {614 let err = Object.freeze({ type : 1,615 message : "Failed to copy files with following error from server",616 detail : "Server returned DataBlockStatus = " + response.DataBlockStatus + " with datablock 'CopyFiles'" });617 onCompletion(null, err);618 return;619 }620 response = response.CopyFiles;621 if(response.UpdateResult == 1) { // already same name exist622 let err = Object.freeze({ type : 2,623 message : "Can not copy files into this location"});624 onCompletion(null, err);625 return;626 }627 if(response.UpdateResult == 2) { // database error628 var err = Object.freeze({ type : 1,629 message : "Failed to copy files with database error from server"});630 onCompletion(null, err);631 return;632 }633 // check conflicted files634 var conflictedFiles = new Array();635 for (var i = 0; i < response.ConflictFiles.length; i++) {636 for (var j = 0; j < files.length; j++) {637 if(files[j].name == response.ConflictFiles[i].name) {638 conflictedFiles.push(files[j]);639 break;640 }641 }642 }643 onCompletion(conflictedFiles, null);644 }.bind(this));645 req.send();646 }647 /*648 ** Move files649 ** 650 ** parameters651 ** -files : array of DeskFile objects to move652 ** -folder : folder to paste the move653 ** -onCompletion : callback function (conflictedFiles, error)654 ** 655 ** errorType656 ** 1 : server error657 ** 2 : invalid location658 **659 */660 moveFiles(files, folder, onCompletion) {661 if(!onCompletion)662 return;663 var req = new RequestServer('MoveFiles');664 var fileIds = new Array();665 for (var i = 0; i < files.length; i++) {666 fileIds.push(files[i].id);667 }668 req.addData('FileList[]', fileIds);669 req.addData('Location', folder.id);670 req.addEventListener('load', function(response, responseErr) {671 if(responseErr) {672 let err = Object.freeze({ type : 1,673 message : "Failed to move files with following error from server",674 detail : responseErr.detail });675 onCompletion(null, err);676 return;677 }678 if(response.DataBlockStatus != 0) {679 let err = Object.freeze({ type : 1,680 message : "Failed to move files with following error from server",681 detail : "Server returned DataBlockStatus = " + response.DataBlockStatus + " with datablock 'MoveFiles'" });682 onCompletion(null, err);683 return;684 }685 response = response.MoveFiles;686 if(response.UpdateResult == 1) { // already same name exist687 let err = Object.freeze({ type : 2,688 message : "Can not move the files into this location"});689 onCompletion(null, err);690 return;691 }692 if(response.UpdateResult == 2) { // database error693 let err = Object.freeze({ type : 1,694 message : "Failed to move files with database error from server"});695 onCompletion(null, err);696 return;697 }698 // check conflicted files699 var conflictedFiles = new Array();700 for (var i = 0; i < response.ConflictFiles.length; i++) {701 for (var j = 0; j < files.length; j++) {702 if(files[j].name == response.ConflictFiles[i].name) {703 conflictedFiles.push(files[j]);704 break;705 }706 }707 }708 onCompletion(conflictedFiles, null);709 }.bind(this));710 req.send();711 }712 /*713 ** Trash files714 ** 715 ** parameters716 ** -files : array of DeskFile objects to throw into trash can717 ** -onCompletion : callback function (error)718 ** 719 ** errorType720 ** 1 : server error721 **722 */723 trashFiles(files, onCompletion) {724 if(!onCompletion)725 return;726 var req = new RequestServer('TrashFiles');727 var fileIds = new Array();728 for (var i = 0; i < files.length; i++) {729 fileIds.push(files[i].id);730 }731 req.addData('FileList[]', fileIds);732 req.addEventListener('load', function(response, responseErr) {733 if(responseErr) {734 let err = Object.freeze({ type : 1,735 message : "Failed to trash files with following error from server",736 detail : responseErr.detail });737 onCompletion(err);738 return;739 }740 if(response.DataBlockStatus != 0) {741 let err = Object.freeze({ type : 1,742 message : "Failed to trash files with following error from server",743 detail : "Server returned DataBlockStatus = " + response.DataBlockStatus + " with datablock 'TrashFiles'" });744 onCompletion(err);745 return;746 }747 // json = json.TrashFiles;748 onCompletion(null);749 }.bind(this));750 req.send();751 }752 /*753 ** Delete files754 ** 755 ** parameters756 ** -files : array of DeskFile objects to delete757 ** -onCompletion : callback function (error)758 ** 759 ** errorType760 ** 1 : server error761 **762 */763 deleteFiles(files, onCompletion) {764 if(!onCompletion)765 return;766 var req = new RequestServer('DeleteFiles');767 var fileIds = new Array();768 for (var i = 0; i < files.length; i++) {769 fileIds.push(files[i].id);770 }771 req.addData('FileList[]', fileIds);772 req.addEventListener('load', function(response, responseErr) {773 if(responseErr) {774 let err = Object.freeze({ type : 1,775 message : "Failed to delete files with following error from server",776 detail : responseErr.detail });777 onCompletion(err);778 return;779 }780 if(response.DataBlockStatus != 0) {781 let err = Object.freeze({ type : 1,782 message : "Failed to delete files with following error from server",783 detail : "Server returned DataBlockStatus = " + response.DataBlockStatus + " with datablock 'DeleteFiles'" });784 onCompletion(err);785 return;786 }787 response = response.DeleteFiles;788 if(response.UpdateResult == 2) { // database error789 let err = Object.freeze({ type : 1,790 message : "Failed to delete files with database error from server"});791 onCompletion(err);792 return;793 }794 onCompletion(null);795 }.bind(this));796 req.send();797 }...
memory.js
Source:memory.js
...73};74MemoryDatabank.prototype.connect = function(params, onCompletion) {75 var bank = this;76 if (bank.connected) {77 onCompletion(new AlreadyConnectedError());78 return;79 }80 setImmediate(function() {81 var type;82 bank.types = {};83 for (type in bank.schema) {84 bank.types[type] = {};85 }86 bank.connected = true;87 Step(88 function() {89 var key, group = this.group();90 for (type in bank.data) {91 for (key in bank.data[type]) {92 bank.create(type, key, bank.data[type][key], group());93 }94 }95 },96 function(err, created) {97 if (err) {98 onCompletion(err);99 } else {100 onCompletion(null);101 }102 }103 );104 });105};106MemoryDatabank.prototype.disconnect = function(onCompletion) {107 var bank = this;108 if (!bank.connected) {109 onCompletion(new NotConnectedError());110 return;111 }112 setImmediate(function() {113 delete bank.types;114 // Always succeed115 bank.connected = false;116 onCompletion(null);117 });118};119MemoryDatabank.prototype.create = function(type, id, value, onCompletion) {120 var bank = this;121 if (!bank.connected) {122 onCompletion(new NotConnectedError());123 return;124 }125 setImmediate(function() {126 if (!bank.types) {127 bank.types = {};128 }129 if (!(type in bank.types)) {130 bank.types[type] = {};131 }132 if (id in bank.types[type]) {133 onCompletion(new AlreadyExistsError(type, id), null);134 } else {135 bank.types[type][id] = bank.freeze(value);136 onCompletion(null, value);137 }138 });139};140MemoryDatabank.prototype.update = function(type, id, value, onCompletion) {141 var bank = this;142 if (!bank.connected) {143 onCompletion(new NotConnectedError());144 return;145 }146 setImmediate(function() {147 if (!bank.types) {148 bank.types = {};149 }150 if (!(type in bank.types)) {151 bank.types[type] = {};152 }153 if (!(id in bank.types[type])) {154 onCompletion(new NoSuchThingError(type, id), null);155 } else {156 bank.types[type][id] = bank.freeze(value);157 onCompletion(null, value);158 }159 });160};161MemoryDatabank.prototype.read = function(type, id, onCompletion) {162 var bank = this;163 if (!bank.connected) {164 onCompletion(new NotConnectedError());165 return;166 }167 setImmediate(function() {168 var value;169 170 if (!bank.types) {171 bank.types = {};172 }173 if (!(type in bank.types)) {174 bank.types[type] = {};175 }176 if (!(id in bank.types[type])) {177 onCompletion(new NoSuchThingError(type, id), null);178 } else {179 value = bank.melt(bank.types[type][id]);180 onCompletion(null, value);181 }182 });183};184MemoryDatabank.prototype.del = function(type, id, onCompletion) {185 var bank = this;186 if (!bank.connected) {187 onCompletion(new NotConnectedError());188 return;189 }190 setImmediate(function() {191 if (!bank.types) {192 bank.types = {};193 }194 if (!(type in bank.types)) {195 bank.types[type] = {};196 }197 if (!(id in bank.types[type])) {198 onCompletion(new NoSuchThingError(type, id));199 } else {200 delete bank.types[type][id];201 onCompletion(null);202 }203 });204};205MemoryDatabank.prototype.save = function(type, id, value, onCompletion) {206 var bank = this;207 if (!bank.connected) {208 onCompletion(new NotConnectedError());209 return;210 }211 setImmediate(function() {212 if (!bank.types) {213 bank.types = {};214 }215 if (!(type in bank.types)) {216 bank.types[type] = {};217 }218 bank.types[type][id] = bank.freeze(value);219 onCompletion(null, value);220 });221};222MemoryDatabank.prototype.search = function(type, criteria, onResult, onCompletion) {223 var bank = this;224 if (!bank.connected) {225 onCompletion(new NotConnectedError());226 return;227 }228 // We have no indices, so search == scan229 bank.scan(type,230 function(value) {231 if (bank.matchesCriteria(value, criteria)) {232 onResult(value);233 }234 },235 function(err) {236 onCompletion(err);237 });238};239MemoryDatabank.prototype.scan = function(type, onResult, onCompletion) {240 var bank = this;241 if (!bank.connected) {242 onCompletion(new NotConnectedError());243 return;244 }245 setImmediate(function() {246 var id, value;247 if (!bank.types) {248 bank.types = {};249 }250 if (!(type in bank.types)) {251 bank.types[type] = {};252 }253 for (id in bank.types[type]) {254 value = bank.melt(bank.types[type][id]);255 onResult(value);256 }257 onCompletion(null);258 });259};260MemoryDatabank.prototype.readAll = function(type, ids, onCompletion) {261 var bank = this;262 if (!bank.connected) {263 onCompletion(new NotConnectedError());264 return;265 }266 setImmediate(function() {267 var i, id, value, map = {};268 if (!bank.types) {269 bank.types = {};270 }271 if (!(type in bank.types)) {272 bank.types[type] = {};273 }274 for (i = 0; i < ids.length; i++) {275 id = ids[i];276 if (!(id in bank.types[type])) {277 map[id] = null;278 } else {279 map[id] = bank.melt(bank.types[type][id]);280 }281 }282 onCompletion(null, map);283 });284};285MemoryDatabank.prototype.incr = function(type, id, onCompletion) {286 var bank = this;287 if (!bank.connected) {288 onCompletion(new NotConnectedError());289 return;290 }291 setImmediate(function() {292 if (!bank.types) {293 bank.types = {};294 }295 if (!(type in bank.types)) {296 bank.types[type] = {};297 }298 if (!(id in bank.types[type])) {299 bank.types[type][id] = 1;300 onCompletion(null, 1);301 } else {302 bank.types[type][id]++;303 onCompletion(null, bank.types[type][id]);304 }305 });306};307MemoryDatabank.prototype.decr = function(type, id, onCompletion) {308 var bank = this;309 if (!bank.connected) {310 onCompletion(new NotConnectedError());311 return;312 }313 setImmediate(function() {314 if (!bank.types) {315 bank.types = {};316 }317 if (!(type in bank.types)) {318 bank.types[type] = {};319 }320 if (!(id in bank.types[type])) {321 bank.types[type][id] = -1;322 onCompletion(null, -1);323 } else {324 bank.types[type][id]--;325 onCompletion(null, bank.types[type][id]);326 }327 });328};329MemoryDatabank.prototype.append = function(type, id, toAppend, onCompletion) {330 var bank = this;331 if (!bank.connected) {332 onCompletion(new NotConnectedError());333 return;334 }335 setImmediate(function() {336 if (!bank.types) {337 bank.types = {};338 }339 if (!(type in bank.types)) {340 bank.types[type] = {};341 }342 if (!(id in bank.types[type])) {343 bank.types[type][id] = [bank.freeze(toAppend)];344 } else {345 bank.types[type][id].push(bank.freeze(toAppend));346 }347 onCompletion(null);348 });349};350MemoryDatabank.prototype.prepend = function(type, id, toAppend, onCompletion) {351 var bank = this;352 if (!bank.connected) {353 onCompletion(new NotConnectedError());354 return;355 }356 setImmediate(function() {357 if (!bank.types) {358 bank.types = {};359 }360 if (!(type in bank.types)) {361 bank.types[type] = {};362 }363 if (!(id in bank.types[type])) {364 bank.types[type][id] = [bank.freeze(toAppend)];365 } else {366 bank.types[type][id].unshift(bank.freeze(toAppend));367 }368 onCompletion(null);369 });370};371MemoryDatabank.prototype.item = function(type, id, index, onCompletion) {372 var bank = this;373 if (!bank.connected) {374 onCompletion(new NotConnectedError());375 return;376 }377 setImmediate(function() {378 if (!bank.types) {379 bank.types = {};380 }381 if (!(type in bank.types)) {382 bank.types[type] = {};383 }384 if (!(id in bank.types[type])) {385 onCompletion(new NoSuchThingError(type, id), null);386 } else if (!(index in bank.types[type][id])) {387 onCompletion(new DatabankError("Bad index: " + index), null);388 } else {389 onCompletion(null, bank.melt(bank.types[type][id][index]));390 }391 });392};393MemoryDatabank.prototype.slice = function(type, id, start, length, onCompletion) {394 var bank = this;395 if (!bank.connected) {396 onCompletion(new NotConnectedError());397 return;398 }399 setImmediate(function() {400 if (!bank.types) {401 bank.types = {};402 }403 if (!(type in bank.types)) {404 bank.types[type] = {};405 }406 if (!(id in bank.types[type])) {407 onCompletion(new NoSuchThingError(type, id), null);408 } else {409 onCompletion(null, bank.melt(bank.types[type][id].slice(start, length)));410 }411 });412};413MemoryDatabank.prototype.indexOf = function(type, id, item, onCompletion) {414 var bank = this;415 if (!bank.connected) {416 onCompletion(new NotConnectedError());417 return;418 }419 setImmediate(function() {420 if (!bank.types) {421 bank.types = {};422 }423 if (!(type in bank.types)) {424 bank.types[type] = {};425 }426 if (!(id in bank.types[type])) {427 onCompletion(new NoSuchThingError(type, id), null);428 } else {429 onCompletion(null, bank.types[type][id].indexOf(bank.freeze(item)));430 }431 });432};433MemoryDatabank.prototype.remove = function(type, id, item, onCompletion) {434 var bank = this;435 if (!bank.connected) {436 onCompletion(new NotConnectedError());437 return;438 }439 setImmediate(function() {440 var i;441 if (!bank.types) {442 bank.types = {};443 }444 if (!(type in bank.types)) {445 bank.types[type] = {};446 }447 if (!(id in bank.types[type])) {448 onCompletion(new NoSuchThingError(type, id), null);449 } else {450 i = bank.types[type][id].indexOf(bank.freeze(item));451 if (i === -1) {452 onCompletion(new DatabankError("No such item"));453 } else {454 bank.types[type][id].splice(i, 1);455 onCompletion(null);456 }457 }458 });459};...
soapelementsproxy.js
Source:soapelementsproxy.js
1function Elements()2{3 this.PROXY = new SOAPProxy(this, 0,4 "http://213.23.125.181:8080/RPC", 5 "urn:SpheonJSOAPChemistry", 6 false); // false = not friendly / needs privileges7}8// Object to proxy methods9Elements.prototype =10{11 PROXY: null,12 RECEIVER: function(proxy, headers, parameters) // This interprets all responses13 {14 proxy.PROXY.result = null;15 if (parameters != null) {16 var parameter = parameters[0];17 // The following line can be used to force a result type18 // parameter.schemaType = proxy.PROXY.getType("boolean");19 proxy.PROXY.result = parameter.value;20 }21 if (proxy.PROXY.oncompletion != null) {22 proxy.PROXY.oncompletion(proxy.PROXY.result);23 }24 },25 // Proxy-specific items26 getElementBySymbol: function(symbol, oncompletion)27 {28 var type = null;29 // The following line can be used to force a parameter type30 // type = this.PROXY.getType("long");31 return this.PROXY.invoke(32 "getElementBySymbol",33 null, new Array(new SOAPParameter(symbol,"symbol",null,type)),34 this.RECEIVER, oncompletion);35 },36 getNumberBySymbol: function(symbol, oncompletion)37 {38 var type = null;39 // The following line can be used to force a parameter type40 // type = this.PROXY.getType("long");41 return this.PROXY.invoke(42 "getNumberBySymbol",43 null, new Array(new SOAPParameter(symbol,"symbol",null,type)),44 this.RECEIVER, oncompletion);45 },46 getNameBySymbol: function(symbol, oncompletion)47 {48 var type = null;49 // The following line can be used to force a parameter type50 // type = this.PROXY.getType("long");51 return this.PROXY.invoke(52 "getNameBySymbol",53 null, new Array(new SOAPParameter(symbol,"symbol",null,type)),54 this.RECEIVER, oncompletion);55 },56 getMassBySymbol: function(symbol, oncompletion)57 {58 var type = null;59 // The following line can be used to force a parameter type60 // type = this.PROXY.getType("long");61 return this.PROXY.invoke(62 "getMassBySymbol",63 null, new Array(new SOAPParameter(symbol,"symbol",null,type)),64 this.RECEIVER, oncompletion);65 },66 getMeltingPointBySymbol: function(symbol, oncompletion)67 {68 var type = null;69 // The following line can be used to force a parameter type70 // type = this.PROXY.getType("long");71 return this.PROXY.invoke(72 "getMeltingPointBySymbol",73 null, new Array(new SOAPParameter(symbol,"symbol",null,type)),74 this.RECEIVER, oncompletion);75 },76 getBoilingPointBySymbol: function(symbol, oncompletion)77 {78 var type = null;79 // The following line can be used to force a parameter type80 // type = this.PROXY.getType("long");81 return this.PROXY.invoke(82 "getBoilingBointBySymbol",83 null, new Array(new SOAPParameter(symbol,"symbol",null,type)),84 this.RECEIVER, oncompletion);85 },86 getFoundBySymbol: function(symbol, oncompletion)87 {88 var type = null;89 // The following line can be used to force a parameter type90 // type = this.PROXY.getType("long");91 return this.PROXY.invoke(92 "foundBySymbol",93 null, new Array(new SOAPParameter(symbol,"symbol",null,type)),94 this.RECEIVER, oncompletion);95 },96 getElementByNumber: function(number, oncompletion)97 {98 var type = null;99 // The following line can be used to force a parameter type100 // type = this.PROXY.getType("long");101 return this.PROXY.invoke(102 "getElementByNumber",103 null, new Array(new SOAPParameter(number,"number",null,type)),104 this.RECEIVER, oncompletion);105 },106 getSymbolByNumber: function(number, oncompletion)107 {108 var type = null;109 // The following line can be used to force a parameter type110 // type = this.PROXY.getType("long");111 return this.PROXY.invoke(112 "getSymbolByNumber",113 null, new Array(new SOAPParameter(number,"number",null,type)),114 this.RECEIVER, oncompletion);115 },116 getNameByNumber: function(number, oncompletion)117 {118 var type = null;119 // The following line can be used to force a parameter type120 // type = this.PROXY.getType("long");121 return this.PROXY.invoke(122 "getNameByNumber",123 null, new Array(new SOAPParameter(number,"number",null,type)),124 this.RECEIVER, oncompletion);125 },126 getMassByNumber: function(number, oncompletion)127 {128 var type = null;129 // The following line can be used to force a parameter type130 // type = this.PROXY.getType("long");131 return this.PROXY.invoke(132 "getMassByNumber",133 null, new Array(new SOAPParameter(number,"number",null,type)),134 this.RECEIVER, oncompletion);135 },136 getMeltingPointByNumber: function(number, oncompletion)137 {138 var type = null;139 // The following line can be used to force a parameter type140 // type = this.PROXY.getType("long");141 return this.PROXY.invoke(142 "getMeltingPointByNumber",143 null, new Array(new SOAPParameter(number,"number",null,type)),144 this.RECEIVER, oncompletion);145 },146 getBoilingPointByNumber: function(number, oncompletion)147 {148 var type = null;149 // The following line can be used to force a parameter type150 // type = this.PROXY.getType("long");151 return this.PROXY.invoke(152 "getBoilingPointByNumber",153 null, new Array(new SOAPParameter(number,"number",null,type)),154 this.RECEIVER, oncompletion);155 },156 getFoundByNumber: function(number, oncompletion)157 {158 var type = null;159 // The following line can be used to force a parameter type160 // type = this.PROXY.getType("long");161 return this.PROXY.invoke(162 "foundByNumber",163 null, new Array(new SOAPParameter(number,"number",null,type)),164 this.RECEIVER, oncompletion);165 }...
WebClient.js
Source:WebClient.js
...87 }88 if (response.status == 200) {89 // console.log('\nRESPONSE SUCCESSSS : ', response.data.data)90 // if (response.data.status == 1) {91 // onCompletion(true, response.data);92 // } else {93 // onCompletion(false, {94 // 'status': response.data.status,95 // 'message': response.data.message96 // });97 // }98 if (response.data.status != 1) {99 onCompletion(null, {100 'code': response.data.status,101 'message': response.data.message102 });103 } else {104 onCompletion(response.data.data, null);105 }106 } else {107 if (response.status == 404) {108 onCompletion(null, {109 'code': response.status,110 'message': "URL NOT FOUND"111 });112 } else if (response.status == 401) {113 onCompletion(null, {114 'code': response.status,115 'message': "Unauthorized"116 });117 } else {118 if (response.problem == 'NETWORK_ERROR') {119 onCompletion(null, {120 'code': 0,121 'message': response.problem122 });123 } else {124 onCompletion(null, {125 'code': 0,126 'message': response.problem127 });128 }129 }130 }...
fences.spec.js
Source:fences.spec.js
...21// Promise resolves when onCompletion value is less than signal value.22g.test('wait,less_than_signaled').fn(async t => {23 const fence = t.queue.createFence();24 t.queue.signal(fence, 2);25 await fence.onCompletion(1);26 t.expect(fence.getCompletedValue() === 2);27});28// Promise resolves when onCompletion value is equal to signal value.29g.test('wait,equal_to_signaled').fn(async t => {30 const fence = t.queue.createFence();31 t.queue.signal(fence, 2);32 await fence.onCompletion(2);33 t.expect(fence.getCompletedValue() === 2);34});35// All promises resolve when signal is called once.36g.test('wait,signaled_once').fn(async t => {37 const fence = t.queue.createFence();38 t.queue.signal(fence, 20);39 const promises = [];40 for (let i = 0; i <= 20; ++i) {41 promises.push(42 fence.onCompletion(i).then(() => {43 t.expect(fence.getCompletedValue() >= i);44 })45 );46 }47 await Promise.all(promises);48});49// Promise resolves when signal is called multiple times.50g.test('wait,signaled_multiple_times').fn(async t => {51 const fence = t.queue.createFence();52 t.queue.signal(fence, 1);53 t.queue.signal(fence, 2);54 await fence.onCompletion(2);55 t.expect(fence.getCompletedValue() === 2);56});57// Promise resolves if fence has already completed.58g.test('wait,already_completed').fn(async t => {59 const fence = t.queue.createFence();60 t.queue.signal(fence, 2);61 // Wait for value to update.62 while (fence.getCompletedValue() < 2) {63 await new Promise(resolve => {64 requestAnimationFrame(resolve);65 });66 }67 t.expect(fence.getCompletedValue() === 2);68 await fence.onCompletion(2);69 t.expect(fence.getCompletedValue() === 2);70});71// Test many calls to signal and wait on fence values one at a time.72g.test('wait,many,serially').fn(async t => {73 const fence = t.queue.createFence();74 for (let i = 1; i <= 20; ++i) {75 t.queue.signal(fence, i);76 await fence.onCompletion(i);77 t.expect(fence.getCompletedValue() === i);78 }79});80// Test many calls to signal and wait on all fence values.81g.test('wait,many,parallel').fn(async t => {82 const fence = t.queue.createFence();83 const promises = [];84 for (let i = 1; i <= 20; ++i) {85 t.queue.signal(fence, i);86 promises.push(87 fence.onCompletion(i).then(() => {88 t.expect(fence.getCompletedValue() >= i);89 })90 );91 }92 await Promise.all(promises);93 t.expect(fence.getCompletedValue() === 20);94});95// Test onCompletion promise resolves within a time limit.96g.test('wait,resolves_within_timeout').fn(t => {97 const fence = t.queue.createFence();98 t.queue.signal(fence, 2);99 return raceWithRejectOnTimeout(100 (async () => {101 await fence.onCompletion(2);102 t.expect(fence.getCompletedValue() === 2);103 })(),104 100,105 'The fence has not been resolved within time limit.'106 );107});108// Test dropping references to the fence and onCompletion promise does not crash.109g.test('drop,fence_and_promise').fn(async t => {110 {111 const fence = t.queue.createFence();112 t.queue.signal(fence, 2);113 fence.onCompletion(2);114 }115 await attemptGarbageCollection();116});117// Test dropping references to the fence and holding the promise does not crash.118g.test('drop,promise').fn(async t => {119 let promise;120 {121 const fence = t.queue.createFence();122 t.queue.signal(fence, 2);123 promise = fence.onCompletion(2);124 }125 await attemptGarbageCollection();126 await promise;...
soapunscrambleproxy.js
Source:soapunscrambleproxy.js
1function Unscramble()2{3 this.PROXY = new SOAPProxy(this, 0, 4 "http://ray.dsl.xmission.com:8080/soap/servlet/rpcrouter", 5 "http://soaptests.mozilla.org/unscramble", 6 true); // true = friendly to untrusted applets7}8// Object to proxy methods9Unscramble.prototype =10{11 // Standard items on all SOAP proxies using SOAPProxy.12 PROXY: null,13 // Proxy-specific items14 unscramble: function(language, word, oncompletion)15 {16 var type = null;17 // The following line can be used to force a parameter type18 type = this.PROXY.getType("string");19 return this.PROXY.invoke(20 "unscramble",21 null, new Array(22 new SOAPParameter(language,"language",null,type),23 new SOAPParameter(word,"word",null,type)),24 function(proxy, headers, parameters) // This interprets the response25 {26 proxy.PROXY.result = null;27 if (parameters != null) {28 var parameter = parameters[0];29 // The following line can be used to force a result type30 // parameter.schemaType = proxy.PROXY.getType("boolean");31 proxy.PROXY.result = parameter.value;32 }33 if (proxy.PROXY.oncompletion != null) {34 proxy.PROXY.oncompletion(proxy.PROXY.result);35 }36 }, oncompletion);37 },38 languages: function(oncompletion)39 {40 var type = null;41 return this.PROXY.invoke("languages",null,null,42 function(proxy, headers, parameters) // This interprets the response43 {44 proxy.PROXY.result = null;45 if (parameters != null) {46 var parameter = parameters[0];47 // The following line can be used to force a result type48 // parameter.schemaType = proxy.PROXY.getType("boolean");49 proxy.PROXY.result = parameter.value;50 }51 if (proxy.PROXY.oncompletion != null) {52 proxy.PROXY.oncompletion(proxy.PROXY.result);53 }54 }, oncompletion);55 }...
blockchaindb.js
Source:blockchaindb.js
1class BlockchainDB {2 constructor (/* session */ bdbBaseURL, /* func */ apiBaseURL /* func */) {3 }4 5 get bdbBaseURL() {6 }7 get apiBaseURL() {8 }9 // session10 // queue11 // QueryError12 // Model13 // Blockchain14 // CurrencyDenomination15 // Currency16 // Transfer17 // Transaction18 // Block19 // Subscription20 getBlockchains (mainnet, onCompletion) {21 }22 getBlockchain (blockchainID, onCompletion) {23 }24 getCurrencies (blockchainID, onCompletion) {25 }26 getCurrency (currencyID, onCompletion) {27 }28 // subscriptions29 getTransfers (blockchainID, address,30 begBlockNumber, endBlockNumber, maxPageSize,31 onCompletion) {32 }33 getTransfer (transferID, onCompletion) {34 }35 getTransactions (blockchainID,36 address,37 begBlockNumber,38 endBlockNumber,39 includeRaw,40 includeProof,41 maxPageSize,42 onCompletion) {43 }44 getTransaction (transactionID,45 includeRaw,46 includeProof,47 onCompletion) {48 }49 createTransaction (blockchainID,50 hash, /* HexString */51 transaction, /* Data */52 onCompletion) {53 }54 // getBlocks55 // getBlock56 // Ethereum57 // JSON58 // sendRequest59 // decorateRequest60 // makeRequest61 // bdb62 // handleResult63 // makeRequest64 // ......
Using AI Code Generation
1var Mocha = require('mocha');2var mocha = new Mocha({3});4mocha.addFile('test/test.js');5mocha.run(function(failures){6 process.on('exit', function () {7 });8});9var assert = require('assert');10describe('Array', function() {11 describe('#indexOf()', function() {12 it('should return -1 when the value is not present', function() {13 assert.equal(-1, [1,2,3].indexOf(5));14 assert.equal(-1, [1,2,3].indexOf(0));15 });16 });17});
Using AI Code Generation
1var delegate = new MochaJSDelegate({2 "webView:didFinishLoadForFrame:": (webView, webFrame) => {3 if (webFrame == webView.mainFrame()) {4 }5 }6});7var webView = UIWebView.alloc().initWithFrame(8 CGRectMake(0, 0, 100, 100)9);10webView.setDelegate(delegate.getClassInstance());11var delegate = new MochaJSDelegate({12 "webView:didFinishLoadForFrame:": (webView, webFrame) => {13 if (webFrame == webView.mainFrame()) {14 }15 }16});17var webView = UIWebView.alloc().initWithFrame(18 CGRectMake(0, 0, 100, 100)19);20webView.setDelegate(delegate.getClassInstance());21var delegate = new MochaJSDelegate({22 "webView:didFinishLoadForFrame:": (webView, webFrame) => {23 if (webFrame == webView.mainFrame()) {24 }25 }26});27var webView = UIWebView.alloc().initWithFrame(28 CGRectMake(0, 0, 100, 100)29);30webView.setDelegate(delegate.getClassInstance());31var delegate = new MochaJSDelegate({32 "webView:didFinishLoadForFrame:": (webView, webFrame) => {33 if (webFrame == webView.mainFrame()) {34 }35 }36});37var webView = UIWebView.alloc().initWithFrame(38 CGRectMake(0, 0, 100, 100)39);40webView.setDelegate(delegate.getClassInstance());41var delegate = new MochaJSDelegate({
Using AI Code Generation
1var delegate = new MochaJSDelegate({2 "webView:didFinishLoadForFrame:": (webView, webFrame) => {3 }4});5var delegate = new MochaJSDelegate({6 "webView:didFinishLoadForFrame:": (webView, webFrame) => {7 }8});9var delegate = new MochaJSDelegate({10 "webView:didFinishLoadForFrame:": (webView, webFrame) => {11 }12});13var delegate = new MochaJSDelegate({14 "webView:didFinishLoadForFrame:": (webView, webFrame) => {15 }16});17var delegate = new MochaJSDelegate({18 "webView:didFinishLoadForFrame:": (webView, webFrame) => {19 }20});21var delegate = new MochaJSDelegate({22 "webView:didFinishLoadForFrame:": (webView, webFrame) => {23 }24});25var delegate = new MochaJSDelegate({26 "webView:didFinishLoadForFrame:": (webView, webFrame) => {27 }28});29var delegate = new MochaJSDelegate({30 "webView:didFinishLoadForFrame:": (webView, webFrame) => {31 }32});33var delegate = new MochaJSDelegate({34 "webView:didFinishLoadForFrame:": (webView, webFrame) => {35 }36});37var delegate = new MochaJSDelegate({
Using AI Code Generation
1var delegate = new MochaJSDelegate({2 "onCompletion":(function(error) {3 if (error) {4 } else {5 }6 })7});8var delegate = new MochaJSDelegate({9 "onCompletion":(function(error) {10 if (error) {11 } else {12 }13 })14});15var delegate = new MochaJSDelegate({16 "onCompletion":(function(error) {17 if (error) {18 } else {19 }20 })21});22var delegate = new MochaJSDelegate({23 "onCompletion":(function(error) {24 if (error) {25 } else {26 }27 })28});29var delegate = new MochaJSDelegate({30 "onCompletion":(function(error) {31 if (error) {32 } else {33 }34 })35});
Using AI Code Generation
1describe('My test', function() {2 it('should pass', function(done) {3 setTimeout(function() {4 done();5 }, 1000);6 });7});8describe('My test', function() {9 it('should pass', function(done) {10 setTimeout(function() {11 done();12 }, 1000);13 });14});15describe('My test', function() {16 after(function(done) {17 setTimeout(function() {18 done();19 }, 1000);20 });21});22describe('My test', function() {23 afterEach(function(done) {24 setTimeout(function() {25 done();26 }, 1000);27 });28});29describe('My test', function() {30 before(function(done) {31 setTimeout(function() {32 done();33 }, 1000);34 });35});36describe('My test', function() {37 beforeEach(function(done) {38 setTimeout(function() {39 done();40 }, 1000);41 });42});43describe('My test', function() {44 context('My context', function(done) {45 setTimeout(function() {46 done();47 }, 1000);48 });49});50describe('My test', function() {51 suiteSetup(function(done) {52 setTimeout(function() {53 done();54 }, 1000);55 });56});57describe('My test', function() {58 suiteTeardown(function(done) {59 setTimeout(function() {
Using AI Code Generation
1var delegate = new MochaJSDelegate({2 "webView:didFinishLoadForFrame:": function(webview, frame) {3 console.log("webView:didFinishLoadForFrame:");4 console.log("webview: " + webview);5 console.log("frame: " + frame);6 }7});8var webView = UIWebView.alloc().initWithFrame(CGRectMake(0, 0, 300, 300));9webView.delegate = delegate.getClassInstance();10var delegate = new MochaJSDelegate({11 "webView:didFinishLoadForFrame:": function(webview, frame) {12 console.log("webView:didFinishLoadForFrame:");13 console.log("webview: " + webview);14 console.log("frame: " + frame);15 }16});17var webView = UIWebView.alloc().initWithFrame(CGRectMake(0, 0, 300, 300));18webView.delegate = delegate.getClassInstance();19I am trying to use MochaJSDelegate to get a callback when a UIWebView has finished loading a URL. I have the following code:When I run this code, I get the following error:TypeError: undefined is not a function (evaluating 'webView.delegate = delegate.getClassInstance()')I am using the following versions of Sketch and MochaJSDelegate:Sketch: 3.8.2MochaJSDelegate: 1.2.1I have also tried using the following code to get a callback when a UIWebView has finished loading a URL, but I get the same error:TypeError: undefined is not a function (evaluating 'webView.delegate = delegate.getClassInstance()')I am using the following versions of Sketch and MochaJSDelegate:Sketch: 3.8.2MochaJSDelegate: 1.2.1
Using AI Code Generation
1var Mocha = require('mocha');2var fs = require('fs');3var mocha = new Mocha();4var testDir = 'test/testDir';5var testFile = 'test/testFile.txt';6fs.readdirSync(testDir).filter(function(file){7 return file.substr(-3) === '.js';8}).forEach(function(file){9 mocha.addFile(10 path.join(testDir, file)11 );12});13mocha.run(function(failures){14 console.log('failures', failures);15 if (failures === 0) {16 fs.writeFile(testFile, 'Mocha Unit Test', function (err) {17 if (err) throw err;18 console.log('File saved!');19 });20 }21});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!