How to use err method in Best

Best JavaScript code snippet using best

user.server.model.tests.js

Source:user.server.model.tests.js Github

copy

Full Screen

1'use strict';2/**3 * Module dependencies.4 */5var should = require('should'),6 mongoose = require('mongoose'),7 User = mongoose.model('User'),8 path = require('path'),9 config = require(path.resolve('./config/config'));10/**11 * Globals12 */13var user1,14 user2,15 user3;16/**17 * Unit tests18 */19describe('User Model Unit Tests:', function () {20 before(function () {21 user1 = {22 firstName: 'Full',23 lastName: 'Name',24 displayName: 'Full Name',25 email: 'test@test.com',26 username: 'username',27 password: 'M3@n.jsI$Aw3$0m3',28 provider: 'local'29 };30 // user2 is a clone of user131 user2 = user1;32 user3 = {33 firstName: 'Different',34 lastName: 'User',35 displayName: 'Full Different Name',36 email: 'test3@test.com',37 username: 'different_username',38 password: 'Different_Password1!',39 provider: 'local'40 };41 });42 describe('Method Save', function () {43 it('should begin with no users', function (done) {44 User.find({}, function (err, users) {45 users.should.have.length(0);46 done();47 });48 });49 it('should be able to save without problems', function (done) {50 var _user1 = new User(user1);51 _user1.save(function (err) {52 should.not.exist(err);53 _user1.remove(function (err) {54 should.not.exist(err);55 done();56 });57 });58 });59 it('should fail to save an existing user again', function (done) {60 var _user1 = new User(user1);61 var _user2 = new User(user2);62 _user1.save(function () {63 _user2.save(function (err) {64 should.exist(err);65 _user1.remove(function (err) {66 should.not.exist(err);67 done();68 });69 });70 });71 });72 it('should be able to show an error when trying to save without first name', function (done) {73 var _user1 = new User(user1);74 _user1.firstName = '';75 _user1.save(function (err) {76 should.exist(err);77 done();78 });79 });80 it('should be able to update an existing user with valid roles without problems', function (done) {81 var _user1 = new User(user1);82 _user1.save(function (err) {83 should.not.exist(err);84 _user1.roles = ['user', 'admin'];85 _user1.save(function (err) {86 should.not.exist(err);87 _user1.remove(function (err) {88 should.not.exist(err);89 done();90 });91 });92 });93 });94 it('should be able to show an error when trying to update an existing user without a role', function (done) {95 var _user1 = new User(user1);96 _user1.save(function (err) {97 should.not.exist(err);98 _user1.roles = [];99 _user1.save(function (err) {100 should.exist(err);101 _user1.remove(function (err) {102 should.not.exist(err);103 done();104 });105 });106 });107 });108 it('should be able to show an error when trying to update an existing user with a invalid role', function (done) {109 var _user1 = new User(user1);110 _user1.save(function (err) {111 should.not.exist(err);112 _user1.roles = ['invalid-user-role-enum'];113 _user1.save(function (err) {114 should.exist(err);115 _user1.remove(function (err) {116 should.not.exist(err);117 done();118 });119 });120 });121 });122 it('should confirm that saving user model doesnt change the password', function (done) {123 var _user1 = new User(user1);124 _user1.save(function (err) {125 should.not.exist(err);126 var passwordBefore = _user1.password;127 _user1.firstName = 'test';128 _user1.save(function (err) {129 var passwordAfter = _user1.password;130 passwordBefore.should.equal(passwordAfter);131 _user1.remove(function (err) {132 should.not.exist(err);133 done();134 });135 });136 });137 });138 it('should be able to save 2 different users', function (done) {139 var _user1 = new User(user1);140 var _user3 = new User(user3);141 _user1.save(function (err) {142 should.not.exist(err);143 _user3.save(function (err) {144 should.not.exist(err);145 _user3.remove(function (err) {146 should.not.exist(err);147 _user1.remove(function (err) {148 should.not.exist(err);149 done();150 });151 });152 });153 });154 });155 it('should not be able to save another user with the same email address', function (done) {156 // Test may take some time to complete due to db operations157 this.timeout(10000);158 var _user1 = new User(user1);159 var _user3 = new User(user3);160 _user1.save(function (err) {161 should.not.exist(err);162 _user3.email = _user1.email;163 _user3.save(function (err) {164 should.exist(err);165 _user1.remove(function(err) {166 should.not.exist(err);167 done();168 });169 });170 });171 });172 it('should not index missing email field, thus not enforce the model\'s unique index', function (done) {173 var _user1 = new User(user1);174 _user1.email = undefined;175 var _user3 = new User(user3);176 _user3.email = undefined;177 _user1.save(function (err) {178 should.not.exist(err);179 _user3.save(function (err) {180 should.not.exist(err);181 _user3.remove(function (err) {182 should.not.exist(err);183 _user1.remove(function (err) {184 should.not.exist(err);185 done();186 });187 });188 });189 });190 });191 it('should not save the password in plain text', function (done) {192 var _user1 = new User(user1);193 var passwordBeforeSave = _user1.password;194 _user1.save(function (err) {195 should.not.exist(err);196 _user1.password.should.not.equal(passwordBeforeSave);197 _user1.remove(function(err) {198 should.not.exist(err);199 done();200 });201 });202 });203 it('should not save the passphrase in plain text', function (done) {204 var _user1 = new User(user1);205 _user1.password = 'Open-Source Full-Stack Solution for MEAN';206 var passwordBeforeSave = _user1.password;207 _user1.save(function (err) {208 should.not.exist(err);209 _user1.password.should.not.equal(passwordBeforeSave);210 _user1.remove(function(err) {211 should.not.exist(err);212 done();213 });214 });215 });216 });217 describe('User Password Validation Tests', function() {218 it('should validate when the password strength passes - "P@$$w0rd!!"', function () {219 var _user1 = new User(user1);220 _user1.password = 'P@$$w0rd!!';221 _user1.validate(function (err) {222 should.not.exist(err);223 });224 });225 it('should validate a randomly generated passphrase from the static schema method', function () {226 var _user1 = new User(user1);227 User.generateRandomPassphrase()228 .then(function (password) {229 _user1.password = password;230 _user1.validate(function (err) {231 should.not.exist(err);232 });233 })234 .catch(function (err) {235 should.not.exist(err);236 });237 });238 it('should validate when the password is undefined', function () {239 var _user1 = new User(user1);240 _user1.password = undefined;241 _user1.validate(function (err) {242 should.not.exist(err);243 });244 });245 it('should validate when the passphrase strength passes - "Open-Source Full-Stack Solution For MEAN Applications"', function () {246 var _user1 = new User(user1);247 _user1.password = 'Open-Source Full-Stack Solution For MEAN Applications';248 _user1.validate(function (err) {249 should.not.exist(err);250 });251 });252 it('should not allow a password less than 10 characters long - "P@$$w0rd!"', function (done) {253 var _user1 = new User(user1);254 _user1.password = 'P@$$w0rd!';255 _user1.validate(function (err) {256 err.errors.password.message.should.equal('The password must be at least 10 characters long.');257 done();258 });259 });260 it('should not allow a password greater than 128 characters long.', function (done) {261 var _user1 = new User(user1);262 _user1.password = ')!/uLT="lh&:`6X!]|15o!$!TJf,.13l?vG].-j],lFPe/QhwN#{Z<[*1nX@n1^?WW-%_.*D)m$toB+N7z}kcN#B_d(f41h%w@0F!]igtSQ1gl~6sEV&r~}~1ub>If1c+';263 _user1.validate(function (err) {264 err.errors.password.message.should.equal('The password must be fewer than 128 characters.');265 done();266 });267 });268 it('should not allow a password with 3 or more repeating characters - "P@$$w0rd!!!"', function (done) {269 var _user1 = new User(user1);270 _user1.password = 'P@$$w0rd!!!';271 _user1.validate(function (err) {272 err.errors.password.message.should.equal('The password may not contain sequences of three or more repeated characters.');273 done();274 });275 });276 it('should not allow a password with no uppercase letters - "p@$$w0rd!!"', function (done) {277 var _user1 = new User(user1);278 _user1.password = 'p@$$w0rd!!';279 _user1.validate(function (err) {280 err.errors.password.message.should.equal('The password must contain at least one uppercase letter.');281 done();282 });283 });284 it('should not allow a password with less than one number - "P@$$word!!"', function (done) {285 var _user1 = new User(user1);286 _user1.password = 'P@$$word!!';287 _user1.validate(function (err) {288 err.errors.password.message.should.equal('The password must contain at least one number.');289 done();290 });291 });292 it('should not allow a password with less than one special character - "Passw0rdss"', function (done) {293 var _user1 = new User(user1);294 _user1.password = 'Passw0rdss';295 _user1.validate(function (err) {296 err.errors.password.message.should.equal('The password must contain at least one special character.');297 done();298 });299 });300 });301 describe('User E-mail Validation Tests', function() {302 it('should not allow invalid email address - "123"', function (done) {303 var _user1 = new User(user1);304 _user1.email = '123';305 _user1.save(function (err) {306 if (!err) {307 _user1.remove(function (err_remove) {308 should.exist(err);309 should.not.exist(err_remove);310 done();311 });312 } else {313 should.exist(err);314 done();315 }316 });317 });318 it('should not allow invalid email address - "123@123@123"', function (done) {319 var _user1 = new User(user1);320 _user1.email = '123@123@123';321 _user1.save(function (err) {322 if (!err) {323 _user1.remove(function (err_remove) {324 should.exist(err);325 should.not.exist(err_remove);326 done();327 });328 } else {329 should.exist(err);330 done();331 }332 });333 });334 it('should allow email address - "123@123"', function (done) {335 var _user1 = new User(user1);336 _user1.email = '123@123';337 _user1.save(function (err) {338 if (!err) {339 _user1.remove(function (err_remove) {340 should.not.exist(err);341 should.not.exist(err_remove);342 done();343 });344 } else {345 should.not.exist(err);346 done();347 }348 });349 });350 it('should not allow invalid email address - "123.com"', function (done) {351 var _user1 = new User(user1);352 _user1.email = '123.com';353 _user1.save(function (err) {354 if (!err) {355 _user1.remove(function (err_remove) {356 should.exist(err);357 should.not.exist(err_remove);358 done();359 });360 } else {361 should.exist(err);362 done();363 }364 });365 });366 it('should not allow invalid email address - "@123.com"', function (done) {367 var _user1 = new User(user1);368 _user1.email = '@123.com';369 _user1.save(function (err) {370 if (!err) {371 _user1.remove(function (err_remove) {372 should.exist(err);373 should.not.exist(err_remove);374 done();375 });376 } else {377 should.exist(err);378 done();379 }380 });381 });382 it('should not allow invalid email address - "abc@abc@abc.com"', function (done) {383 var _user1 = new User(user1);384 _user1.email = 'abc@abc@abc.com';385 _user1.save(function (err) {386 if (!err) {387 _user1.remove(function (err_remove) {388 should.exist(err);389 should.not.exist(err_remove);390 done();391 });392 } else {393 should.exist(err);394 done();395 }396 });397 });398 it('should not allow invalid characters in email address - "abc~@#$%^&*()ef=@abc.com"', function (done) {399 var _user1 = new User(user1);400 _user1.email = 'abc~@#$%^&*()ef=@abc.com';401 _user1.save(function (err) {402 if (!err) {403 _user1.remove(function (err_remove) {404 should.exist(err);405 should.not.exist(err_remove);406 done();407 });408 } else {409 should.exist(err);410 done();411 }412 });413 });414 it('should not allow space characters in email address - "abc def@abc.com"', function (done) {415 var _user1 = new User(user1);416 _user1.email = 'abc def@abc.com';417 _user1.save(function (err) {418 if (!err) {419 _user1.remove(function (err_remove) {420 should.exist(err);421 should.not.exist(err_remove);422 done();423 });424 } else {425 should.exist(err);426 done();427 }428 });429 });430 it('should not allow doudble quote characters in email address - "abc\"def@abc.com"', function (done) {431 var _user1 = new User(user1);432 _user1.email = 'abc\"def@abc.com';433 _user1.save(function (err) {434 if (err) {435 _user1.remove(function (err_remove) {436 should.exist(err);437 should.not.exist(err_remove);438 done();439 });440 } else {441 should.exist(err);442 done();443 }444 });445 });446 it('should not allow double dotted characters in email address - "abcdef@abc..com"', function (done) {447 var _user1 = new User(user1);448 _user1.email = 'abcdef@abc..com';449 _user1.save(function (err) {450 if (err) {451 _user1.remove(function (err_remove) {452 should.exist(err);453 should.not.exist(err_remove);454 done();455 });456 } else {457 should.exist(err);458 done();459 }460 });461 });462 it('should allow single quote characters in email address - "abc\'def@abc.com"', function (done) {463 var _user1 = new User(user1);464 _user1.email = 'abc\'def@abc.com';465 _user1.save(function (err) {466 if (!err) {467 _user1.remove(function (err_remove) {468 should.not.exist(err);469 should.not.exist(err_remove);470 done();471 });472 } else {473 should.not.exist(err);474 done();475 }476 });477 });478 it('should allow valid email address - "abc@abc.com"', function (done) {479 var _user1 = new User(user1);480 _user1.email = 'abc@abc.com';481 _user1.save(function (err) {482 if (!err) {483 _user1.remove(function (err_remove) {484 should.not.exist(err);485 should.not.exist(err_remove);486 done();487 });488 } else {489 should.not.exist(err);490 done();491 }492 });493 });494 it('should allow valid email address - "abc+def@abc.com"', function (done) {495 var _user1 = new User(user1);496 _user1.email = 'abc+def@abc.com';497 _user1.save(function (err) {498 if (!err) {499 _user1.remove(function (err_remove) {500 should.not.exist(err);501 should.not.exist(err_remove);502 done();503 });504 } else {505 should.not.exist(err);506 done();507 }508 });509 });510 it('should allow valid email address - "abc.def@abc.com"', function (done) {511 var _user1 = new User(user1);512 _user1.email = 'abc.def@abc.com';513 _user1.save(function (err) {514 if (!err) {515 _user1.remove(function (err_remove) {516 should.not.exist(err);517 should.not.exist(err_remove);518 done();519 });520 } else {521 should.not.exist(err);522 done();523 }524 });525 });526 it('should allow valid email address - "abc.def@abc.def.com"', function (done) {527 var _user1 = new User(user1);528 _user1.email = 'abc.def@abc.def.com';529 _user1.save(function (err) {530 if (!err) {531 _user1.remove(function (err_remove) {532 should.not.exist(err);533 should.not.exist(err_remove);534 done();535 });536 } else {537 should.not.exist(err);538 done();539 }540 });541 });542 it('should allow valid email address - "abc-def@abc.com"', function (done) {543 var _user1 = new User(user1);544 _user1.email = 'abc-def@abc.com';545 _user1.save(function (err) {546 should.not.exist(err);547 if (!err) {548 _user1.remove(function (err_remove) {549 should.not.exist(err_remove);550 done();551 });552 } else {553 done();554 }555 });556 });557 });558 describe('Username Validation', function() {559 it('should show error to save username beginning with .', function(done) {560 var _user = new User(user1);561 _user.username = '.login';562 _user.save(function(err) {563 should.exist(err);564 done();565 });566 });567 it('should be able to show an error when try to save with not allowed username', function (done) {568 var _user = new User(user1);569 _user.username = config.illegalUsernames[Math.floor(Math.random() * config.illegalUsernames.length)];570 _user.save(function(err) {571 should.exist(err);572 done();573 });574 });575 it('should show error to save username end with .', function(done) {576 var _user = new User(user1);577 _user.username = 'login.';578 _user.save(function(err) {579 should.exist(err);580 done();581 });582 });583 it('should show error to save username with ..', function(done) {584 var _user = new User(user1);585 _user.username = 'log..in';586 _user.save(function(err) {587 should.exist(err);588 done();589 });590 });591 it('should show error to save username shorter than 3 character', function(done) {592 var _user = new User(user1);593 _user.username = 'lo';594 _user.save(function(err) {595 should.exist(err);596 done();597 });598 });599 it('should show error saving a username without at least one alphanumeric character', function(done) {600 var _user = new User(user1);601 _user.username = '-_-';602 _user.save(function(err) {603 should.exist(err);604 done();605 });606 });607 it('should show error saving a username longer than 34 characters', function(done) {608 var _user = new User(user1);609 _user.username = 'l'.repeat(35);610 _user.save(function(err) {611 should.exist(err);612 done();613 });614 });615 it('should save username with dot', function(done) {616 var _user = new User(user1);617 _user.username = 'log.in';618 _user.save(function(err) {619 should.not.exist(err);620 done();621 });622 });623 });624 after(function (done) {625 User.remove().exec(done);626 });...

Full Screen

Full Screen

callback-return.js

Source:callback-return.js Github

copy

Full Screen

1/**2 * @fileoverview Tests for callback return rule.3 * @author Jamund Ferguson4 */5"use strict";6//------------------------------------------------------------------------------7// Requirements8//------------------------------------------------------------------------------9const rule = require("../../../lib/rules/callback-return"),10 RuleTester = require("../../../lib/testers/rule-tester");11//------------------------------------------------------------------------------12// Tests13//------------------------------------------------------------------------------14const ruleTester = new RuleTester();15ruleTester.run("callback-return", rule, {16 valid: [17 // callbacks inside of functions should return18 "function a(err) { if (err) return callback (err); }",19 "function a(err) { if (err) return callback (err); callback(); }",20 "function a(err) { if (err) { return callback (err); } callback(); }",21 "function a(err) { if (err) { return /* confusing comment */ callback (err); } callback(); }",22 "function x(err) { if (err) { callback(); return; } }",23 "function x(err) { if (err) { \n log();\n callback(); return; } }",24 "function x(err) { if (err) { callback(); return; } return callback(); }",25 "function x(err) { if (err) { return callback(); } else { return callback(); } }",26 "function x(err) { if (err) { return callback(); } else if (x) { return callback(); } }",27 "function x(err) { if (err) return callback(); else return callback(); }",28 "function x(cb) { cb && cb(); }",29 "function x(next) { typeof next !== 'undefined' && next(); }",30 "function x(next) { if (typeof next === 'function') { return next() } }",31 "function x() { switch(x) { case 'a': return next(); } }",32 "function x() { for(x = 0; x < 10; x++) { return next(); } }",33 "function x() { while(x) { return next(); } }",34 "function a(err) { if (err) { obj.method (err); } }",35 // callback() all you want outside of a function36 "callback()",37 "callback(); callback();",38 "while(x) { move(); }",39 "for (var i = 0; i < 10; i++) { move(); }",40 "for (var i = 0; i < 10; i++) move();",41 "if (x) callback();",42 "if (x) { callback(); }",43 // arrow functions44 {45 code: "var x = err => { if (err) { callback(); return; } }",46 parserOptions: { ecmaVersion: 6 }47 },48 {49 code: "var x = err => callback(err)",50 parserOptions: { ecmaVersion: 6 }51 },52 {53 code: "var x = err => { setTimeout( () => { callback(); }); }",54 parserOptions: { ecmaVersion: 6 }55 },56 // classes57 {58 code: "class x { horse() { callback(); } } ",59 parserOptions: { ecmaVersion: 6 }60 }, {61 code: "class x { horse() { if (err) { return callback(); } callback(); } } ",62 parserOptions: { ecmaVersion: 6 }63 },64 // options (only warns with the correct callback name)65 {66 code: "function a(err) { if (err) { callback(err) } }",67 options: [["cb"]]68 },69 {70 code: "function a(err) { if (err) { callback(err) } next(); }",71 options: [["cb", "next"]]72 },73 {74 code: "function a(err) { if (err) { return next(err) } else { callback(); } }",75 options: [["cb", "next"]]76 },77 // allow object methods (https://github.com/eslint/eslint/issues/4711)78 {79 code: "function a(err) { if (err) { return obj.method(err); } }",80 options: [["obj.method"]]81 },82 {83 code: "function a(err) { if (err) { return obj.prop.method(err); } }",84 options: [["obj.prop.method"]]85 },86 {87 code: "function a(err) { if (err) { return obj.prop.method(err); } otherObj.prop.method() }",88 options: [["obj.prop.method", "otherObj.prop.method"]]89 },90 {91 code: "function a(err) { if (err) { callback(err); } }",92 options: [["obj.method"]]93 },94 {95 code: "function a(err) { if (err) { otherObj.method(err); } }",96 options: [["obj.method"]]97 },98 {99 code: "function a(err) { if (err) { //comment\nreturn obj.method(err); } }",100 options: [["obj.method"]]101 },102 {103 code: "function a(err) { if (err) { /*comment*/return obj.method(err); } }",104 options: [["obj.method"]]105 },106 {107 code: "function a(err) { if (err) { return obj.method(err); //comment\n } }",108 options: [["obj.method"]]109 },110 {111 code: "function a(err) { if (err) { return obj.method(err); /*comment*/ } }",112 options: [["obj.method"]]113 },114 // only warns if object of MemberExpression is an Identifier115 {116 code: "function a(err) { if (err) { obj().method(err); } }",117 options: [["obj().method"]]118 },119 {120 code: "function a(err) { if (err) { obj.prop().method(err); } }",121 options: [["obj.prop().method"]]122 },123 {124 code: "function a(err) { if (err) { obj().prop.method(err); } }",125 options: [["obj().prop.method"]]126 },127 // does not warn if object of MemberExpression is invoked128 {129 code: "function a(err) { if (err) { obj().method(err); } }",130 options: [["obj.method"]]131 },132 {133 code: "function a(err) { if (err) { obj().method(err); } obj.method(); }",134 options: [["obj.method"]]135 },136 // known bad examples that we know we are ignoring137 "function x(err) { if (err) { setTimeout(callback, 0); } callback(); }", // callback() called twice138 "function x(err) { if (err) { process.nextTick(function(err) { callback(); }); } callback(); }" // callback() called twice139 ],140 invalid: [141 {142 code: "function a(err) { if (err) { callback (err); } }",143 errors: [{144 messageId: "missingReturn",145 line: 1,146 column: 30,147 nodeType: "CallExpression"148 }]149 },150 {151 code: "function a(callback) { if (typeof callback !== 'undefined') { callback(); } }",152 errors: [{153 messageId: "missingReturn",154 line: 1,155 column: 63,156 nodeType: "CallExpression"157 }]158 },159 {160 code: "function a(callback) { if (typeof callback !== 'undefined') callback(); }",161 errors: [{162 messageId: "missingReturn",163 line: 1,164 column: 61,165 nodeType: "CallExpression"166 }]167 },168 {169 code: "function a(callback) { if (err) { callback(); horse && horse(); } }",170 errors: [{171 messageId: "missingReturn",172 line: 1,173 column: 35,174 nodeType: "CallExpression"175 }]176 },177 {178 code: "var x = (err) => { if (err) { callback (err); } }",179 parserOptions: { ecmaVersion: 6 },180 errors: [{181 messageId: "missingReturn",182 line: 1,183 column: 31,184 nodeType: "CallExpression"185 }]186 },187 {188 code: "var x = { x(err) { if (err) { callback (err); } } }",189 parserOptions: { ecmaVersion: 6 },190 errors: [{191 messageId: "missingReturn",192 line: 1,193 column: 31,194 nodeType: "CallExpression"195 }]196 },197 {198 code: "function x(err) { if (err) {\n log();\n callback(err); } }",199 errors: [{200 messageId: "missingReturn",201 line: 3,202 column: 2,203 nodeType: "CallExpression"204 }]205 },206 {207 code: "var x = { x(err) { if (err) { callback && callback (err); } } }",208 parserOptions: { ecmaVersion: 6 },209 errors: [{210 messageId: "missingReturn",211 line: 1,212 column: 43,213 nodeType: "CallExpression"214 }]215 },216 {217 code: "function a(err) { callback (err); callback(); }",218 errors: [{219 messageId: "missingReturn",220 line: 1,221 column: 19,222 nodeType: "CallExpression"223 }]224 },225 {226 code: "function a(err) { callback (err); horse(); }",227 errors: [{228 messageId: "missingReturn",229 line: 1,230 column: 19,231 nodeType: "CallExpression"232 }]233 },234 {235 code: "function a(err) { if (err) { callback (err); horse(); return; } }",236 errors: [{237 messageId: "missingReturn",238 line: 1,239 column: 30,240 nodeType: "CallExpression"241 }]242 },243 {244 code: "var a = (err) => { callback (err); callback(); }",245 parserOptions: { ecmaVersion: 6 },246 errors: [{247 messageId: "missingReturn",248 line: 1,249 column: 20,250 nodeType: "CallExpression"251 }]252 },253 {254 code: "function a(err) { if (err) { callback (err); } else if (x) { callback(err); return; } }",255 errors: [{256 messageId: "missingReturn",257 line: 1,258 column: 30,259 nodeType: "CallExpression"260 }]261 },262 {263 code: "function x(err) { if (err) { return callback(); }\nelse if (abc) {\ncallback(); }\nelse {\nreturn callback(); } }",264 errors: [{265 messageId: "missingReturn",266 line: 3,267 column: 1,268 nodeType: "CallExpression"269 }]270 },271 {272 code: "class x { horse() { if (err) { callback(); } callback(); } } ",273 parserOptions: { ecmaVersion: 6 },274 errors: [{275 messageId: "missingReturn",276 line: 1,277 column: 32,278 nodeType: "CallExpression"279 }]280 },281 // generally good behavior which we must not allow to keep the rule simple282 {283 code: "function x(err) { if (err) { callback() } else { callback() } }",284 errors: [{285 messageId: "missingReturn",286 line: 1,287 column: 30,288 nodeType: "CallExpression"289 }, {290 messageId: "missingReturn",291 line: 1,292 column: 50,293 nodeType: "CallExpression"294 }]295 },296 {297 code: "function x(err) { if (err) return callback(); else callback(); }",298 errors: [299 {300 messageId: "missingReturn",301 line: 1,302 column: 52,303 nodeType: "CallExpression"304 }305 ]306 },307 {308 code: "() => { if (x) { callback(); } }",309 parserOptions: { ecmaVersion: 6 },310 errors: [311 {312 messageId: "missingReturn",313 line: 1,314 column: 18,315 nodeType: "CallExpression"316 }317 ]318 },319 {320 code: "function b() { switch(x) { case 'horse': callback(); } }",321 errors: [322 {323 messageId: "missingReturn",324 line: 1,325 column: 42,326 nodeType: "CallExpression"327 }328 ]329 },330 {331 code: "function a() { switch(x) { case 'horse': move(); } }",332 options: [["move"]],333 errors: [334 {335 messageId: "missingReturn",336 line: 1,337 column: 42,338 nodeType: "CallExpression"339 }340 ]341 },342 // loops343 {344 code: "var x = function() { while(x) { move(); } }",345 options: [["move"]],346 errors: [347 {348 messageId: "missingReturn",349 line: 1,350 column: 33,351 nodeType: "CallExpression"352 }353 ]354 },355 {356 code: "function x() { for (var i = 0; i < 10; i++) { move(); } }",357 options: [["move"]],358 errors: [359 {360 messageId: "missingReturn",361 line: 1,362 column: 47,363 nodeType: "CallExpression"364 }365 ]366 },367 {368 code: "var x = function() { for (var i = 0; i < 10; i++) move(); }",369 options: [["move"]],370 errors: [371 {372 messageId: "missingReturn",373 line: 1,374 column: 51,375 nodeType: "CallExpression"376 }377 ]378 },379 {380 code: "function a(err) { if (err) { obj.method(err); } }",381 options: [["obj.method"]],382 errors: [383 {384 messageId: "missingReturn",385 line: 1,386 column: 30,387 nodeType: "CallExpression"388 }389 ]390 },391 {392 code: "function a(err) { if (err) { obj.prop.method(err); } }",393 options: [["obj.prop.method"]],394 errors: [395 {396 messageId: "missingReturn",397 line: 1,398 column: 30,399 nodeType: "CallExpression"400 }401 ]402 },403 {404 code: "function a(err) { if (err) { obj.prop.method(err); } otherObj.prop.method() }",405 options: [["obj.prop.method", "otherObj.prop.method"]],406 errors: [407 {408 messageId: "missingReturn",409 line: 1,410 column: 30,411 nodeType: "CallExpression"412 }413 ]414 },415 {416 code: "function a(err) { if (err) { /*comment*/obj.method(err); } }",417 options: [["obj.method"]],418 errors: [419 {420 messageId: "missingReturn",421 line: 1,422 column: 41,423 nodeType: "CallExpression"424 }425 ]426 },427 {428 code: "function a(err) { if (err) { //comment\nobj.method(err); } }",429 options: [["obj.method"]],430 errors: [431 {432 messageId: "missingReturn",433 line: 2,434 column: 1,435 nodeType: "CallExpression"436 }437 ]438 },439 {440 code: "function a(err) { if (err) { obj.method(err); /*comment*/ } }",441 options: [["obj.method"]],442 errors: [443 {444 messageId: "missingReturn",445 line: 1,446 column: 30,447 nodeType: "CallExpression"448 }449 ]450 },451 {452 code: "function a(err) { if (err) { obj.method(err); //comment\n } }",453 options: [["obj.method"]],454 errors: [455 {456 messageId: "missingReturn",457 line: 1,458 column: 30,459 nodeType: "CallExpression"460 }461 ]462 }463 ]...

Full Screen

Full Screen

data.js

Source:data.js Github

copy

Full Screen

1"use strict";2const mysql = require("mysql");3let config = {4 host: "us-cdbr-east-03.cleardb.com",5 port: 3306,6 database: "heroku_4d5cf3f565482d3",7 user: "b4c0797768ddd6",8 password: "51a3b7d2",9};10function row2play(row) {11 return {12 beat_id: row.beat_id13 }14}15function row2beat(row) {16 return {17 id: row.id,18 name: row.name,19 producer_id: row.producer_id,20 cover: row.cover,21 genre: row.genre,22 tag: row.tag,23 bpm: row.bpm,24 mood: row.mood,25 price: row.price,26 audio: row.audio27 }28}29function row2producer(row) {30 return {31 id: row.id,32 username: row.username,33 name: row.name,34 avatar: row.avatar,35 background: row.background,36 aboutme: row.aboutme,37 genre: row.genre,38 twitter: row.twitter,39 instagram: row.instagram,40 youtube: row.youtube,41 email: row.email42 }43}44function row2user(row) {45 return {46 id: row.id,47 username: row.username,48 password: row.password49 }50}51function row2genre(row) {52 return {53 id: row.id,54 name: row.name55 }56}57function row2mood(row) {58 return {59 id: row.id,60 name: row.name61 }62}63function row2soldbeat(row) {64 return {65 data: row.data,66 created_at: row.created_at + ""67 }68}69function getMoods(cb) {70 let connection = mysql.createConnection(config);71 connection.connect((err) => {72 if(err) {73 cb(err);74 } else {75 let sql = "SELECT * from moods";76 connection.query(sql, (err, rows) => {77 connection.end();78 if (err) {79 return cb(err);80 } else {81 return cb(err, rows.map(row2mood));82 }83 });84 }85 });86}87function getGenres(cb) {88 let connection = mysql.createConnection(config);89 connection.connect((err) => {90 if(err) {91 cb(err);92 } else {93 let sql = "SELECT * from genres";94 connection.query(sql, (err, rows) => {95 connection.end();96 if (err) {97 return cb(err);98 } else {99 return cb(err, rows.map(row2genre));100 }101 });102 }103 });104}105function getBeats(cb) {106 let connection = mysql.createConnection(config);107 connection.connect((err) => {108 if(err) {109 cb(err);110 } else {111 let sql = "SELECT * from beats";112 connection.query(sql, (err, rows) => {113 connection.end();114 if (err) {115 return cb(err);116 } else {117 return cb(err, rows.map(row2beat));118 }119 });120 }121 });122}123function getBeat(id, cb) {124 let connection = mysql.createConnection(config);125 connection.connect((err) => {126 if(err) {127 cb(err);128 } else {129 let sql = `SELECT * from beats where id=${id}`;130 connection.query(sql, (err, rows) => {131 connection.end();132 if (err) {133 return cb(err);134 } else {135 return cb(err, rows.map(row2beat));136 }137 });138 }139 });140}141function getBeatsByProducerId(producer_id, cb) {142 let connection = mysql.createConnection(config);143 connection.connect((err) => {144 if(err) {145 cb(err);146 } else {147 let sql = `SELECT * from beats where producer_id=${producer_id}`;148 connection.query(sql, (err, rows) => {149 connection.end();150 if (err) {151 return cb(err);152 } else {153 return cb(err, rows.map(row2beat));154 }155 })156 }157 })158}159function getSoldBeats(id, cb) {160 let connection = mysql.createConnection(config);161 connection.connect((err) => {162 if(err) {163 cb(err);164 } else {165 let sql = `SELECT * from notifications where notifiable_id=${id}`;166 connection.query(sql, (err, rows) => {167 connection.end();168 if (err) {169 return cb(err);170 } else {171 return cb(err, rows.map(row2soldbeat));172 }173 });174 }175 });176}177function getPlays(beat_id, cb) {178 let connection = mysql.createConnection(config);179 connection.connect((err) => {180 if(err) {181 cb(err);182 } else {183 let sql = `SELECT * from plays where beat_id=${beat_id}`;184 connection.query(sql, (err, rows) => {185 connection.end();186 if (err) {187 return cb(err);188 } else {189 return cb(err, rows.map(row2play));190 }191 });192 }193 });194}195function getProducers(cb) {196 let connection = mysql.createConnection(config);197 connection.connect((err) => {198 if(err) {199 cb(err);200 } else {201 let sql = "SELECT * from users";202 connection.query(sql, (err, rows) => {203 connection.end();204 if (err) {205 return cb(err);206 } else {207 return cb(err, rows.map(row2producer));208 }209 });210 }211 });212}213function loginUser(username, cb) {214 let connection = mysql.createConnection(config);215 connection.connect((err) => {216 if(err) {217 cb(err);218 } else {219 let sql = `SELECT * from users where username='${username}'`;220 connection.query(sql, (err, rows) => {221 connection.end();222 if (err) {223 return cb(err);224 } else {225 return cb(err, rows.map(row2user));226 }227 });228 }229 });230}231function getProducer(id, cb) {232 let connection = mysql.createConnection(config);233 connection.connect((err) => {234 if(err) {235 cb(err);236 } else {237 let sql = `SELECT * from users where id=${id}`;238 connection.query(sql, (err, rows) => {239 connection.end();240 if (err) {241 return cb(err);242 } else {243 return cb(err, rows.map(row2producer));244 }245 });246 }247 });248}249function getUserById(id, cb) {250 let connection = mysql.createConnection(config);251 connection.connect((err) => {252 if(err) {253 cb(err);254 } else {255 let sql = `SELECT * from users where id='${id}'`;256 connection.query(sql, (err, rows) => {257 connection.end();258 if (err) {259 return cb(err);260 } else {261 return cb(err, rows.map(row2user));262 }263 })264 }265 })266}267function getProducerByUsername(username, cb) {268 let connection = mysql.createConnection(config);269 connection.connect((err) => {270 if(err) {271 cb(err);272 } else {273 let sql = `SELECT * from users where username='${username}'`;274 connection.query(sql, (err, rows) => {275 connection.end();276 if (err) {277 return cb(err);278 } else {279 return cb(err, rows.map(row2producer));280 }281 })282 }283 })284}285function createBeat(id, name, producerId, cover, genre, tag, bpm, mood, price, audio, cb) {286 let connection = mysql.createConnection(config);287 connection.connect((err) => {288 if (err) {289 cb(err);290 } else {291 const producerType = "App\Models\User";292 let sql = "INSERT INTO `beats`(`id`, `name`, `producer_id`, `cover`, `genre`, `tag`, `bpm`, `mood`, `price`, `audio`, `producer_type`) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";293 connection.query(sql, [id, name, producerId, cover, genre, tag, bpm, mood, price, audio, producerType], (err, result) => {294 connection.end();295 if (err) cb(err);296 else cb(err, true);297 });298 }299 });300}301function registerPlay(beat_id, created_at, updated_at, cb) {302 let connection = mysql.createConnection(config);303 connection.connect((err) => {304 if (err) {305 cb(err);306 } else {307 let sql = "INSERT INTO `plays`(`beat_id`, `created_at`, `updated_at`) VALUES(?, ?, ?);";308 connection.query(sql, [beat_id, created_at, updated_at], (err, result) => {309 connection.end();310 if (err) cb(err);311 else cb(err, true);312 });313 }314 });315}316function buyBeat(id, type, notifiable_type, notifiable_id, data, read_at, created_at, updated_at, cb) {317 let connection = mysql.createConnection(config);318 connection.connect((err) => {319 if (err) {320 cb(err);321 } else {322 let sql = "INSERT INTO `notifications`(`id`, `type`, `notifiable_type`, `notifiable_id`, `data`, `read_at`, `created_at`, `updated_at`) VALUES(?, ?, ?, ?, ?, ?, ?, ?);";323 connection.query(sql, [id, type, notifiable_type, notifiable_id, data, read_at, created_at, updated_at], (err, result) => {324 connection.end();325 if (err) cb(err);326 else cb(err, true);327 });328 }329 });330}331function registerUser(id, username, name, email, password, avatar, background, aboutme, genre, twitter, instagram, youtube, created_at, updated_at, cb) {332 let connection = mysql.createConnection(config);333 connection.connect((err) => {334 if (err) {335 cb(err);336 } else {337 let sql = "INSERT INTO `users`(`id`, `username`, `name`, `email`, `password`, `avatar`, `background`, `aboutme`, `genre`, `twitter`, `instagram`, `youtube`, `created_at`, `updated_at`) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";338 connection.query(sql, [id, username, name, email, password, avatar, background, aboutme, genre, twitter, instagram, youtube, created_at, updated_at], (err, result) => {339 connection.end();340 if (err) cb(err);341 else cb(err, true);342 });343 }344 });345}346function updateUserInfo(id, username, name, email, aboutme, genre, twitter, instagram, youtube, updated_at, cb) {347 let connection = mysql.createConnection(config);348 connection.connect((err) => {349 if (err) {350 cb(err);351 } else {352 let sql = "UPDATE `users` SET `username` = ?, `name` = ?, `email` = ?, `aboutme` = ?, `genre` = ?, `twitter` = ?, `instagram` = ?, `youtube` = ?, `updated_at` = ? WHERE `id`= ?";353 connection.query(sql, [username, name, email, aboutme, genre, twitter, instagram, youtube, updated_at, id], (err, result) => {354 connection.end();355 if (err) cb(err);356 else cb(err, true);357 });358 }359 })360}361function changeAvatar(id, avatar, updated_at, cb) {362 let connection = mysql.createConnection(config);363 connection.connect((err) => {364 if (err) {365 cb(err);366 } else {367 let sql = "UPDATE `users` SET `avatar` = ?, `updated_at` = ? WHERE `id` = ?";368 connection.query(sql, [avatar, updated_at, id], (err, result) => {369 connection.end();370 if (err) cb(err);371 else cb(err, true);372 });373 }374 })375}376function changePassword(id, password, updated_at, cb) {377 let connection = mysql.createConnection(config);378 connection.connect((err) => {379 if (err) {380 cb(err);381 } else {382 let sql = "UPDATE `users` SET `password` = ?, `updated_at` = ? WHERE `id` = ?";383 connection.query(sql, [password, updated_at, id], (err, result) => {384 connection.end();385 if (err) cb(err);386 else cb(err, true);387 });388 }389 })390}391module.exports = {392 getBeats,393 getBeat,394 getBeatsByProducerId,395 getProducers,396 getProducer,397 getProducerByUsername,398 getUserById,399 getGenres,400 getMoods,401 getPlays,402 getSoldBeats,403 createBeat,404 buyBeat,405 registerUser,406 registerPlay,407 loginUser,408 updateUserInfo,409 changeAvatar,410 changePassword...

Full Screen

Full Screen

nvshen.js

Source:nvshen.js Github

copy

Full Screen

1var mongodb = require('./db');2var pic = require('./pic');3var crypto = require('crypto');4var fs = require('fs');5var util = require('util');6function nvshen(girl){7 this.uname = girl.uname;8 this.head = girl.head || "head.png";9 this.gname = girl.gname;10 this.descri = girl.descri || "";11 this.like = girl.like || 0;12 this.plike = girl.plike || 1;13}14nvshen.prototype = {15 add: function(username, callback){16 var ogirl = {17 uname: username,18 head: this.head,19 gname: this.gname,20 descri: this.descri,21 like: this.like,22 plike: this.plike23 }24 mongodb.open(function(err, db){25 if(err){26 return callback(err);27 }28 db.collection('girl', function(err, collection){29 if(err){30 mongodb.close();31 return callback(err);32 }33 collection.ensureIndex('gname', {'unique':'true'});34 collection.insert(ogirl, {safe:true}, function(err, girl){35 mongodb.close();36 callback(err, girl[0]);37 })38 })39 });40 },41 hg:function(tf, callback){42 var self = this;43 var loc = 0;44 if(tf == 'inc' || tf == 'dec'){45 if(tf == 'inc'){46 this.plike *= 1.2;47 this.like = 1 + Math.sqrt(4 - 2 * (this.plike - 2));48 }49 else {50 this.plike *=0.8;51 this.like = 1 + Math.sqrt(4 - 2 * (this.plike - 2));52 }53 mongodb.open(function(err, db){54 if(err){55 return callback(err);56 }57 db.collection('girl', function(err, collection){58 if(err){59 mongodb.close();60 return callback(err);61 }62 collection.update({"uname":self.uname, "gname":self.gname},{$set:{"like":self.like, "plike":self.plike}}, function(err){63 loc = 1;64 callback(err);65 });66 })67 db.collection('silencer', function(err, collection){68 if(err){69 mongodb.close();70 return callback(err);71 }72 collection.update({"uname":self.uname}, {$set:{"op":1}}, function(err){73 while(!loc){}74 mongodb.close();75 callback(err);76 });77 })78 })79 }80 else if(tf == 'hat'){81 mongodb.open(function(err, db){82 if(err){83 return callback(err);84 }85 db.collection('girl', function(err, collection){86 if(err){87 return callback(err);88 }89 collection.remove({"uname":self.uname,"gname":self.gname}, function(err){90 loc = 1;91 callback(err);92 })93 })94 db.collection('silencer', function(err, collection){95 if(err){96 return callback(err);97 }98 collection.update({"uname":self.uname}, {$push:{"hates":self.gname}}, function(err){99 while(!loc){}100 mongodb.close();101 callback(err);102 })103 })104 })105 }106 },107 up:function(odata, callback){108 var self = this;109 var tt = odata.date.toString();110 var md5 = crypto.createHash('md5');111 console.log(odata.name);112 var tname = odata.name.split('.');113 var tn = tname[tname.length-1];114 var stin = self.uname + tt;115 var rdir = md5.update(stin).digest('base64')+'.'+tn;116 var ddir = __dirname+'/../private/'+self.uname+'/'+self.gname+'/'+rdir;117 var tmppath = odata.path;118 119 fs.rename(tmppath, ddir, function(err){120 if(err){121 console.log("rename err");122 return callback(err);123 }124 else{125 //fs.unlink(tmppath, function(err){ 126 // console.log(err);127 //});128 mongodb.open(function(err, db){129 if(err){130 console.log("db open err");131 return callback(err);132 }133 db.collection('gallery', function(err, collection){134 if(err){135 mongodb.close();136 console.log("dbs err");137 return callback(err);138 }139 collection.insert({uname:self.uname, gname:self.gname, descri:odata.descri, date:odata.date, picurl:rdir}, {safe:true}, function(err, doc){140 mongodb.close();141 console.log("ins err");142 console.log(err);143 callback(err, doc);144 })145 })146 })147 } 148 })149 },150 gg:function(callback){151 var self = this;152 mongodb.open(function(err, db){153 if(err){154 callback(err);155 }156 db.collection('gallery', function(err, collection){157 if(err){158 mongodb.close();159 return callback(err);160 }161 collection.find({"uname":self.uname, "gname":self.gname}).toArray(function(err, doc){162 mongodb.close();163 callback(err, doc);164 })165 })166 })167 },168 gp:function(start, callback){169 var self = this;170 mongodb.open(function(err, db){171 if(err){172 callback(err);173 }174 db.collection('speaktoher', function(err,collection){175 if(err){176 mongodb.close();177 return callback(err);178 }179 collection.find({"uname":self.uname,"gname":self.gname}).toArray(function(err, doc){180 mongodb.close();181 callback(err, doc);182 })183 })184 })185 },186 sp:function(odata, callback){187 var self = this;188 mongodb.open(function(err, db){189 if(err){190 return callback(err);191 }192 db.collection('speaktoher', function(err, collection){193 if(err){194 mongodb.close();195 return callback(err);196 }197 collection.insert(odata, {safe:true}, function(err){198 mongodb.close();199 callback(err);200 })201 })202 })203 },204 share:function(callback){205 var self = this;206 mongodb.open(function(err, db){207 if(err){208 return callback(err);209 }210 db.collection('gallery', function(err, collection){211 if(err){212 mongodb.close();213 return callback(err);214 }215 collection.find({"gname":self.gname, "uname":self.uname}).toArray(function(err, doc){216 var BUF_LENGTH = 64 * 1024;217 var _buff = new Buffer(BUF_LENGTH);218 doc.forEach(function(e){219 e["share"]=1;220 console.log(e.picurl);221 var srcFile = __dirname+"/../private/"+self.uname+"/"+self.gname+"/"+e.picurl;222 var destFile = __dirname+"/../public/pubpic/"+e.picurl;223 console.log(srcFile);224 console.log(destFile);225 var fdr = fs.openSync(srcFile, 'r');226 var fdw = fs.openSync(destFile, 'w');227 var bytesRead = 1;228 var pos = 0;229 while (bytesRead > 0) {230 bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos);231 fs.writeSync(fdw, _buff, 0, bytesRead);232 pos += bytesRead;233 }234 fs.closeSync(fdr);235 fs.closeSync(fdw);236 console.log("try to write");237 collection.save(e);238 })239 mongodb.close();240 callback(err);241 })242 })243 })244 }245}246nvshen.exist = function(username, girlname, callback){247 mongodb.open(function(err, db){248 if(err){249 return callback(err);250 }251 db.collection('girl', function(err, collection){252 if(err){253 mongodb.close();254 return callback(err);255 }256 collection.findOne({"uname":username, "gname":girlname}, function(err, doc){257 mongodb.close();258 callback(doc);259 });260 })261 })262}263nvshen.get = function(username, girlname, callback){264 mongodb.open(function(err, db){265 if(err){266 return callback(err);267 }268 db.collection('girl', function(err, collection){269 if(err){270 mongodb.close();271 return callback(err);272 }273 collection.findOne({"uname":username, "gname":girlname}, function(err, doc){274 mongodb.close();275 return callback(err, doc);276 })277 })278 })279}280nvshen.getAll = function(username, callback){281 mongodb.open(function(err, db){282 if(err){283 return callback(err);284 }285 db.collection('girl', function(err, collection){286 if(err){287 mongodb.close();288 return callback(err);289 }290 collection.find({"uname":username}).toArray(function(err, doc){291 mongodb.close();292 //return doc.toArray(callback);293 return callback(err, doc);294 });295 });296 })297}...

Full Screen

Full Screen

db.js

Source:db.js Github

copy

Full Screen

1/**2 * Created by mac on 17/4/26.3 */4var mongo = require('../db');5var ObjectID = require('mongodb').ObjectID;6function userInfo(name) {7 this.name = name;8}9module.exports = userInfo;10userInfo.saveInfor = function(username, password, openid, callback) {11 var user = {12 nameuser: username,13 password: password,14 openid: openid15 }16 mongo.open(function(err, db) {17 if(err) {18 return callback(err);19 }20 db.collection("users", function(err, collection) {21 if(err) {22 return callback(err)23 }24 collection.save(user, function(err) {25 if(err) {26 return callback(err);27 }28 var res = "关联成功"29 return callback(null, res);30 })31 })32 })33}34userInfo.checkInfo = function(openid, callback) {35 mongo.open(function (err, db) {36 if(err) {37 return callback(err)38 }39 db.collection("users", function(err, collection) {40 if(err) {41 return callback(err);42 }43 var query = {}44 if(openid) {45 query.openid = openid46 }47 collection.findOne(query, function(err, docs) {48 if(err) {49 return callback(err);50 }51 return callback(null, docs);52 })53 })54 })55}56userInfo.saveCompany = function(username, place, manager, callback) {57 var company = {58 name: username,59 //place: place,60 //managers: manager61 }62 console.log(username)63 mongo.open(function(err, db) {64 if(err) {65 return callback(err);66 }67 db.collection("CompanyList", function(err, collection) {68 if(err) {69 return callback(err)70 }71 //var query = {}72 //if(username) {73 // query.name = username74 //}75 collection.save(company, function(err) {76 if(err) {77 return callback(err)78 }79 return callback(null)80 })81 })82 })83}84userInfo.saveNews = function(time, topic, picture ,content, callback) {85 var News = {86 time: time,87 topic: topic,88 picture: picture,89 content: content90 }91 //console.log(username)92 mongo.open(function(err, db) {93 if(err) {94 return callback(err);95 }96 db.collection("News", function(err, collection) {97 if(err) {98 return callback(err)99 }100 collection.save(News, function(err) {101 if(err) {102 return callback(err)103 }104 return callback(null)105 })106 })107 })108}109userInfo.savePay = function(data, callback) {110 var pay = {111 openid: data.openid,112 out_trade_no: data.out_trade_no,113 }114 //console.log(username)115 mongo.open(function(err, db) {116 if(err) {117 return callback(err);118 }119 db.collection("pays", function(err, collection) {120 if(err) {121 return callback(err)122 }123 collection.save(pay, function(err) {124 if(err) {125 return callback(err)126 }127 return callback(null)128 })129 })130 })131}132userInfo.findCompany = function(callback) {133 //console.log(username)134 mongo.open(function(err, db) {135 if(err) {136 return callback(err);137 }138 db.collection("CompanyList", function(err, collection) {139 if(err) {140 return callback(err)141 }142 //var query = {}143 //if(username) {144 // query.name = username145 //}146 collection.find({}).toArray(function(err, docs){147 if(err) {148 return callback(err)149 }150 return callback(null, docs)151 })152 })153 })154}155userInfo.deletCompany = function(_id ,callback) {156 var relId = ObjectID(_id)157 console.log(relId)158 mongo.open(function(err, db) {159 if(err) {160 return callback(err);161 }162 db.collection("CompanyList", function(err, collection) {163 if(err) {164 return callback(err)165 }166 //var query = {}167 //if(username) {168 // query.name = username169 //}170 collection.remove({_id: relId}, function(err) {171 if(err) {172 return callback(err)173 }174 return callback(null)175 })176 })177 })178}179userInfo.findCheck = function(callback) {180 //console.log(username)181 mongo.open(function(err, db) {182 if(err) {183 return callback(err);184 }185 db.collection("Business", function(err, collection) {186 if(err) {187 return callback(err)188 }189 //var query = {}190 //if(username) {191 // query.name = username192 //}193 collection.find({}).toArray(function(err, docs){194 if(err) {195 return callback(err)196 }197 return callback(null, docs)198 })199 })200 })201}202userInfo.findCheckIndex = function(openid ,callback) {203 mongo.open(function(err, db) {204 if(err) {205 return callback(err);206 }207 db.collection("Business", function(err, collection) {208 if(err) {209 return callback(err)210 }211 var query = {}212 if(openid) {213 query.priveteId = openid214 }215 collection.findOne(query, function(err, docs) {216 if(err) {217 return callback(err)218 }219 return callback(null, docs.materialInfor);220 })221 })222 })223}224userInfo.checkPay = function(data ,callback) {225 var openid = data.openid;226 var out_trade_no = data.out_trade_no227 mongo.open(function(err, db) {228 if(err) {229 return callback(err);230 }231 db.collection("Business", function(err, collection) {232 if(err) {233 return callback(err)234 }235 collection.update({"priveteId":openid , materialInfor:{$elemMatch:{out_trade_no:out_trade_no}}}, {$set:{"materialInfor.$.isCheck":"true"}},{w:0},function(err) {236 if(err) {237 return callback(err)238 }239 return callback(null);240 })241 })242 })243}244userInfo.checkIsPay = function(data ,callback) {245 var openid = data.openid;246 var out_trade_no = data.out_trade_no247 mongo.open(function(err, db) {248 if(err) {249 return callback(err);250 }251 db.collection("Business", function(err, collection) {252 if(err) {253 return callback(err)254 }255 collection.update({"priveteId":openid , materialInfor:{$elemMatch:{out_trade_no:out_trade_no}}}, {$set:{"materialInfor.$.isPay":"true"}},{w:0},function(err) {256 if(err) {257 return callback(err)258 }259 return callback(null);260 })261 })262 })...

Full Screen

Full Screen

test-child-process-spawnsync-validation-errors.js

Source:test-child-process-spawnsync-validation-errors.js Github

copy

Full Screen

1'use strict';2const common = require('../common');3const assert = require('assert');4const spawnSync = require('child_process').spawnSync;5const signals = process.binding('constants').os.signals;6function pass(option, value) {7 // Run the command with the specified option. Since it's not a real command,8 // spawnSync() should run successfully but return an ENOENT error.9 const child = spawnSync('not_a_real_command', { [option]: value });10 assert.strictEqual(child.error.code, 'ENOENT');11}12function fail(option, value, message) {13 assert.throws(() => {14 spawnSync('not_a_real_command', { [option]: value });15 }, message);16}17{18 // Validate the cwd option19 const err = /^TypeError: "cwd" must be a string$/;20 pass('cwd', undefined);21 pass('cwd', null);22 pass('cwd', __dirname);23 fail('cwd', 0, err);24 fail('cwd', 1, err);25 fail('cwd', true, err);26 fail('cwd', false, err);27 fail('cwd', [], err);28 fail('cwd', {}, err);29 fail('cwd', common.mustNotCall(), err);30}31{32 // Validate the detached option33 const err = /^TypeError: "detached" must be a boolean$/;34 pass('detached', undefined);35 pass('detached', null);36 pass('detached', true);37 pass('detached', false);38 fail('detached', 0, err);39 fail('detached', 1, err);40 fail('detached', __dirname, err);41 fail('detached', [], err);42 fail('detached', {}, err);43 fail('detached', common.mustNotCall(), err);44}45if (!common.isWindows) {46 {47 // Validate the uid option48 if (process.getuid() !== 0) {49 const err = /^TypeError: "uid" must be an integer$/;50 pass('uid', undefined);51 pass('uid', null);52 pass('uid', process.getuid());53 fail('uid', __dirname, err);54 fail('uid', true, err);55 fail('uid', false, err);56 fail('uid', [], err);57 fail('uid', {}, err);58 fail('uid', common.mustNotCall(), err);59 fail('uid', NaN, err);60 fail('uid', Infinity, err);61 fail('uid', 3.1, err);62 fail('uid', -3.1, err);63 }64 }65 {66 // Validate the gid option67 if (process.getgid() !== 0) {68 const err = /^TypeError: "gid" must be an integer$/;69 pass('gid', undefined);70 pass('gid', null);71 pass('gid', process.getgid());72 fail('gid', __dirname, err);73 fail('gid', true, err);74 fail('gid', false, err);75 fail('gid', [], err);76 fail('gid', {}, err);77 fail('gid', common.mustNotCall(), err);78 fail('gid', NaN, err);79 fail('gid', Infinity, err);80 fail('gid', 3.1, err);81 fail('gid', -3.1, err);82 }83 }84}85{86 // Validate the shell option87 const err = /^TypeError: "shell" must be a boolean or string$/;88 pass('shell', undefined);89 pass('shell', null);90 pass('shell', false);91 fail('shell', 0, err);92 fail('shell', 1, err);93 fail('shell', [], err);94 fail('shell', {}, err);95 fail('shell', common.mustNotCall(), err);96}97{98 // Validate the argv0 option99 const err = /^TypeError: "argv0" must be a string$/;100 pass('argv0', undefined);101 pass('argv0', null);102 pass('argv0', 'myArgv0');103 fail('argv0', 0, err);104 fail('argv0', 1, err);105 fail('argv0', true, err);106 fail('argv0', false, err);107 fail('argv0', [], err);108 fail('argv0', {}, err);109 fail('argv0', common.mustNotCall(), err);110}111{112 // Validate the windowsVerbatimArguments option113 const err = /^TypeError: "windowsVerbatimArguments" must be a boolean$/;114 pass('windowsVerbatimArguments', undefined);115 pass('windowsVerbatimArguments', null);116 pass('windowsVerbatimArguments', true);117 pass('windowsVerbatimArguments', false);118 fail('windowsVerbatimArguments', 0, err);119 fail('windowsVerbatimArguments', 1, err);120 fail('windowsVerbatimArguments', __dirname, err);121 fail('windowsVerbatimArguments', [], err);122 fail('windowsVerbatimArguments', {}, err);123 fail('windowsVerbatimArguments', common.mustNotCall(), err);124}125{126 // Validate the timeout option127 const err = /^TypeError: "timeout" must be an unsigned integer$/;128 pass('timeout', undefined);129 pass('timeout', null);130 pass('timeout', 1);131 pass('timeout', 0);132 fail('timeout', -1, err);133 fail('timeout', true, err);134 fail('timeout', false, err);135 fail('timeout', __dirname, err);136 fail('timeout', [], err);137 fail('timeout', {}, err);138 fail('timeout', common.mustNotCall(), err);139 fail('timeout', NaN, err);140 fail('timeout', Infinity, err);141 fail('timeout', 3.1, err);142 fail('timeout', -3.1, err);143}144{145 // Validate the maxBuffer option146 const err = /^TypeError: "maxBuffer" must be a positive number$/;147 pass('maxBuffer', undefined);148 pass('maxBuffer', null);149 pass('maxBuffer', 1);150 pass('maxBuffer', 0);151 pass('maxBuffer', Infinity);152 pass('maxBuffer', 3.14);153 fail('maxBuffer', -1, err);154 fail('maxBuffer', NaN, err);155 fail('maxBuffer', -Infinity, err);156 fail('maxBuffer', true, err);157 fail('maxBuffer', false, err);158 fail('maxBuffer', __dirname, err);159 fail('maxBuffer', [], err);160 fail('maxBuffer', {}, err);161 fail('maxBuffer', common.mustNotCall(), err);162}163{164 // Validate the killSignal option165 const typeErr = /^TypeError: "killSignal" must be a string or number$/;166 const unknownSignalErr =167 common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL' }, 17);168 pass('killSignal', undefined);169 pass('killSignal', null);170 pass('killSignal', 'SIGKILL');171 fail('killSignal', 'SIGNOTAVALIDSIGNALNAME', unknownSignalErr);172 fail('killSignal', true, typeErr);173 fail('killSignal', false, typeErr);174 fail('killSignal', [], typeErr);175 fail('killSignal', {}, typeErr);176 fail('killSignal', common.mustNotCall(), typeErr);177 // Invalid signal names and numbers should fail178 fail('killSignal', 500, unknownSignalErr);179 fail('killSignal', 0, unknownSignalErr);180 fail('killSignal', -200, unknownSignalErr);181 fail('killSignal', 3.14, unknownSignalErr);182 Object.getOwnPropertyNames(Object.prototype).forEach((property) => {183 fail('killSignal', property, unknownSignalErr);184 });185 // Valid signal names and numbers should pass186 for (const signalName in signals) {187 pass('killSignal', signals[signalName]);188 pass('killSignal', signalName);189 pass('killSignal', signalName.toLowerCase());190 }...

Full Screen

Full Screen

handle-callback-err.js

Source:handle-callback-err.js Github

copy

Full Screen

1/**2 * @fileoverview Tests for missing-err rule.3 * @author Jamund Ferguson4 */5"use strict";6//------------------------------------------------------------------------------7// Requirements8//------------------------------------------------------------------------------9const rule = require("../../../lib/rules/handle-callback-err"),10 RuleTester = require("../../../lib/testers/rule-tester");11//------------------------------------------------------------------------------12// Tests13//------------------------------------------------------------------------------14const ruleTester = new RuleTester();15const expectedErrorMessage = "Expected error to be handled.";16const expectedFunctionDeclarationError = { message: expectedErrorMessage, type: "FunctionDeclaration" };17const expectedFunctionExpressionError = { message: expectedErrorMessage, type: "FunctionExpression" };18ruleTester.run("handle-callback-err", rule, {19 valid: [20 "function test(error) {}",21 "function test(err) {console.log(err);}",22 "function test(err, data) {if(err){ data = 'ERROR';}}",23 "var test = function(err) {console.log(err);};",24 "var test = function(err) {if(err){/* do nothing */}};",25 "var test = function(err) {if(!err){doSomethingHere();}else{};}",26 "var test = function(err, data) {if(!err) { good(); } else { bad(); }}",27 "try { } catch(err) {}",28 "getData(function(err, data) {if (err) {}getMoreDataWith(data, function(err, moreData) {if (err) {}getEvenMoreDataWith(moreData, function(err, allOfTheThings) {if (err) {}});});});",29 "var test = function(err) {if(! err){doSomethingHere();}};",30 "function test(err, data) {if (data) {doSomething(function(err) {console.error(err);});} else if (err) {console.log(err);}}",31 "function handler(err, data) {if (data) {doSomethingWith(data);} else if (err) {console.log(err);}}",32 "function handler(err) {logThisAction(function(err) {if (err) {}}); console.log(err);}",33 "function userHandler(err) {process.nextTick(function() {if (err) {}})}",34 "function help() { function userHandler(err) {function tester() { err; process.nextTick(function() { err; }); } } }",35 "function help(done) { var err = new Error('error'); done(); }",36 { code: "var test = err => err;", parserOptions: { ecmaVersion: 6 } },37 { code: "var test = err => !err;", parserOptions: { ecmaVersion: 6 } },38 { code: "var test = err => err.message;", parserOptions: { ecmaVersion: 6 } },39 { code: "var test = function(error) {if(error){/* do nothing */}};", options: ["error"] },40 { code: "var test = (error) => {if(error){/* do nothing */}};", options: ["error"], parserOptions: { ecmaVersion: 6 } },41 { code: "var test = function(error) {if(! error){doSomethingHere();}};", options: ["error"] },42 { code: "var test = function(err) { console.log(err); };", options: ["^(err|error)$"] },43 { code: "var test = function(error) { console.log(error); };", options: ["^(err|error)$"] },44 { code: "var test = function(anyError) { console.log(anyError); };", options: ["^.+Error$"] },45 { code: "var test = function(any_error) { console.log(anyError); };", options: ["^.+Error$"] },46 { code: "var test = function(any_error) { console.log(any_error); };", options: ["^.+(e|E)rror$"] }47 ],48 invalid: [49 { code: "function test(err) {}", errors: [expectedFunctionDeclarationError] },50 { code: "function test(err, data) {}", errors: [expectedFunctionDeclarationError] },51 { code: "function test(err) {errorLookingWord();}", errors: [expectedFunctionDeclarationError] },52 { code: "function test(err) {try{} catch(err) {}}", errors: [expectedFunctionDeclarationError] },53 { code: "function test(err, callback) { foo(function(err, callback) {}); }", errors: [expectedFunctionDeclarationError, expectedFunctionExpressionError] },54 { code: "var test = (err) => {};", parserOptions: { ecmaVersion: 6 }, errors: [{ message: expectedErrorMessage, type: "ArrowFunctionExpression" }] },55 { code: "var test = function(err) {};", errors: [expectedFunctionExpressionError] },56 { code: "var test = function test(err, data) {};", errors: [expectedFunctionExpressionError] },57 { code: "var test = function test(err) {/* if(err){} */};", errors: [expectedFunctionExpressionError] },58 { code: "function test(err) {doSomethingHere(function(err){console.log(err);})}", errors: [expectedFunctionDeclarationError] },59 { code: "function test(error) {}", options: ["error"], errors: [expectedFunctionDeclarationError] },60 { code: "getData(function(err, data) {getMoreDataWith(data, function(err, moreData) {if (err) {}getEvenMoreDataWith(moreData, function(err, allOfTheThings) {if (err) {}});}); });", errors: [expectedFunctionExpressionError] },61 { code: "getData(function(err, data) {getMoreDataWith(data, function(err, moreData) {getEvenMoreDataWith(moreData, function(err, allOfTheThings) {if (err) {}});}); });", errors: [expectedFunctionExpressionError, expectedFunctionExpressionError] },62 { code: "function userHandler(err) {logThisAction(function(err) {if (err) { console.log(err); } })}", errors: [expectedFunctionDeclarationError] },63 { code: "function help() { function userHandler(err) {function tester(err) { err; process.nextTick(function() { err; }); } } }", errors: [expectedFunctionDeclarationError] },64 { code: "var test = function(anyError) { console.log(otherError); };", options: ["^.+Error$"], errors: [expectedFunctionExpressionError] },65 { code: "var test = function(anyError) { };", options: ["^.+Error$"], errors: [expectedFunctionExpressionError] },66 { code: "var test = function(err) { console.log(error); };", options: ["^(err|error)$"], errors: [expectedFunctionExpressionError] }67 ]...

Full Screen

Full Screen

test-fs-error-messages.js

Source:test-fs-error-messages.js Github

copy

Full Screen

1'use strict';2const common = require('../common');3const assert = require('assert');4const path = require('path');5const fs = require('fs');6const fn = path.join(common.fixturesDir, 'non-existent');7const existingFile = path.join(common.fixturesDir, 'exit.js');8const existingFile2 = path.join(common.fixturesDir, 'create-file.js');9const existingDir = path.join(common.fixturesDir, 'empty');10const existingDir2 = path.join(common.fixturesDir, 'keys');11// ASYNC_CALL12fs.stat(fn, function(err) {13 assert.equal(fn, err.path);14 assert.ok(0 <= err.message.indexOf(fn));15});16fs.lstat(fn, function(err) {17 assert.ok(0 <= err.message.indexOf(fn));18});19fs.readlink(fn, function(err) {20 assert.ok(0 <= err.message.indexOf(fn));21});22fs.link(fn, 'foo', function(err) {23 assert.ok(0 <= err.message.indexOf(fn));24});25fs.link(existingFile, existingFile2, function(err) {26 assert.ok(0 <= err.message.indexOf(existingFile));27 assert.ok(0 <= err.message.indexOf(existingFile2));28});29fs.symlink(existingFile, existingFile2, function(err) {30 assert.ok(0 <= err.message.indexOf(existingFile));31 assert.ok(0 <= err.message.indexOf(existingFile2));32});33fs.unlink(fn, function(err) {34 assert.ok(0 <= err.message.indexOf(fn));35});36fs.rename(fn, 'foo', function(err) {37 assert.ok(0 <= err.message.indexOf(fn));38});39fs.rename(existingDir, existingDir2, function(err) {40 assert.ok(0 <= err.message.indexOf(existingDir));41 assert.ok(0 <= err.message.indexOf(existingDir2));42});43fs.rmdir(fn, function(err) {44 assert.ok(0 <= err.message.indexOf(fn));45});46fs.mkdir(existingFile, 0o666, function(err) {47 assert.ok(0 <= err.message.indexOf(existingFile));48});49fs.rmdir(existingFile, function(err) {50 assert.ok(0 <= err.message.indexOf(existingFile));51});52fs.chmod(fn, 0o666, function(err) {53 assert.ok(0 <= err.message.indexOf(fn));54});55fs.open(fn, 'r', 0o666, function(err) {56 assert.ok(0 <= err.message.indexOf(fn));57});58fs.readFile(fn, function(err) {59 assert.ok(0 <= err.message.indexOf(fn));60});61// Sync62const errors = [];63let expected = 0;64try {65 ++expected;66 fs.statSync(fn);67} catch (err) {68 errors.push('stat');69 assert.ok(0 <= err.message.indexOf(fn));70}71try {72 ++expected;73 fs.mkdirSync(existingFile, 0o666);74} catch (err) {75 errors.push('mkdir');76 assert.ok(0 <= err.message.indexOf(existingFile));77}78try {79 ++expected;80 fs.chmodSync(fn, 0o666);81} catch (err) {82 errors.push('chmod');83 assert.ok(0 <= err.message.indexOf(fn));84}85try {86 ++expected;87 fs.lstatSync(fn);88} catch (err) {89 errors.push('lstat');90 assert.ok(0 <= err.message.indexOf(fn));91}92try {93 ++expected;94 fs.readlinkSync(fn);95} catch (err) {96 errors.push('readlink');97 assert.ok(0 <= err.message.indexOf(fn));98}99try {100 ++expected;101 fs.linkSync(fn, 'foo');102} catch (err) {103 errors.push('link');104 assert.ok(0 <= err.message.indexOf(fn));105}106try {107 ++expected;108 fs.linkSync(existingFile, existingFile2);109} catch (err) {110 errors.push('link');111 assert.ok(0 <= err.message.indexOf(existingFile));112 assert.ok(0 <= err.message.indexOf(existingFile2));113}114try {115 ++expected;116 fs.symlinkSync(existingFile, existingFile2);117} catch (err) {118 errors.push('symlink');119 assert.ok(0 <= err.message.indexOf(existingFile));120 assert.ok(0 <= err.message.indexOf(existingFile2));121}122try {123 ++expected;124 fs.unlinkSync(fn);125} catch (err) {126 errors.push('unlink');127 assert.ok(0 <= err.message.indexOf(fn));128}129try {130 ++expected;131 fs.rmdirSync(fn);132} catch (err) {133 errors.push('rmdir');134 assert.ok(0 <= err.message.indexOf(fn));135}136try {137 ++expected;138 fs.rmdirSync(existingFile);139} catch (err) {140 errors.push('rmdir');141 assert.ok(0 <= err.message.indexOf(existingFile));142}143try {144 ++expected;145 fs.openSync(fn, 'r');146} catch (err) {147 errors.push('opens');148 assert.ok(0 <= err.message.indexOf(fn));149}150try {151 ++expected;152 fs.renameSync(fn, 'foo');153} catch (err) {154 errors.push('rename');155 assert.ok(0 <= err.message.indexOf(fn));156}157try {158 ++expected;159 fs.renameSync(existingDir, existingDir2);160} catch (err) {161 errors.push('rename');162 assert.ok(0 <= err.message.indexOf(existingDir));163 assert.ok(0 <= err.message.indexOf(existingDir2));164}165try {166 ++expected;167 fs.readdirSync(fn);168} catch (err) {169 errors.push('readdir');170 assert.ok(0 <= err.message.indexOf(fn));171}172process.on('exit', function() {173 assert.equal(expected, errors.length,174 'Test fs sync exceptions raised, got ' + errors.length +175 ' expected ' + expected);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var logger = require('./lib/bestLogger');2logger.err('This is an error message');3var logger = require('./lib/bestLogger');4logger.log('This is a log message');5var logger = require('./lib/bestLogger');6logger.warn('This is a warning message');7var logger = require('./lib/bestLogger');8logger.info('This is an info message');9var logger = require('./lib/bestLogger');10logger.debug('This is a debug message');11var logger = require('./lib/bestLogger');12logger.trace('This is a trace message');13var logger = require('./lib/bestLogger');14logger.err('This is an error message');15logger.log('This is a log message');16logger.warn('This is a warning message');17logger.info('This is an info message');18logger.debug('This is a debug message');19logger.trace('This is a trace message');20var logger = require('./lib/bestLogger');21logger.setLevel('error');22logger.err('This is an error message');23logger.log('This is a log message');24logger.warn('This is a warning message');25logger.info('This is an info message');26logger.debug('This is a debug message');27logger.trace('This is a trace message');28logger.setLevel('log');29logger.err('This is an error message');30logger.log('This is a log message');31logger.warn('This is a warning message');32logger.info('This is an info message');33logger.debug('This is a debug message');34logger.trace('This is a trace message');35logger.setLevel('warn');36logger.err('This is an error message');37logger.log('This is a log message');38logger.warn('This is a warning message');39logger.info('This is an info message');40logger.debug('This is a debug message');41logger.trace('This is a trace message');42logger.setLevel('info');43logger.err('This is

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPracticeError = require('./lib/BestPracticeError');2var err = new BestPracticeError('Test error message');3err.err();4var BestPracticeError = require('./lib/BestPracticeError');5var err = new BestPracticeError('Test error message');6err.err();7var BestPracticeError = require('./lib/BestPracticeError');8var err = new BestPracticeError('Test error message');9err.err();10var BestPracticeError = require('./lib/BestPracticeError');11var err = new BestPracticeError('Test error message');12err.err();13var BestPracticeError = require('./lib/BestPracticeError');14var err = new BestPracticeError('Test error message');15err.err();16var BestPracticeError = require('./lib/BestPracticeError');17var err = new BestPracticeError('Test error message');18err.err();19var BestPracticeError = require('./lib/BestPracticeError');20var err = new BestPracticeError('Test error message');21err.err();22var BestPracticeError = require('./lib/BestPracticeError');23var err = new BestPracticeError('Test error message');24err.err();25var BestPracticeError = require('./lib/BestPracticeError');26var err = new BestPracticeError('Test error message');27err.err();28var BestPracticeError = require('./lib/BestPracticeError');29var err = new BestPracticeError('Test error message');30err.err();31var BestPracticeError = require('./lib/BestPracticeError');32var err = new BestPracticeError('Test error message');

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestMovies = require('./bestmovies');2var movies = BestMovies();3movies.err('Error: Something went wrong');4module.exports = function() {5 var err = function(msg) {6 console.log(msg);7 };8 return {9 };10};11var BestMovies = require('./bestmovies');12var movies = BestMovies();13movies.err('Error: Something went wrong');14module.exports = function() {15 var err = function(msg) {16 console.log(msg);17 };18 return {19 };20};21var BestMovies = require('./bestmovies');22var movies = BestMovies();23movies.err('Error: Something went wrong');24module.exports = function() {25 var err = function(msg) {26 console.log(msg);27 };28 return {29 };30};31var BestMovies = require('./bestmovies');32var movies = BestMovies();33movies.err('Error: Something went wrong');34module.exports = function() {35 var err = function(msg) {36 console.log(msg);37 };38 return {39 };40};41var BestMovies = require('./bestmovies');42var movies = BestMovies();43movies.err('Error: Something went wrong');44module.exports = function() {45 var err = function(msg) {46 console.log(msg);47 };48 return {49 };50};51var BestMovies = require('./bestmovies');52var movies = BestMovies();53movies.err('Error: Something went wrong');54module.exports = function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestError = require('./bestError');2try {3 throw new BestError('This is the best error ever!');4} catch (err) {5 console.log('Error message:', err.message);6 console.log('Error name:', err.name);7 console.log('Error stack:', err.stack);8 console.log('Error code:', err.code);9 console.log('Error method:', err.err());10}11class BestError extends Error {12 constructor(message) {13 super(message);14 this.name = 'BestError';15 this.code = 500;16 }17 err() {18 return {19 }20 }21}22module.exports = BestError;23 at Object.<anonymous> (test4.js:5:9)24 at Module._compile (internal/modules/cjs/loader.js:1200:30)25 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)26 at Module.load (internal/modules/cjs/loader.js:1050:32)27 at Function.Module._load (internal/modules/cjs/loader.js:938:14)28 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)29Error method: { name: 'BestError', message: 'This is the best error ever!', code: 500 }30const MyError = require('./myError');31try {32 throw new MyError('This is a custom error!');33} catch (err) {34 console.log('Error message:', err.message);35 console.log('Error name:', err.name);36 console.log('Error stack:', err.stack);37}

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFriend = require('./BestFriend');2var myBestFriend = new BestFriend("John", "Doe", 23);3myBestFriend.err();4var BestFriend = require('./BestFriend');5var myBestFriend = new BestFriend("John", "Doe", 23);6myBestFriend.err();7var BestFriend = function(first, last, age){8 this.first = first;9 this.last = last;10 this.age = age;11}12BestFriend.prototype.err = function(){13 console.log("I am " + this.first + " " + this.last + " and I am " + this.age + " years old.");14}15module.exports = BestFriend;16module.exports = BestFriend;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestError = require('./besterror');2var err = new BestError('This is a test');3console.log(err.message);4console.log(err.name);5console.log(err.stack);6console.log(err.toString());7console.log(err);8var BestError = require('./besterror');9var err = new BestError('This is a test');10console.log(err.message);11console.log(err.name);12console.log(err.stack);13console.log(err.toString());14console.log(err);15var BestError = require('./besterror');16var err = new BestError('This is a test');17console.log(err.message);18console.log(err.name);19console.log(err.stack);20console.log(err.toString());

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestLibrary = require("bestlibrary");2var bl = new BestLibrary();3bl.err("test4.js");4var BestLibrary = require("bestlibrary");5var bl = new BestLibrary();6bl.err("test5.js");7var BestLibrary = require("bestlibrary");8var bl = new BestLibrary();9bl.err("test6.js");10var BestLibrary = require("bestlibrary");11var bl = new BestLibrary();12bl.err("test7.js");13var BestLibrary = require("bestlibrary");14var bl = new BestLibrary();15bl.err("test8.js");16var BestLibrary = require("bestlibrary");17var bl = new BestLibrary();18bl.err("test9.js");19var BestLibrary = require("bestlibrary");20var bl = new BestLibrary();21bl.err("test10.js");22var BestLibrary = require("bestlibrary");23var bl = new BestLibrary();24bl.err("test11.js");25var BestLibrary = require("bestlibrary");26var bl = new BestLibrary();27bl.err("test12.js");28var BestLibrary = require("bestlibrary");29var bl = new BestLibrary();30bl.err("test13.js");31var BestLibrary = require("bestlibrary");

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestError = require('./besterror');2var besterror = new BestError('test4.js');3var err = besterror.err;4err('This is an error message');5var util = require('util');6function BestError(filename) {7 this.filename = filename;8}9BestError.prototype.err = function(msg) {10 console.log(this.filename + ': ' + msg);11}12module.exports = BestError;

Full Screen

Using AI Code Generation

copy

Full Screen

1function test4() {2 var dict = ["cat", "dog", "rabbit", "rat", "bird"];3 var word = "rabit";4 var bm = new BestMatch(word, dict);5 var best = bm.err();6 console.log("best match for " + word + " is " + best);7}8function test5() {9 var dict = ["cat", "dog", "rabbit", "rat", "bird"];10 var word = "rabit";11 var bm = new BestMatch(word, dict);12 var best = bm.err();13 console.log("best match for " + word + " is " + best);14}15function test6() {16 var dict = ["cat", "dog", "rabbit", "rat", "bird"];17 var word = "rabit";18 var bm = new BestMatch(word, dict);19 var best = bm.err();20 console.log("best match for " + word + " is " + best);21}22function test7() {23 var dict = ["cat", "dog", "rabbit", "rat", "bird"];24 var word = "rabit";25 var bm = new BestMatch(word, dict);26 var best = bm.err();27 console.log("best match for " + word + " is " + best);28}29function test8() {30 var dict = ["cat", "dog", "rabbit", "rat", "bird"];31 var word = "rabit";32 var bm = new BestMatch(word, dict);33 var best = bm.err();34 console.log("best match for " + word + " is " + best);35}

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

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