Best JavaScript code snippet using devicefarmer-stf
app.js
Source:app.js
2var app = express();3//é¾æ¥æ°æ®åºæ¨¡å4var mysql = require("mysql");5//è¿æ¥æå¡å¨é
ç½®.......................................................................6function createConnection() {7 var connection = mysql.createConnection({8 host: 'localhost',// 127.0.0.19 user: 'root',10 password: '',11 database: 'homestay'12 });13 return connection14}15//解å³è·¨å16app.all('*', function(req, res, next) {17 res.header("Access-Control-Allow-Origin", "*");18 res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");19 res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");20 res.header("X-Powered-By",' 3.2.1')21 next();22});23app.use(express.static('public'));24// parse application/json 25//get请æ±.................................................................................26//æ´æ°æ°å®¿ä¿¡æ¯çæ¥å£27app.get('/edithhomestay', function(req, res) {28 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã29 var connection = createConnection();30 connection.connect();31 //å¼å
¥æ¥æ¾æ¨¡å32 require('./router/update').edithhomestay(req,res,connection);33 console.log(req.query)34})35//.......................èµä¿è±ªåç两个æ¥å£...........................................36app.get('/userlogin',function(req,res){37 // res.append("Access-Control-Allow-Origin", "*");38 var connection = createConnection();39 connection.connect();40 require('./router/userlogin.js').userlogin(req,res,connection);41})42//.......................èµä¿è±ªåç两个æ¥å£................................................43//éè¿aid寻æ¾ç®¡çåçä¿¡æ¯44app.get('/selectaid', function(req, res) {45 46 var connection = createConnection();47 connection.connect();48 //å¼å
¥æ¥æ¾æ¨¡å49 require('./router/select').selectAid(req,res,connection);50 console.log(req.query)51}) 52//订åæå
¥53app.get('/insertord', function(req, res) {54 55 var connection = createConnection();56 connection.connect();57 //å¼å
¥æå
¥æ¨¡å 58 require('./router/insert').inserthzj(req,res,connection)59 console.log(req.query)60})61//å·¥ä½è®¡åå¶å®62app.get('/setplan', function(req, res) {63 64 var connection = createConnection();65 connection.connect();66 //å¼å
¥æå
¥æ¨¡å 67 require('./router/insert').setPlan(req,res,connection)68 console.log(req.query)69})70//å é¤å·¥ä½è®¡å71app.get('/closeplan', function(req, res) {72 73 var connection = createConnection();74 connection.connect();75 //å¼å
¥æ¥æ¾æ¨¡å76 require('./router/del').closePlan(req,res,connection);77 console.log(req.query)78})79//解éåå·¥80app.get('/dismissal', function(req, res) {81 82 var connection = createConnection();83 connection.connect();84 //å¼å
¥æ¥æ¾æ¨¡å85 require('./router/del').disMissal(req,res,connection);86 console.log(req.query)87})88//å é¤homestaryéé¢çæ°å®¿ä¿¡æ¯89app.get('/delethomestray', function(req, res) {90 91 var connection = createConnection();92 connection.connect();93 //å¼å
¥æ¥æ¾æ¨¡å94 require('./router/del').delSelf(req,res,connection);95 console.log(req.query)96}) 97//å é¤checkhomestayéé¢çæ°å®¿ä¿¡æ¯98app.get('/deletcheck', function(req, res) {99 100 var connection = createConnection();101 connection.connect();102 //å¼å
¥æ¥æ¾æ¨¡å103 require('./router/del').delCheck(req,res,connection);104 console.log(req.query)105}) 106//å¢å å®¡æ ¸è¿å
³çæ°å®¿ä¿¡æ¯107app.get('/insertcheck', function(req, res) {108 109 var connection = createConnection();110 connection.connect();111 //å¼å
¥æå
¥æ¨¡å 112 require('./router/insert').insertCheck(req,res,connection)113 console.log(req.query)114})115//å¢å 116app.get('/insert', function(req, res) {117 118 var connection = createConnection();119 connection.connect();120 //å¼å
¥æå
¥æ¨¡å 121 require('./router/insert').insert(req,res,connection)122 console.log(req.query)123})124//æ ¹æ®hidè·åé
åºæ°æ®125app.get('/selecthid', function(req, res) {126 127 var connection = createConnection();128 connection.connect();129 //å¼å
¥æ¥æ¾æ¨¡å130 require('./router/select').selectId(req,res,connection);131 console.log(req.query)132}) 133//è·åè¯è®ºæ°134app.get('/selectcommon', function(req, res) {135 136 var connection = createConnection();137 connection.connect();138 //å¼å
¥æ¥æ¾æ¨¡å139 require('./router/select').selectCommon(req,res,connection);140 console.log(req.query)141})142//å页è·åå端页é¢çååæ°æ®143app.get('/selectpage', function(req, res) {144 145 var connection = createConnection();146 connection.connect();147 //å¼å
¥æ¥æ¾æ¨¡å148 require('./router/select').selectPage(req,res,connection);149 console.log(req.query)150}) 151 152//è·åææå端页é¢çååæ°æ®153app.get('/selectAll', function(req, res) {154 155 var connection = createConnection();156 connection.connect();157 //å¼å
¥æ¥æ¾æ¨¡å158 require('./router/select').selectAll(req,res,connection);159 console.log(req.query)160})161//è·åæææåå¸çæ±ç§ä¿¡æ¯ ä½è·¯çæ¥å£ï¼ä¸è¦å¨æéååäºåä½ï¼162app.get('/myrelease', function(req, res) {163 164 var connection = createConnection();165 connection.connect();166 //å¼å
¥æ¥æ¾æ¨¡å167 require('./router/myRelease').myRelease(req,res,connection);168 console.log(req.query)169}) 170//å é¤åå¸æ±ç§çä¿¡æ¯ 171app.get('/deleteRelease', function(req, res) {172 var connection = createConnection();173 connection.connect();174 //å¼å
¥æ¥æ¾æ¨¡å175 require('./router/deleteRelease').deleteRelease(req,res,connection);176 console.log(req.query)177}) 178//æ¥æ¾æætraveléé¢çä¸è¥¿179app.get('/selectTravel', function(req, res) {180 // 解å³è·¨å181 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã182 var connection = createConnection();183 connection.connect();184 //å¼å
¥æ¥æ¾æ¨¡å185 require('./router/select').selectTravel(req,res,connection);186 console.log(req.query)187}) 188// æ¯æ¬¡æ¥æ¾åæ¡é
åºä¿¡æ¯189app.get('/selecthotel', function(req, res) {190 // 解å³è·¨å191 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã192 var connection = createConnection();193 connection.connect();194 //å¼å
¥æ¥æ¾æ¨¡å195 require('./router/selecthotel').selecthotel(req,res,connection);196 console.log(req.query)197}) 198// æ¥æ¾å享199app.get('/selectShare', function(req, res) {200 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã201 var connection = createConnection();202 connection.connect();203 //å¼å
¥æ¥æ¾æ¨¡å204 require('./router/share').selectShare(req,res,connection);205 console.log(req.query)206}) 207 208// é
åºæåº209app.get('/sorthotel', function(req, res) {210 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã211 var connection = createConnection();212 connection.connect();213 //å¼å
¥æ¥æ¾æ¨¡å214 require('./router/sorthotel').sorthotel(req,res,connection);215 console.log(req.query)216}) 217//æ¥æ¾ææå®¡æ ¸è¡¨åéçä¸è¥¿218app.get('/checkhomestay', function(req, res) {219 // 解å³è·¨å220 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã221 var connection = createConnection();222 connection.connect();223 //å¼å
¥æ¥æ¾æ¨¡å224 require('./router/select').checkhomestay(req,res,connection);225 console.log(req.query)226}) 227//è·åææworkplanéé¢çä¸è¥¿228app.get('/getplan', function(req, res) {229 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã230 var connection = createConnection();231 connection.connect();232 //å¼å
¥æ¥æ¾æ¨¡å233 require('./router/select').getplan(req,res,connection);234 console.log(req.query)235}) 236//è·åææadminéé¢çä¸è¥¿237app.get('/getadmin', function(req, res) {238 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã239 var connection = createConnection();240 connection.connect();241 //å¼å
¥æ¥æ¾æ¨¡å242 require('./router/select').getadmin(req,res,connection);243 console.log(req.query)244}) 245//æ´æ°adminçåå·¥è¯å246app.get('/changerate', function(req, res) {247 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã248 var connection = createConnection();249 connection.connect();250 //å¼å
¥æ¥æ¾æ¨¡å251 require('./router/update').updaterare(req,res,connection);252 console.log(req.query)253}) 254//è·å订åä¿¡æ¯255app.get('/getorder', function(req, res) {256 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã257 var connection = createConnection();258 connection.connect();259 //å¼å
¥æ¥æ¾æ¨¡å260 require('./router/orderlist').orderlist(req,res,connection);261 console.log(req.query)262}) 263//æ´æ°è®¢åç¶æ264app.get('/updateType', function(req, res) {265 var connection = createConnection();266 connection.connect();267 require('./router/update').updateType(req,res,connection);268 console.log(req.query)269}) 270//è¦post请æ±...............................................................................271// parse application/x-www-form-urlencoded 272//使ç¨bodyParser模å273//ç¨äºpost请æ±è·ååæ°274var bodyParser = require('body-parser')275app.use(bodyParser.urlencoded({276 extended: false277}))278//é±¼é²279app.post('/release', function(req, res) {280 281 var connection = createConnection();282 connection.connect();283 //å¼å
¥æå
¥æ¨¡å 284 require('./router/release').release(req,res,connection)285})286//注å管çè
287app.post('/registeradmin', function(req, res) {288 // 解å³è·¨å289 290 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã291 var connection = createConnection();292 connection.connect();293 //å¼å
¥æå
¥æ¨¡å 294 require('./router/register').registerAdmin(req,res,connection)295})296//éªè¯ç»å½è
297app.post('/loginadmin', function(req, res) {298 // 解å³è·¨å299 300 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã301 var connection = createConnection();302 connection.connect();303 //å¼å
¥æå
¥æ¨¡å 304 require('./router/register').loginAdmin(req,res,connection)305})306//èµä¿è±ªåç307app.post('/userregister', function(req, res) {308 309 //ç¶å请æ±çå¾å¿«çæ¶åæè½æ£å¸¸å
³éé¾æ¥ã310 var connection = createConnection();311 connection.connect();312 //å¼å
¥æå
¥æ¨¡å 313 require('./router/userregister.js').userregister(req,res,connection)314})315app.post('/userchange', function(req, res) {316 var connection = createConnection();317 connection.connect();318 //å¼å
¥æå
¥æ¨¡å 319 require('./router/userchange.js').userchange(req,res,connection)320})321//çå¬è¯¥ç«¯å£..............................................................................322var server = app.listen(3000, function() {323 //æµè¯324 //æµè¯325 var host = server.address().address326 var port = server.address().port327 console.log("åºç¨å®ä¾ï¼è®¿é®å°å为 http://%s:%s", host, port)...
test-createconnection-async.js
Source:test-createconnection-async.js
...7var cfg = require('../config.js');8exports.mysql_libmysqlclient_createConnection_0 = function (test) {9 test.expect(1);10 test.throws(function () {11 cfg.mysql_libmysqlclient.createConnection();12 }, "require('mysql-libmysqlclient').createConnection() must get callback as last argument");13 test.done();14};15exports.mysql_libmysqlclient_createConnection_1_NoFunction = function (test) {16 test.expect(1);17 test.throws(function () {18 cfg.mysql_libmysqlclient.createConnection(cfg.host);19 }, "require('mysql-libmysqlclient').createConnection() must get callback as last argument");20 test.done();21};22exports.mysql_libmysqlclient_createConnection_1_Function = function (test) {23 test.expect(2);24 cfg.mysql_libmysqlclient.createConnection(function (err, conn) {25 test.ok(err === null, "Error object is not present");26 test.ok(conn instanceof cfg.mysql_bindings.MysqlConnection, "conn instanceof MysqlConnection");27 if (conn.connectedSync()) {28 conn.closeSync();29 }30 test.done();31 });32};33exports.mysql_libmysqlclient_createConnection_2 = function (test) {34 test.expect(3);35 cfg.mysql_libmysqlclient.createConnection(cfg.host, function (err, conn) {36 test.ok(err instanceof Error, "Error object is present");37 test.ok(!conn, "Connection object is not defined");38 test.ok(err.message.match(/Connection error.*Access denied for user/));39 test.done();40 });41};42exports.mysql_libmysqlclient_createConnection_3_Function = function (test) {43 test.expect(3);44 cfg.mysql_libmysqlclient.createConnection(cfg.host, cfg.user, function (err, conn) {45 test.ok(err instanceof Error, "Error object is present");46 test.ok(!conn, "Connection object is not defined");47 var error = "Access denied for user '" + cfg.user + "'@'" + cfg.host + "' (using password: NO)";48 var errno = 1045;49 test.equals(err.message, "Connection error #" + errno + ": " + error, "Callback exception");50 if (conn && conn.connectedSync()) {51 conn.closeSync();52 }53 test.done();54 });55};56exports.mysql_libmysqlclient_createConnection_3_NoFunction = function (test) {57 test.expect(1);58 test.throws(function () {59 cfg.mysql_libmysqlclient.createConnection(cfg.host, cfg.user, cfg.password);60 }, "require('mysql-libmysqlclient').createConnection() must get callback as last argument");61 test.done();62};63exports.mysql_libmysqlclient_createConnection_4 = function (test) {64 test.expect(2);65 cfg.mysql_libmysqlclient.createConnection(cfg.host, cfg.user, cfg.password, function (err, conn) {66 test.ok(err === null, "Error object is not present");67 test.ok(conn instanceof cfg.mysql_bindings.MysqlConnection, "conn instanceof MysqlConnection");68 if (conn.connectedSync()) {69 conn.closeSync();70 }71 test.done();72 });73};74exports.mysql_libmysqlclient_createConnection_5_AccessAllowed = function (test) {75 test.expect(3);76 cfg.mysql_libmysqlclient.createConnection(cfg.host, cfg.user, cfg.password, cfg.database, function (err, conn) {77 test.ok(err === null, "Error object is not present");78 test.ok(conn instanceof cfg.mysql_bindings.MysqlConnection, "conn instanceof MysqlConnection");79 var isConnected = conn.connectedSync();80 test.ok(isConnected, "cfg.mysql_libmysqlclient.createConnection(host, user, password, database, callback)");81 if (!isConnected) {82 // Extra debug output83 console.log("Error:" + conn.connectError);84 } else {85 conn.closeSync();86 }87 test.done();88 });89};90exports.mysql_libmysqlclient_createConnection_5_AccessDenied = function (test) {91 test.expect(3);92 cfg.mysql_libmysqlclient.createConnection(cfg.host, cfg.user, cfg.password, cfg.database_denied, function (err, conn) {93 test.ok(err, "Error object is present");94 test.ok(!conn, "Connection object is not defined");95 var error = "Access denied for user '" + cfg.user + "'@'" + cfg.host + "' to database '" + cfg.database_denied + "'";96 var errno = 1044;97 test.equals(err.message, "Connection error #" + errno + ": " + error, "Callback exception");98 test.done();99 });100};101exports.mysql_libmysqlclient_createConnection_6 = function (test) {102 test.expect(3);103 cfg.mysql_libmysqlclient.createConnection(cfg.host, cfg.user, cfg.password, cfg.database, cfg.port, function (err, conn) {104 test.ok(err === null, "Error object is not present");105 test.ok(conn instanceof cfg.mysql_bindings.MysqlConnection, "conn instanceof MysqlConnection");106 var isConnected = conn.connectedSync();107 test.ok(isConnected, "cfg.mysql_libmysqlclient.createConnection(host, user, password, database, flags, callback)");108 if (!isConnected) {109 // Extra debug output110 console.log("Error:" + conn.connectError);111 } else {112 conn.closeSync();113 }114 test.done();115 });116};117exports.mysql_libmysqlclient_createConnection_8 = function (test) {118 test.expect(3);119 var compress_flag = cfg.mysql_bindings.CLIENT_COMPRESS;120 cfg.mysql_libmysqlclient.createConnection(cfg.host, cfg.user, cfg.password, cfg.database, null, null, compress_flag, function (err, conn) {121 test.ok(err === null, "Error object is not present");122 test.ok(conn instanceof cfg.mysql_bindings.MysqlConnection, "conn instanceof MysqlConnection");123 var isConnected = conn.connectedSync();124 test.ok(isConnected, "cfg.mysql_libmysqlclient.createConnection(host, user, password, database, flags, callback)");125 if (!isConnected) {126 // Extra debug output127 console.log("Error:" + conn.connectError);128 } else {129 conn.closeSync();130 }131 test.done();132 });133};134exports.mysql_libmysqlclient_createConnectionSync_DSN_1 = function (test) {135 test.expect(3);136 var dsn = require('util').format("mysql://%s:%s@%s:%s", cfg.user, cfg.password, cfg.host, cfg.port);137 cfg.mysql_libmysqlclient.createConnection(dsn, function (err, conn) {138 test.ok(err === null, "Error object is not present");139 test.ok(conn instanceof cfg.mysql_bindings.MysqlConnection, "conn instanceof MysqlConnection");140 var isConnected = conn.connectedSync();141 test.ok(isConnected, "cfg.mysql_libmysqlclient.createConnection(dsn(user, password, host, port), callback)");142 if (!isConnected) {143 // Extra debug output144 console.log("Error:" + conn.connectError);145 } else {146 conn.closeSync();147 }148 test.done();149 });150};151exports.mysql_libmysqlclient_createConnectionSync_DSN_2 = function (test) {152 test.expect(3);153 var dsn = require('util').format("mysql://%s:%s@%s:%s?qwerty=1234", cfg.user, cfg.password, cfg.host, cfg.port);154 cfg.mysql_libmysqlclient.createConnection(dsn, function (err, conn) {155 test.ok(err === null, "Error object is not present");156 test.ok(conn instanceof cfg.mysql_bindings.MysqlConnection, "conn instanceof MysqlConnection");157 var isConnected = conn.connectedSync();158 test.ok(isConnected, "cfg.mysql_libmysqlclient.createConnection(dsn(user, password, host, port), callback)");159 if (!isConnected) {160 // Extra debug output161 console.log("Error:" + conn.connectError);162 } else {163 conn.closeSync();164 }165 test.done();166 });167};168exports.mysql_libmysqlclient_createConnectionSync_DSN_3 = function (test) {169 test.expect(3);170 var dsn = require('util').format("mysql://%s:%s@%s:%s/%s/zxcvbn?qwerty=1234", cfg.user, cfg.password, cfg.host, cfg.port, cfg.database);171 cfg.mysql_libmysqlclient.createConnection(dsn, function (err, conn) {172 test.ok(err === null, "Error object is not present");173 test.ok(conn instanceof cfg.mysql_bindings.MysqlConnection, "conn instanceof MysqlConnection");174 var isConnected = conn.connectedSync();175 test.ok(isConnected, "cfg.mysql_libmysqlclient.createConnection(dsn(user, password, host, port, database), callback)");176 if (!isConnected) {177 // Extra debug output178 console.log("Error:" + conn.connectError);179 } else {180 conn.closeSync();181 }182 test.done();183 });...
client.js
Source:client.js
...128};129//130// ### function createConnection (options)131//132proto.createConnection = function createConnection(options) {133 if (!options)134 options = {};135 var state = this._spdyState;136 var stream = new spdy.Stream(state.connection, {137 id: state.id,138 priority: options.priority || 7,139 client: true,140 decompress: options.spdy.decompress == undefined ? true :141 options.spdy.decompress142 });143 state.id += 2;144 state.connection._addStream(stream);145 return stream;146};...
getdata.js
Source:getdata.js
...5var createConnection = require("../createConnection.js")6router.post('/indexbanner', function (req, res, next) {7 res.setHeader("Access-Control-Allow-Origin", "*");//å
许跨å8 res.setHeader("Content-Type", "text/plain;charset=UTF-8");//å符ç¼ç 9 createConnection(`select * from index_banner where type='${req.body.type}'`, function (results) {10 res.send(results);11 });12});13router.post('/indexblist', function (req, res, next) {14 res.setHeader("Access-Control-Allow-Origin", "*");//å
许跨å15 res.setHeader("Content-Type", "text/plain;charset=UTF-8");//å符ç¼ç 16 createConnection(`select * from index_booklist where type='${req.body.type}'`, function (results) {17 res.send(results);18 });19});20router.post('/getbanner', function (req, res, next) {21 res.setHeader("Access-Control-Allow-Origin", "*");//å
许跨å22 res.setHeader("Content-Type", "text/plain;charset=UTF-8");//å符ç¼ç 23 createConnection(`select * from autoplay where type='${req.body.type}'`, function (results) {24 res.send(results);25 });26});27router.post('/latelyupdate', function (req, res, next) {28 res.setHeader("Access-Control-Allow-Origin", "*");//å
许跨å29 res.setHeader("Content-Type", "text/plain;charset=UTF-8");//å符ç¼ç 30 createConnection(`select * from index_lately_update`, function (results) {31 res.send(results);32 });33});34router.post('/indextop', function (req, res, next) {35 res.setHeader("Access-Control-Allow-Origin", "*");//å
许跨å36 res.setHeader("Content-Type", "text/plain;charset=UTF-8");//å符ç¼ç 37 createConnection(`select * from index_top where type='${req.body.type}'`, function (results) {38 res.send(results);39 });40});41router.post('/getbookinfo', function (req, res, next) {42 res.setHeader("Access-Control-Allow-Origin", "*");//å
许跨å43 res.setHeader("Content-Type", "text/plain;charset=UTF-8");//å符ç¼ç 44 createConnection(`select * from book_info where book_id_curr='${req.body.actionid}'`, function (results) {45 res.send(results);46 });47});48router.post('/getdata2', function (req, res, next) {49 res.setHeader("Access-Control-Allow-Origin", "*");//å
许跨å50 res.setHeader("Content-Type", "text/plain;charset=UTF-8");//å符ç¼ç 51 createConnection(`select * from index_top`, function (results) {52 res.send(results);53 });54});55router.post('/getdata1', function (req, res, next) {56 res.setHeader("Access-Control-Allow-Origin", "*");//å
许跨å57 res.setHeader("Content-Type", "text/plain;charset=UTF-8");//å符ç¼ç 58 createConnection(`select * from autoplay`, function (results) {59 res.send(results);60 });61});62router.post('/getdata3', function (req, res, next) {63 res.setHeader("Access-Control-Allow-Origin", "*");//å
许跨å64 res.setHeader("Content-Type", "text/plain;charset=UTF-8");//å符ç¼ç 65 createConnection(`select * from index_lately_update`, function (results) {66 res.send(results);67 });68});69router.post('/getdata4', function (req, res, next) {70 res.setHeader("Access-Control-Allow-Origin", "*");//å
许跨å71 res.setHeader("Content-Type", "text/plain;charset=UTF-8");//å符ç¼ç 72 createConnection(`select * from index_booklist`, function (results) {73 res.send(results);74 });75});...
Database.test.js
Source:Database.test.js
...16// const connection = {};17// // createConnection = jest.fn(async () => connection);18// const config = {};19// const db = new Database(config);20// return expect(db.createConnection()).resolves.toBe(connection);21// });22// it('Creates a connection with the databases config', async () => {23// const connection = {};24// createConnection = jest.fn(async () => connection);25// const config = {};26// const db = new Database(config);27// await db.createConnection();28// expect(createConnection).toBeCalledWith(config);29// expect(createConnection).toBeCalledTimes(1);30// });31// it('Stores the connection internally', async () => {32// const connection = {};33// createConnection = jest.fn(async () => connection);34// const config = {};35// const db = new Database(config);36// await db.createConnection();37// expect(db.connection).toBe(connection);38// });39// });40// describe('Get connection always returns a connection object.', () => {41// it('returns a connection object when only just initialized.', async () => {42// const connection = {};43// createConnection = jest.fn(async () => connection);44// const config = {};45// const db = new Database(config);46// const conn = await db.getConnection();47// expect(conn).toBe(connection);48// });49// it('returns the same connection object after creating it.', async () => {50// const connection = {};...
transport_lists_spec.js
Source:transport_lists_spec.js
1describe("Transport lists", function() {2 var _isReady = Pusher.isReady;3 beforeEach(function() {4 spyOn(Pusher.WSTransport, "isSupported").andReturn(true);5 spyOn(Pusher.FlashTransport, "isSupported").andReturn(true);6 spyOn(Pusher.SockJSTransport, "isSupported").andReturn(true);7 spyOn(Pusher.WSTransport, "createConnection")8 .andCallFake(Pusher.Mocks.getTransport);9 spyOn(Pusher.FlashTransport, "createConnection")10 .andCallFake(Pusher.Mocks.getTransport);11 spyOn(Pusher.SockJSTransport, "createConnection")12 .andCallFake(Pusher.Mocks.getTransport);13 spyOn(Pusher, "getDefaultStrategy").andCallFake(function() {14 return [15 [":def_transport", "a", "ws", 1, {}],16 [":def_transport", "b", "flash", 2, {}],17 [":def_transport", "c", "sockjs", 3, {}],18 [":def", "strategy", [":best_connected_ever", ":a", ":b", ":c"]]19 ];20 });21 spyOn(Pusher.Network, "isOnline").andReturn(true);22 Pusher.isReady = true;23 });24 afterEach(function() {25 Pusher.isReady = _isReady;26 });27 it("should use all transports if the whitelist is not specified", function() {28 var pusher = new Pusher("asdf", { disableStats: true });29 expect(Pusher.WSTransport.createConnection).toHaveBeenCalled();30 expect(Pusher.FlashTransport.createConnection).toHaveBeenCalled();31 expect(Pusher.SockJSTransport.createConnection).toHaveBeenCalled();32 pusher.disconnect();33 });34 it("should not use any transports if the whitelist is empty", function() {35 var pusher = new Pusher("asdf", {36 disableStats: true,37 enabledTransports: []38 });39 expect(Pusher.WSTransport.createConnection).not.toHaveBeenCalled();40 expect(Pusher.FlashTransport.createConnection).not.toHaveBeenCalled();41 expect(Pusher.SockJSTransport.createConnection).not.toHaveBeenCalled();42 pusher.disconnect();43 });44 it("should use only transports from the whitelist", function() {45 var pusher = new Pusher("asdf", {46 disableStats: true,47 enabledTransports: ["a", "c"]48 });49 expect(Pusher.WSTransport.createConnection).toHaveBeenCalled();50 expect(Pusher.FlashTransport.createConnection).not.toHaveBeenCalled();51 expect(Pusher.SockJSTransport.createConnection).toHaveBeenCalled();52 pusher.disconnect();53 });54 it("should not use transports from the blacklist", function() {55 var pusher = new Pusher("asdf", {56 disableStats: true,57 disabledTransports: ["a", "b"]58 });59 expect(Pusher.WSTransport.createConnection).not.toHaveBeenCalled();60 expect(Pusher.FlashTransport.createConnection).not.toHaveBeenCalled();61 expect(Pusher.SockJSTransport.createConnection).toHaveBeenCalled();62 pusher.disconnect();63 });64 it("should not use transports from the blacklist, even if they are on the whitelist", function() {65 var pusher = new Pusher("asdf", {66 disableStats: true,67 enabledTransports: ["b", "c"],68 disabledTransports: ["b"]69 });70 expect(Pusher.WSTransport.createConnection).not.toHaveBeenCalled();71 expect(Pusher.FlashTransport.createConnection).not.toHaveBeenCalled();72 expect(Pusher.SockJSTransport.createConnection).toHaveBeenCalled();73 pusher.disconnect();74 });...
test-net-create-connection.js
Source:test-net-create-connection.js
...17 ++clientConnected;18 }19 function fail(opts, errtype, msg) {20 assert.throws(function() {21 var client = net.createConnection(opts, cb);22 }, function(err) {23 return err instanceof errtype && msg === err.message;24 });25 }26 net.createConnection(tcpPort).on('connect', cb);27 net.createConnection(tcpPort, 'localhost').on('connect', cb);28 net.createConnection(tcpPort, cb);29 net.createConnection(tcpPort, 'localhost', cb);30 net.createConnection(tcpPort + '', 'localhost', cb);31 net.createConnection({port: tcpPort + ''}).on('connect', cb);32 net.createConnection({port: '0x' + tcpPort.toString(16)}, cb);33 fail({34 port: true35 }, TypeError, 'port should be a number or string: true');36 fail({37 port: false38 }, TypeError, 'port should be a number or string: false');39 fail({40 port: []41 }, TypeError, 'port should be a number or string: ');42 fail({43 port: {}44 }, TypeError, 'port should be a number or string: [object Object]');45 fail({46 port: null47 }, TypeError, 'port should be a number or string: null');48 fail({49 port: ''50 }, RangeError, 'port should be >= 0 and < 65536: ');51 fail({52 port: ' '53 }, RangeError, 'port should be >= 0 and < 65536: ');54 fail({55 port: '0x'56 }, RangeError, 'port should be >= 0 and < 65536: 0x');57 fail({58 port: '-0x1'59 }, RangeError, 'port should be >= 0 and < 65536: -0x1');60 fail({61 port: NaN62 }, RangeError, 'port should be >= 0 and < 65536: NaN');63 fail({64 port: Infinity65 }, RangeError, 'port should be >= 0 and < 65536: Infinity');66 fail({67 port: -168 }, RangeError, 'port should be >= 0 and < 65536: -1');69 fail({70 port: 6553671 }, RangeError, 'port should be >= 0 and < 65536: 65536');72});73// Try connecting to random ports, but do so once the server is closed74server.on('close', function() {75 function nop() {}76 net.createConnection({port: 0}).on('error', nop);77 net.createConnection({port: undefined}).on('error', nop);78});79process.on('exit', function() {80 assert.equal(clientConnected, expectedConnections);...
test-http-createConnection.js
Source:test-http-createConnection.js
...29 });30 });31 });32});33function createConnection() {34 return net.createConnection(server.address().port, '127.0.0.1');35}36function createConnectionAsync(options, cb) {37 setImmediate(function() {38 cb(null, net.createConnection(server.address().port, '127.0.0.1'));39 });40}41function createConnectionBoth1(options, cb) {42 const socket = net.createConnection(server.address().port, '127.0.0.1');43 setImmediate(function() {44 cb(null, socket);45 });46 return socket;47}48function createConnectionBoth2(options, cb) {49 const socket = net.createConnection(server.address().port, '127.0.0.1');50 cb(null, socket);51 return socket;52}53function createConnectionError(options, cb) {54 process.nextTick(cb, new Error('Could not create socket'));...
Using AI Code Generation
1var stf = require('devicefarmer-stf');2stfConnection.devices().then(function(devices) {3 console.log(devices);4});5var stf = require('devicefarmer-stf');6stfConnection.devices().then(function(devices) {7 console.log(devices);8});9var stf = require('devicefarmer-stf');10stfConnection.devices().then(function(devices) {11 console.log(devices);12});13var stf = require('devicefarmer-stf');14stfConnection.devices().then(function(devices) {15 console.log(devices);16});17var stf = require('devicefarmer-stf');18stfConnection.devices().then(function(devices) {19 console.log(devices);20});21var stf = require('devicefarmer-stf');22stfConnection.devices().then(function(devices) {23 console.log(devices);24});25var stf = require('devicefarmer-stf');26stfConnection.devices().then(function(devices) {27 console.log(devices);28});29var stf = require('devicefarmer-stf');30stfConnection.devices().then(function(devices) {31 console.log(devices);32});
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var device = stf.createConnection();3device.connect();4var stf = require('devicefarmer-stf');5var device = stf.createConnection();6device.connect();7var stf = require('devicefarmer-stf');8var device = stf.createConnection();9device.connect();10var stf = require('devicefarmer-stf');11var device = stf.createConnection();12device.connect();13var stf = require('devicefarmer-stf');14var device = stf.createConnection();15device.connect();16var stf = require('devicefarmer-stf');17var device = stf.createConnection();18device.connect();19var stf = require('devicefarmer-stf');20var device = stf.createConnection();21device.connect();22var stf = require('devicefarmer-stf');23var device = stf.createConnection();24device.connect();25var stf = require('devicefarmer-stf');26var device = stf.createConnection();27device.connect();28var stf = require('devicefarmer-stf');29var device = stf.createConnection();30device.connect();31var stf = require('devicefarmer-stf');32var device = stf.createConnection();33device.connect();
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!!