Best JavaScript code snippet using ava
transport.js
Source:transport.js
1/* Copyright (c) 2013-2015 Richard Rodger & other contributors, MIT License */2/* jshint node:true, asi:true, eqnull:true */3'use strict'4// Load modules5var LruCache = require('lru-cache')6var Tcp = require('./lib/tcp')7var TransportUtil = require('./lib/transport-utils.js')8var Http = require('./lib/http')9// Declare internals10var internals = {11 defaults: {12 msgprefix: 'seneca_',13 callmax: 1111,14 msgidlen: 12,15 warn: {16 unknown_message_id: true,17 invalid_kind: true,18 invalid_origin: true,19 no_message_id: true,20 message_loop: true,21 own_message: true,22 },23 check: {24 message_loop: true,25 own_message: true,26 },27 web: {28 type: 'web',29 port: 10101,30 host: '0.0.0.0',31 path: '/act',32 protocol: 'http',33 timeout: 5555,34 max_listen_attempts: 11,35 attempt_delay: 222,36 serverOptions: {},37 },38 tcp: {39 type: 'tcp',40 host: '0.0.0.0',41 port: 10201,42 timeout: 5555,43 },44 },45 plugin: 'transport',46}47module.exports = function transport(options) {48 var seneca = this49 var settings = seneca.util.deepextend(internals.defaults, options)50 var callmap = new LruCache({ max: settings.callmax })51 var transportUtil = new TransportUtil({52 callmap: callmap,53 seneca: seneca,54 options: settings,55 })56 seneca.add(57 { role: internals.plugin, cmd: 'inflight' },58 internals.inflight(callmap)59 )60 seneca.add({ role: internals.plugin, cmd: 'listen' }, internals.listen)61 seneca.add({ role: internals.plugin, cmd: 'client' }, internals.client)62 seneca.add(63 { role: internals.plugin, hook: 'listen', type: 'tcp' },64 Tcp.listen(settings, transportUtil)65 )66 seneca.add(67 { role: internals.plugin, hook: 'client', type: 'tcp' },68 Tcp.client(settings, transportUtil)69 )70 seneca.add(71 { role: internals.plugin, hook: 'listen', type: 'web' },72 Http.listen(settings, transportUtil)73 )74 seneca.add(75 { role: internals.plugin, hook: 'client', type: 'web' },76 Http.client(settings, transportUtil)77 )78 // Aliases.79 seneca.add(80 { role: internals.plugin, hook: 'listen', type: 'http' },81 Http.listen(settings, transportUtil)82 )83 seneca.add(84 { role: internals.plugin, hook: 'client', type: 'http' },85 Http.client(settings, transportUtil)86 )87 // Legacy API.88 seneca.add(89 { role: internals.plugin, hook: 'listen', type: 'direct' },90 Http.listen(settings, transportUtil)91 )92 seneca.add(93 { role: internals.plugin, hook: 'client', type: 'direct' },94 Http.client(settings, transportUtil)95 )96 return {97 name: internals.plugin,98 exportmap: { utils: transportUtil },99 options: settings,100 }101}102module.exports.preload = function () {103 var seneca = this104 var meta = {105 name: internals.plugin,106 exportmap: {107 utils: function () {108 var transportUtil = seneca.export(internals.plugin).utils109 if (transportUtil !== meta.exportmap.utils) {110 transportUtil.apply(this, arguments)111 }112 },113 },114 }115 return meta116}117internals.inflight = function (callmap) {118 return function (args, callback) {119 var inflight = {}120 callmap.forEach(function (val, key) {121 inflight[key] = val122 })123 callback(null, inflight)124 }125}126internals.listen = function (args, callback) {127 var seneca = this128 var config = Object.assign({}, args.config, {129 role: internals.plugin,130 hook: 'listen',131 })132 //var listen_args = seneca.util.clean(_.omit(config, 'cmd'))133 var listen_args = seneca.util.clean(config)134 delete config.cmd135 var legacyError = internals.legacyError(seneca, listen_args.type)136 if (legacyError) {137 return callback(legacyError)138 }139 seneca.act(listen_args, callback)140}141internals.client = function (args, callback) {142 var seneca = this143 var config = Object.assign({}, args.config, {144 role: internals.plugin,145 hook: 'client',146 })147 //var client_args = seneca.util.clean(_.omit(config, 'cmd'))148 var client_args = seneca.util.clean(config)149 delete config.cmd150 var legacyError = internals.legacyError(seneca, client_args.type)151 if (legacyError) {152 return callback(legacyError)153 }154 seneca.act(client_args, callback)155}156internals.legacyError = function (seneca, type) {157 if (type === 'pubsub') {158 return seneca.fail('plugin-needed', { name: 'seneca-redis-transport' })159 }160 if (type === 'queue') {161 return seneca.fail('plugin-needed', { name: 'seneca-beanstalkd-transport' })162 }...
error.js
Source:error.js
1/**2 * ÐазовÑй клаÑÑ Ð¾Ñибок3 */4class LegacyError extends Error {5 constructor( message ) {6 super( message );7 this.name = this.constructor.name;8 this.message = `${ this.name }: ${ this.message }`;9 }10}11/**12 * ÐлаÑÑ Ð¾Ñибок оÑвеÑа API13 */14export class ApiResponseError extends LegacyError {}15/**16 * ÐлаÑÑ Ð¾Ñибок ÑеÑевÑÑ
запÑоÑов17 */18export class RequestError extends LegacyError {19 constructor( statusCode, statusText ) {20 super( `${ statusCode } ${ statusText }` );21 this.statusCode = statusCode;22 this.statusText = statusText;23 }24}25/**26 * ÐлаÑÑ Ð¾Ñибок валидаÑии27 */28export class ValidationError extends LegacyError {}29/**30 * УÑоÑнÑÑÑий клаÑÑ Ð¾Ñибок валидаÑии: ÐекоÑÑекÑнÑй Ñип31 */32export class TypeValidationError extends ValidationError {33 constructor( expected, got ) {34 super( `Expected value with type "${ expected }", got - "${ got }"` );35 this.expected = expected;36 this.got = got;37 }...
Using AI Code Generation
1const test = require('ava');2const LegacyError = require('ava/lib/test').LegacyError;3test('LegacyError', t => {4 t.throws(() => {5 throw new LegacyError(new Error('foo'));6 }, 'foo');7});
Using AI Code Generation
1var LegacyError = require('error').LegacyError;2var MyError = LegacyError.extend('MyError', {3 constructor: function MyError(message, code) {4 LegacyError.call(this, message);5 this.code = code;6 }7});8var err = new MyError('something bad', 500);9console.log(err.message); va something bad10var NroError =rrequire('error').N wE= rr;11vaeqMyErrur = NewError.extend('MyError', {12 constructor: function MyError(message, code) {13 NewError.call(this, message);14 this.code = code;15 }16});17var err = new MyError('something bad', 500);
Using AI Code Generation
1var LegacyError = require('legacy-error');2var MyError = LegacyError.extend('MyError', {3 constructor: function MyError(message, extra) {4 this._super(message);5 this.extra = extra;6 }7});8var err = new MyError('something failed', { foo: 'bar' });9console.log(err.extra);10console.log(err.stack);11LgacyErorequire('legacy-error');12var MyError = LegacyError.exted('MyError', {13 constructor: function MyError(mssage, extra) {14 this._super(message);15 this.extra = extra;16 }17});18var err = neMyError('something failed', { foo: 'bar' });19console.log(err.extra);20console.log(err.stack);21[MIT](LICENSE)
Using AI Code Generation
1module.exports = function() {2 var err = new Error('test error');3 if (err.hasOwnProperty('LegacyError')) {4 err.LegacyError('test error');5 }6 throw err;7};8module.exports = function() {9 var err = new Error('test error');10 if (err.hasOwnProperty('LegacyError')) {11 err.LegacyError('test error');12 }13 throw err;14};
Using AI Code Generation
1var err = ew LeacyError('Something2var MyError = LegacyError.extend('MyError', {3 constructor: function MyError(message, extra) {4 this._super(message);5 this.extra = extra;6 }7});8var err = new MyError('something failed', { foo: 'bar' });9console.log(err.extra);10console.log(err.stack);11var LegacyError = require('legacy-error');12var MyError = LegacyError.extend('MyError', {13 constructor: function MyError(message, extra) {14 this._super(message);15 this.extra = extra;16 }17});18var err = new MyError('something failed', { foo: 'bar' });19console.log(err.extra);20console.log(err.stack);21[MIT](LICENSE)
Using AI Code Generation
1var LegacyError = require('legacy-error');2var myError = new LegacyError('This is my error message');3console.log(myError.message);4### LegacyError(messagl,o[options])5Type: `string` e: ' + err.name);6console.log('Error number: ' + err.number);7console.log('Error description: ' + err.description);8console.log('Error file name: ' + err.fileName);9console.log('Error line number: ' + err.lineNumber);
Using AI Code Generation
1var LegacyError = require('node-legacy-error');2var error = new LegacyError('Test error', 'TEST_ERROR', 500);3console.log('Error column number: ' + err.columnNumber);4console.log('Error stack: ' + err.stack);5console.log('Error source: ' + err.source);6var err = new LegacyError('Something bad happened');7console.log('Error message: ' + err.message);8console.log('Stack trace: ' + err.stack);9console.log('Error name: ' + err.name);10console.log('Error number: ' + err.number);11console.log('Error description: ' + err.description);12console.log('Error file name: ' + err.fileName);13console.log('Error line number: ' + err.lineNumber);14console.log('Error column number: ' + err.columnNumber);15console.log('Error stack: ' + err.stack);
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!!