Best JavaScript code snippet using appium
cli.test.js
Source:cli.test.js
...37 it("must be a function", function () {38 t.typeOf(mostel.cli, "function");39 });40 it("should start a mosca.Server", function (done) {41 startServer(done, function (server) {42 t.instanceOf(server, mosca.Server);43 });44 });45 it("should create a bunyan logger", function (done) {46 args.push("-i");47 var s = startServer(done, function (server) {48 t.ok(server.logger);49 });50 if (s.logger) {51 s.logger.streams.pop();52 }53 });54 it("should set the logging level to 40", function (done) {55 startServer(done, function (server) {56 t.equal(server.logger.level(), 40);57 });58 });59 it("should support a `info` option by setting the bunyan level to 30", function (done) {60 args.push("-i");61 var s = startServer(done, function (server) {62 t.equal(server.logger.level(), 30);63 });64 if (s.logger) {65 s.logger.streams.pop();66 }67 });68 it("should support a `debug` option by setting the bunyan level to 20", function (done) {69 args.push("--debug");70 var s = startServer(done, function (server) {71 t.equal(server.logger.level(), 20);72 });73 if (s.logger) {74 s.logger.streams.pop();75 }76 });77 it("should support a port flag", function(done) {78 args.push("-p");79 args.push("2883");80 startServer(done, function(server) {81 t.equal(server.opts.port, 2883);82 });83 });84 it("should support a port flag (bis)", function(done) {85 args.push("--port");86 args.push("2883");87 startServer(done, function(server) {88 t.equal(server.opts.port, 2883);89 });90 });91 it("should support a parent port", function(done) {92 args.push("--parent-port");93 args.push("3833");94 startServer(done, function(server) {95 t.equal(server.opts.backend.type, "mqtt");96 t.equal(server.opts.backend.port, 3833);97 });98 });99 it("should support a parent host", function(done) {100 args.push("--parent-host");101 args.push("localhost");102 args.push("--parent-port");103 args.push("3833");104 startServer(done, function(server) {105 t.equal(server.opts.backend.type, "mqtt");106 t.equal(server.opts.backend.host, "localhost");107 });108 });109 it("should support a parent prefix", function(done) {110 args.push("--parent-port");111 args.push("3833");112 args.push("--parent-prefix");113 args.push("/ahaha");114 startServer(done, function(server) {115 t.equal(server.opts.backend.prefix, "/ahaha");116 });117 });118 it("should support a config option", function (done) {119 args.push("--config");120 args.push("test/sample_config.js");121 startServer(done, function (server) {122 t.propertyVal(server.opts, "port", 2883);123 t.deepPropertyVal(server.opts, "backend.port", 3833);124 });125 });126 it("should support a config option with an absolute path", function (done) {127 args.push("-c");128 args.push(process.cwd() + "/test/sample_config.js");129 startServer(done, function (server) {130 t.propertyVal(server.opts, "port", 2883);131 t.deepPropertyVal(server.opts, "backend.port", 3833);132 });133 });134 it("should create necessary default options even if not specified in config file", function (done) {135 args.push("-c");136 args.push(process.cwd() + "/test/sample_config.js");137 args.push("-i");138 var s = startServer(done, function (server) {139 t.deepPropertyVal(server.opts, "logger.name", "mosca");140 });141 if (s.logger) {142 s.logger.streams.pop();143 }144 });145 it("should create an app to an authorization file", function (done) {146 args.push("addapp");147 args.push("myapp");148 args.push("mykey");149 args.push("--creds");150 tmp.file(function (err, path) {151 if (err) {152 done(err);153 return;154 }155 args.push(path);156 mostel.cli(args, function () {157 var content = JSON.parse(fs.readFileSync(path));158 t.property(content, "idx");159 t.property(content, "apps");160 t.deepProperty(content, "apps.mykey");161 done();162 });163 });164 });165 it("should remove an app from an authorization file", function (done) {166 args.push("addapp");167 args.push("myapp");168 args.push("mykey");169 args.push("--creds");170 tmp.file(function (err, path) {171 if (err) {172 done(err);173 return;174 }175 args.push(path);176 var cloned = [].concat(args);177 cloned[2] = "rmapp";178 cloned.splice(3, 1);179 mostel.cli(args, function () {180 mostel.cli(cloned, function () {181 var content = JSON.parse(fs.readFileSync(path));182 t.notDeepProperty(content, "apps.mykey");183 done();184 });185 });186 });187 });188 it("should support authorizing an authorized client", function (done) {189 args.push("--creds");190 args.push("test/creds.json");191 async.waterfall([192 function (cb) {193 mostel.cli(args, cb);194 },195 function (server, cb) {196 servers.unshift(server);197 var options = { username: "test_key", password: "kyte7mewy230faey2use" };198 var client = mqtt.createClient(1883, "localhost", options);199 client.on("error", cb);200 client.on("connect", function () {201 cb(null, client);202 });203 },204 function (client, cb) {205 client.once("close", cb);206 client.end();207 }208 ], function (err) {209 if (err instanceof Error) {210 done(err);211 return;212 }213 done();214 });215 });216 it("should support negating an unauthorized client", function (done) {217 args.push("--creds");218 args.push("test/creds.json");219 async.waterfall([220 function (cb) {221 mostel.cli(args, cb);222 },223 function (server, cb) {224 servers.unshift(server);225 var options = { username: "bad", password: "bad" };226 var client = mqtt.createClient(1883, "localhost", options);227 client.on("error", cb);228 client.on("connect", function () {229 cb(null, client);230 });231 },232 function (client, cb) {233 client.once("close", cb);234 client.end();235 }236 ], function (err) {237 if (err) {238 done();239 return;240 }241 done(new Error("No error thrown"));242 });243 });244 it("should reload the current config if killed with SIGHUP on a Linux-based OS", function (done) {245 if (os.platform() === "win32") return done();246 args.push("addapp");247 args.push("myapp");248 args.push("mykey");249 args.push("mysecret");250 args.push("--creds");251 var cloned = null;252 async.waterfall([253 function (cb) {254 tmp.file(cb);255 },256 function (path, fd, cb) {257 args.push(path);258 cloned = [].concat(args);259 cloned[2] = "rmapp";260 cloned.splice(3, 1);261 mostel.cli(args, cb);262 },263 function (cb) {264 mostel.cli(["node", "mostel", "--creds", cloned[cloned.length - 1]], cb);265 },266 function (server, cb) {267 servers.unshift(server);268 setTimeout(function () {269 mostel.cli(cloned, cb);270 }, 300);271 },272 function (cb) {273 process.kill(process.pid, 'SIGHUP');274 setTimeout(cb, 50);275 },276 function (cb) {277 var options = { username: "mykey", password: "mysecret" };278 var client = mqtt.createClient(1883, "localhost", options);279 client.once("error", cb);280 client.once("connect", function () {281 client.once("close", cb);282 client.end();283 });284 }285 ], function (err) {286 if (err) {287 done();288 return;289 }290 done(new Error("should have errored"));291 });292 });293 it("should save the creds.json as a formatted JSON when adding", function (done) {294 args.push("addapp");295 args.push("myapp");296 args.push("mykey");297 args.push("--creds");298 tmp.file(function (err, path) {299 if (err) {300 done(err);301 return;302 }303 args.push(path);304 mostel.cli(args, function () {305 var content = fs.readFileSync(path);306 t.equal(JSON.stringify(JSON.parse(content), null, 2), content.toString('utf8'));307 done();308 });309 });310 });311 it("should save the creds.json as a formatted JSON when removing", function (done) {312 args.push("addapp");313 args.push("myapp");314 args.push("mykey");315 args.push("--creds");316 tmp.file(function (err, path) {317 if (err) {318 done(err);319 return;320 }321 args.push(path);322 var cloned = [].concat(args);323 cloned[2] = "rmapp";324 cloned[3] = "anotherkey";325 mostel.cli(args, function () {326 mostel.cli(cloned, function () {327 var content = fs.readFileSync(path);328 t.equal(JSON.stringify(JSON.parse(content), null, 2), content.toString('utf8'));329 done();330 });331 });332 });333 });334 it("should create a leveldb with the --db flag", function(done) {335 tmp.dir(function (err, path, fd) {336 if (err) {337 done(err);338 return;339 }340 args.push("--db");341 args.push(path);342 startServer(done, function(server) {343 t.instanceOf(server.persistence, mosca.persistence.LevelUp);344 t.equal(server.persistence.options.path, path);345 });346 });347 });348 describe("with --key and --cert", function() {349 beforeEach(function() {350 args.push("--key");351 args.push(SECURE_KEY);352 args.push("--cert");353 args.push(SECURE_CERT);354 });355 it("should pass key and cert to the server", function(done) {356 startServer(done, function(server) {357 t.equal(server.opts.secure.keyPath, SECURE_KEY);358 t.equal(server.opts.secure.certPath, SECURE_CERT);359 });360 });361 it("should support the --secure-port flag", function(done) {362 var port = nextPort();363 args.push("--secure-port");364 args.push(port);365 startServer(done, function(server) {366 t.equal(server.opts.secure.port, port);367 });368 });369 it("should set the secure port by default at 8883", function(done) {370 startServer(done, function(server) {371 t.equal(server.opts.secure.port, 8883);372 });373 });374 it("should pass the --non-secure flag to the server", function(done) {375 args.push("--non-secure");376 startServer(done, function(server) {377 t.equal(server.opts.allowNonSecure, true);378 });379 });380 it("should allow to set the https port", function(done) {381 args.push("--https-port");382 args.push("3000");383 startServer(done, function(server) {384 t.equal(server.opts.https.port, 3000);385 });386 });387 it("should serve a HTTPS static directory", function(done) {388 args.push("--https-port");389 args.push("3000");390 args.push("--https-static");391 args.push("/path/to/nowhere");392 startServer(done, function(server) {393 t.equal(server.opts.https.static, "/path/to/nowhere");394 });395 });396 it("should serve a HTTPS browserify bundle", function(done) {397 args.push("--https-port");398 args.push("3000");399 args.push("--https-bundle");400 startServer(done, function(server) {401 t.equal(server.opts.https.bundle, true);402 });403 });404 });405 it("should allow to set the http port", function(done) {406 args.push("--http-port");407 args.push("3000");408 startServer(done, function(server) {409 t.equal(server.opts.http.port, 3000);410 });411 });412 it("should allow to limit the server only to http", function(done) {413 args.push("--http-port");414 args.push("3000");415 args.push("--only-http");416 startServer(done, function(server) {417 t.equal(server.opts.http.port, 3000);418 });419 });420 it("should serve a HTTP static directory", function(done) {421 args.push("--http-port");422 args.push("3000");423 args.push("--http-static");424 args.push("/path/to/nowhere");425 startServer(done, function(server) {426 t.equal(server.opts.http.static, "/path/to/nowhere");427 });428 });429 it("should serve a HTTP browserify bundle", function(done) {430 args.push("--http-port");431 args.push("3000");432 args.push("--http-bundle");433 startServer(done, function(server) {434 t.equal(server.opts.http.bundle, true);435 });436 });437 it("should have stats enabled by default", function(done) {438 var s = startServer(done, function(server) {439 t.equal(server.opts.stats, true);440 });441 });442 it("should allow to disable stats", function(done) {443 args.push("--disable-stats");444 var s = startServer(done, function(server) {445 t.equal(server.opts.stats, false);446 });447 });448 it("should allow to specify a broker id", function(done) {449 args.push("--broker-id");450 args.push("44cats");451 var s = startServer(done, function(server) {452 t.equal(server.id, "44cats");453 });454 });455 it("should specify an interface to bind to", function(done) {456 args.push("--host");457 args.push("127.0.0.1");458 startServer(done, function(server) {459 t.equal(server.opts.host, "127.0.0.1");460 });461 });...
cli.js
Source:cli.js
...36 it("must be a function", function() {37 expect(mosca.cli).to.be.a("function");38 });39 it("should start a mosca.Server", function(done) {40 startServer(done, function(server) {41 expect(server).to.be.instanceOf(mosca.Server);42 });43 });44 it("should support a port flag", function(done) {45 args.push("-p");46 args.push("2883");47 startServer(done, function(server) {48 expect(server.opts.port).to.eql(2883);49 });50 });51 it("should support a port flag (bis)", function(done) {52 args.push("--port");53 args.push("2883");54 startServer(done, function(server) {55 expect(server.opts.port).to.eql(2883);56 });57 });58 it("should support a parent port", function(done) {59 args.push("--parent-port");60 args.push("3833");61 startServer(done, function(server) {62 expect(server.opts.backend.type).to.eql("mqtt");63 expect(server.opts.backend.port).to.eql(3833);64 });65 });66 it("should support a parent host", function(done) {67 args.push("--parent-host");68 args.push("localhost");69 args.push("--parent-port");70 args.push("3833");71 startServer(done, function(server) {72 expect(server.opts.backend.type).to.eql("mqtt");73 expect(server.opts.backend.host).to.eql("localhost");74 });75 });76 it("should support a parent prefix", function(done) {77 args.push("--parent-port");78 args.push("3833");79 args.push("--parent-prefix");80 args.push("/ahaha");81 startServer(done, function(server) {82 expect(server.opts.backend.prefix).to.eql("/ahaha");83 });84 });85 it("should support a config option", function(done) {86 args.push("--config");87 args.push("test/sample_config.js");88 startServer(done, function(server) {89 expect(server.opts).to.have.property("port", 2883);90 expect(server.opts).to.have.deep.property("backend.port", 3833);91 });92 });93 it("should support a config option with an absolute path", function(done) {94 args.push("-c");95 args.push(process.cwd() + "/test/sample_config.js");96 startServer(done, function(server) {97 expect(server.opts).to.have.property("port", 2883);98 expect(server.opts).to.have.deep.property("backend.port", 3833);99 });100 });101 it("should add an user to an authorization file", function(done) {102 args.push("adduser");103 args.push("myuser");104 args.push("mypass");105 args.push("--credentials");106 tmp.file(function (err, path, fd) {107 if (err) {108 done(err);109 return;110 }111 args.push(path);112 mosca.cli(args, function () {113 var content = JSON.parse(fs.readFileSync(path));114 expect(content).to.have.property("myuser");115 done();116 });117 });118 });119 it("should add an user specifying the authorizePublish pattern", function(done) {120 args.push("adduser");121 args.push("myuser");122 args.push("mypass");123 args.push("--authorize-publish");124 args.push("hello/**/*");125 args.push("--credentials");126 tmp.file(function (err, path, fd) {127 if (err) {128 done(err);129 return;130 }131 args.push(path);132 mosca.cli(args, function () {133 var content = JSON.parse(fs.readFileSync(path));134 expect(content.myuser).to.have.property("authorizePublish", "hello/**/*");135 done();136 });137 });138 });139 it("should add an user specifying the authorizeSubscribe pattern", function(done) {140 args.push("adduser");141 args.push("myuser");142 args.push("mypass");143 args.push("--authorize-subscribe");144 args.push("hello/**/*");145 args.push("--credentials");146 tmp.file(function (err, path, fd) {147 if (err) {148 done(err);149 return;150 }151 args.push(path);152 mosca.cli(args, function () {153 var content = JSON.parse(fs.readFileSync(path));154 expect(content.myuser).to.have.property("authorizeSubscribe", "hello/**/*");155 done();156 });157 });158 });159 it("should remove an user from an authorization file", function(done) {160 args.push("adduser");161 args.push("myuser");162 args.push("mypass");163 args.push("--credentials");164 tmp.file(function (err, path, fd) {165 if (err) {166 done(err);167 return;168 }169 args.push(path);170 var cloned = [].concat(args);171 cloned[2] = "rmuser";172 mosca.cli(args, function () {173 mosca.cli(cloned, function () {174 var content = JSON.parse(fs.readFileSync(path));175 expect(content).not.to.have.property("myuser");176 done();177 });178 });179 });180 });181 it("should support authorizing an authorized client", function(done) {182 args.push("--credentials");183 args.push("test/credentials.json");184 steed.waterfall([185 function(cb) {186 mosca.cli(args, cb);187 },188 function(server, cb) {189 servers.unshift(server);190 var options = { username: "test", password: "test", port: 1883 };191 var client = mqtt.connect(options);192 client.on("error", cb);193 client.on("connect", function() {194 cb(null, client);195 });196 },197 function(client, cb) {198 client.once("close", cb);199 client.end();200 }201 ], function(err) {202 if(err instanceof Error) {203 done(err);204 return;205 }206 done();207 });208 });209 it("should support negating an unauthorized client", function(done) {210 args.push("--credentials");211 args.push("test/credentials.json");212 steed.waterfall([213 function(cb) {214 mosca.cli(args, cb);215 },216 function(server, cb) {217 servers.unshift(server);218 var options = { port: 1883, username: "bad", password: "bad" };219 var client = mqtt.connect(options);220 client.on("error", cb);221 client.on("connect", function() {222 cb(null, client);223 });224 },225 function(client, cb) {226 client.once("close", cb);227 client.end();228 }229 ], function(err) {230 if(err) {231 done();232 return;233 }234 done(new Error("No error thrown"));235 });236 });237 it("should reload the current config if killed with SIGHUP on a Linux-based OS", function(done) {238 if(os.platform() === "win32") return done();239 args.push("adduser");240 args.push("myuser");241 args.push("mypass");242 args.push("--credentials");243 var cloned = null;244 steed.waterfall([245 function(cb) {246 tmp.file(cb);247 },248 function(path, fd, ignore, cb) {249 args.push(path);250 cloned = [].concat(args);251 cloned[2] = "rmuser";252 mosca.cli(args, cb);253 },254 function(cb) {255 mosca.cli(["node", "mosca", "--credentials", cloned[cloned.length - 1]], cb);256 },257 function(server, cb) {258 servers.unshift(server);259 setTimeout(function() {260 mosca.cli(cloned, cb);261 }, 300);262 },263 function(cb) {264 process.kill(process.pid, 'SIGHUP');265 setTimeout(cb, 50);266 },267 function(cb) {268 var options = { port: 1883, username: "myuser", password: "mypass" };269 var client = mqtt.connect(options);270 client.once("error", cb);271 client.once("connect", function() {272 client.once("close", cb);273 client.end();274 });275 }276 ], function(err) {277 if(err) {278 done();279 return;280 }281 done(new Error("should have errored"));282 });283 });284 it("should save the credentials.json as a formatted JSON when adding", function(done) {285 args.push("adduser");286 args.push("myuser");287 args.push("mypass");288 args.push("--credentials");289 tmp.file(function (err, path, fd) {290 if (err) {291 done(err);292 return;293 }294 args.push(path);295 mosca.cli(args, function () {296 var content = fs.readFileSync(path);297 expect(JSON.stringify(JSON.parse(content), null, 2)).to.equal(content.toString('utf8'));298 done();299 });300 });301 });302 it("should save the credentials.json as a formatted JSON when removing", function(done) {303 args.push("adduser");304 args.push("myuser");305 args.push("mypass");306 args.push("--credentials");307 tmp.file(function (err, path, fd) {308 if (err) {309 done(err);310 return;311 }312 args.push(path);313 var cloned = [].concat(args);314 cloned[2] = "rmuser";315 cloned[3] = "anotheruser";316 mosca.cli(args, function () {317 mosca.cli(cloned, function () {318 var content = fs.readFileSync(path);319 expect(JSON.stringify(JSON.parse(content), null, 2)).to.equal(content.toString('utf8'));320 done();321 });322 });323 });324 });325 it("should create a memory persistence object", function(done) {326 var s = startServer(done, function(server) {327 expect(server.persistence).to.be.instanceOf(mosca.persistence.Memory);328 });329 });330 it("should create a leveldb with the --db flag", function(done) {331 tmp.dir(function (err, path, fd) {332 if (err) {333 done(err);334 return;335 }336 args.push("--db");337 args.push(path);338 startServer(done, function(server) {339 expect(server.persistence).to.be.instanceOf(mosca.persistence.LevelUp);340 expect(server.persistence.options.path).to.eql(path);341 });342 });343 });344 describe("with --key and --cert", function() {345 beforeEach(function() {346 args.push("--key");347 args.push(SECURE_KEY);348 args.push("--cert");349 args.push(SECURE_CERT);350 });351 it("should pass key and cert to the server", function(done) {352 startServer(done, function(server) {353 expect(server.opts.secure.keyPath).to.eql(SECURE_KEY);354 expect(server.opts.secure.certPath).to.eql(SECURE_CERT);355 });356 });357 it("should support the --secure-port flag", function(done) {358 var port = nextPort();359 args.push("--secure-port");360 args.push(port);361 startServer(done, function(server) {362 expect(server.opts.secure.port).to.eql(port);363 });364 });365 it("should set the secure port by default at 8883", function(done) {366 startServer(done, function(server) {367 expect(server.opts.secure.port).to.eql(8883);368 });369 });370 it("should pass the --non-secure flag to the server", function(done) {371 args.push("--non-secure");372 startServer(done, function(server) {373 expect(server.opts.allowNonSecure).to.eql(true);374 });375 });376 it("should allow to set the https port", function(done) {377 args.push("--https-port");378 args.push("3000");379 startServer(done, function(server) {380 expect(server.opts.https.port).to.eql(3000);381 });382 });383 it("should serve a HTTPS static directory", function(done) {384 args.push("--https-port");385 args.push("3000");386 args.push("--https-static");387 args.push("/path/to/nowhere");388 startServer(done, function(server) {389 expect(server.opts.https.static).to.eql("/path/to/nowhere");390 });391 });392 it("should serve a HTTPS browserify bundle", function(done) {393 args.push("--https-port");394 args.push("3000");395 args.push("--https-bundle");396 startServer(done, function(server) {397 expect(server.opts.https.bundle).to.eql(true);398 });399 });400 });401 it("should allow to set the http port", function(done) {402 args.push("--http-port");403 args.push("3000");404 startServer(done, function(server) {405 expect(server.opts.http.port).to.eql(3000);406 });407 });408 it("should allow to limit the server only to http", function(done) {409 args.push("--http-port");410 args.push("3000");411 args.push("--only-http");412 startServer(done, function(server) {413 expect(server.opts.http.port).to.eql(3000);414 });415 });416 it("should serve a HTTP static directory", function(done) {417 args.push("--http-port");418 args.push("3000");419 args.push("--http-static");420 args.push("/path/to/nowhere");421 startServer(done, function(server) {422 expect(server.opts.http.static).to.eql("/path/to/nowhere");423 });424 });425 it("should serve a HTTP browserify bundle", function(done) {426 args.push("--http-port");427 args.push("3000");428 args.push("--http-bundle");429 startServer(done, function(server) {430 expect(server.opts.http.bundle).to.eql(true);431 });432 });433 it("should have stats enabled by default", function(done) {434 var s = startServer(done, function(server) {435 expect(server.opts.stats).to.equal(true);436 });437 });438 it("should allow to disable stats", function(done) {439 args.push("--disable-stats");440 var s = startServer(done, function(server) {441 expect(server.opts.stats).to.equal(false);442 });443 });444 it("should allow to specify a broker id", function(done) {445 args.push("--broker-id");446 args.push("44cats");447 var s = startServer(done, function(server) {448 expect(server.id).to.equal("44cats");449 });450 });451 it("should specify an interface to bind to", function(done) {452 args.push("--host");453 args.push("127.0.0.1");454 startServer(done, function(server) {455 expect(server.opts.host).to.eql("127.0.0.1");456 });457 });...
jschilicatServerTest.js
Source:jschilicatServerTest.js
...24 ok(this.attach, "Server must support this.attach(...)");25 ok(this.attachRestlet, "Server must support this.Restlet(...)");26 }27 });28 JsChilicat.startServer({});29 // JsChilicat.disposeServers();30});31test("JsChilicat.start will not fail without Servers.", function() {32 expect(0);33 JsChilicat.startServer({});34});35test("Server Instance", function() {36 expect(3);37 JsChilicat.newServer({38 init: function(context) {39 ok(!this.called, "init is called twice");40 ok(context, "Context parameter is not defined [JsChilicat.server.init()].");41 equals("value", context.someValue, "Context.someValue is not defined.");42 this.called = true;43 }44 });45 JsChilicat.startServer({ someValue: "value" });46 JsChilicat.disposeServers();47 JsChilicat.startServer({ someValue: "second call - should not work" });48});49test("Server.startServer Exception", function() {50 expect(6);51 JsChilicat.newServer({52 init: function(context) {53 ok(false, "Should no be called");54 }55 });56 try {57 JsChilicat.startServer(null);58 } catch(e) {59 ok(e.type, "Exception must have type attribute");60 equals("undefined", e.type, "Type is incorrect");61 }62 try {63 JsChilicat.startServer();64 } catch(e) {65 ok(e.type, "Exception must have type attribute");66 equals("undefined", e.type, "Type is incorrect");67 }68 try {69 JsChilicat.startServer(undefined);70 } catch(e) {71 ok(e.type, "Exception must have type attribute");72 equals("undefined", e.type, "Type is incorrect");73 }74 75 JsChilicat.disposeServers();76});77test("Mutliple Server Instance", function() {78 expect(6);79 var impl = {80 init: function(context) {81 ok(!this.called, "init is called twice");82 ok(context, "Context parameter is not defined [JsChilicat.server.init()].");83 equals("value", context.someValue, "Context.someValue is not defined.");84 this.called = true;85 }86 }87 // register multiple instances.88 JsChilicat.newServer(impl);89 JsChilicat.newServer(impl);90 JsChilicat.startServer({ someValue: "value" });91 JsChilicat.disposeServers();92});93test("Server.init.attach", function() {94 expect(5);95 JsChilicat.newServer({96 init: function(context) {97 ok(true, "Init must be called.");98 this.attach("/index.html", "../other.html");99 this.attach("/resourses", "../resourceFolder");100 try {101 this.attach();102 } catch(e) {103 ok(e.type, "Exception must have type attribute");104 equals("undefined", e.type, "Type is incorrect");105 }106 try {107 this.attach("string");108 } catch(e) {109 ok(e.type, "Exception must have type attribute");110 equals("undefined", e.type, "Type is incorrect");111 }112 }113 });114 JsChilicat.startServer({ someValue: "value" });115 JsChilicat.disposeServers();...
mese-dev-server copy.js
Source:mese-dev-server copy.js
...38 // çå¾
æ建å®æï¼å¯å¨æéå¯webæå¡39 compiler.hooks.done.tap("ææç¼è¯å®æ", async () => {40 if (server) {41 server.close(async () => {42 server = await startServer([outputPath, host, port]);43 });44 } else {45 server = await startServer([outputPath, host, port]);46 }47 });48});49function startServer(options) {50 if (startServer.id) clearTimeout(startServer.id);51 return new Promise((resolve) => {52 startServer.id = setTimeout(() => {53 const spinner = ora("Starting server...").start();54 const [meseAppDir, host, port] = options;55 const server = new Server({56 meseAppDir,57 host,58 port,59 success: (port) => {60 resolve(server);61 spinner.stop();62 const arr = [63 chalk.bgGreenBright.black(" Mese "),...
main_571.js
Source:main_571.js
...13//depoly web file,for dev14//exec('gulp');15options.isAutoProxy=true;16var startServer=helper.startServerHander(options);17startServer(require('./app/zj/proxy-19571'),19571);18/*19startServer(require('./app/zj/proxy-10570'),10570);20startServer(require('./app/zj/proxy-10571'),10571);21startServer(require('./app/zj/proxy-10572'),10572);22startServer(require('./app/zj/proxy-10573'),10573);23startServer(require('./app/zj/proxy-10574'),10574);24startServer(require('./app/zj/proxy-10575'),10575);25startServer(require('./app/zj/proxy-10576'),10576);26startServer(require('./app/zj/proxy-10577'),10577);27startServer(require('./app/zj/proxy-10578'),10578);28startServer(require('./app/zj/proxy-10579'),10579);29startServer(require('./app/zj/proxy-10580'),10580);30startServer(require('./app/zj/proxy-10010'),10010);31startServer(require('./app/zj/proxy-10021'),10021);*/32helper. copy(path.resolve("app/zj/injected/!injected-19571.js") , path.resolve("public/zj/injected-19571.js"))33//for ä¸æéè¦GBK js34/*35function utf82gbk(file){36 var iconv = require('iconv-lite');37 var data= fs.readFileSync(file) ;38 data= iconv.decode(data, 'utf-8');39 data=iconv.encode(data,'gbk')40 fs.writeFileSync(file,data) ;41}42setTimeout(function(){43 var file = path.resolve("public/zj/injected-19571.js");44 utf82gbk(file);45 },3000);46*/47//startServer(require('./app/zj_hz_cg/app_zj_hz_cg'),3333);48//http://www.jb51.net/article/48467.htm49//http://www.jb51.net/article/52118.htm50//http://www.zjsgat.gov.cn:8080/was/portals/car_lllegal_query.jsp...
run-tests.js
Source:run-tests.js
1const { spawn } = require('child_process');2const { kill } = require('cross-port-killer');3const env = Object.create(process.env);4env.BROWSER = 'none';5env.TEST = true;6// flag to prevent multiple test7let once = false;8const startServer = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['start'], {9 env,10});11startServer.stderr.on('data', data => {12 // eslint-disable-next-line13 console.log(data.toString());14});15startServer.on('exit', () => {16 kill(process.env.PORT || 8000);17});18// eslint-disable-next-line19console.log('Starting development server for e2e tests...');20startServer.stdout.on('data', data => {21 // eslint-disable-next-line22 console.log(data.toString());23 if (!once && data.toString().indexOf('App running at') >= 0) {24 // eslint-disable-next-line25 once = true;26 console.log('Development server is started, ready to run tests.');27 const testCmd = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['test'], {28 stdio: 'inherit',29 });30 testCmd.on('exit', code => {31 startServer.kill();32 process.exit(code);33 });34 }...
StartServer.js
Source:StartServer.js
...4 // private app: Application;5 // private server: Server;6 // private io: IoServer;7 function StartServer() {8 this.startServer();9 }10 StartServer.prototype.startServer = function () {11 // this.server.listen(PORT, () => console.log('\x1b[36m', 'Serwer uruchomiony'));12 console.log("WESZLO");13 };14 StartServer.bootstrap = function () {15 return new StartServer();16 };17 return StartServer;18}());...
index.js
Source:index.js
1const startServer = require('./utils/startServer');2module.exports = startServer;3module.exports.default = startServer;4module.exports.startServer = startServer;...
Using AI Code Generation
1var appiumServer = new AppiumServer();2appiumServer.startServer();3var appiumServer = new AppiumServer();4appiumServer.startServer();5var appiumServer = new AppiumServer();6appiumServer.stopServer();7var appiumServer = new AppiumServer();8appiumServer.startServer({9 appiumJSPath: "C:\\Program Files (x86)\\Appium\\node_modules\\appium\\bin\\appium.js",
Using AI Code Generation
1var AppiumServer = require('./AppiumServer');2AppiumServer.startServer();3AppiumServer.stopServer();4var exec = require('child_process').exec;5var AppiumServer = function () {6 this.startServer = function () {7 exec('appium', function (error, stdout, stderr) {8 console.log(stdout);9 console.log(stderr);10 if (error !== null) {11 console.log('exec error: ' + error);12 }13 });14 };15 this.stopServer = function () {16 exec('killall node', function (error, stdout, stderr) {17 console.log(stdout);18 console.log(stderr);19 if (error !== null) {20 console.log('exec error: ' + error);21 }22 });23 };24};25module.exports = new AppiumServer();
Using AI Code Generation
1const AppiumServer = require('./appium-server');2const appiumServer = new AppiumServer();3appiumServer.startServer();4const { exec } = require('child_process');5const path = require('path');6const isWin = process.platform === 'win32';7const isMac = process.platform === 'darwin';8class AppiumServer {9 constructor() {10 this.appiumServerPath = path.resolve(__dirname, '..', 'node_modules', '.bin', 'appium');11 if (isWin) {12 this.appiumServerPath = this.appiumServerPath + '.cmd';13 }14 }15 startServer() {16 exec(this.appiumServerPath, (error, stdout, stderr) => {17 if (error) {18 console.log(`Error: ${error.message}`);19 return;20 }21 if (stderr) {22 console.log(`Stderr: ${stderr}`);23 return;24 }25 console.log(`Stdout: ${stdout}`);26 });27 }28}29module.exports = AppiumServer;
Using AI Code Generation
1var AppiumServer = require('./appiumServer.js');2var appiumServer = new AppiumServer();3appiumServer.startServer();4appiumServer.stopServer();5var exec = require('child_process').exec;6var child;7var AppiumServer = function(){8 this.startServer = function(){9 child = exec('appium', function(error, stdout, stderr){10 if(error !== null){11 console.log('exec error:' + error);12 }13 });14 };15 this.stopServer = function(){16 process.kill(child.pid);17 };18};19module.exports = AppiumServer;
Using AI Code Generation
1var AppiumServer = require('./AppiumServer.js');2var appiumServer = new AppiumServer();3var appiumServer.startServer();4var appiumServer = function(){5 this.startServer = function(){6 var appium = require('appium');7 var args = {8 };9 appium.main(args, function(err, appium) {10 if (err) {11 console.error('Appium startup failure: ' + err.message);12 return;13 }14 console.log('Appium is running');15 });16 }17}18module.exports = appiumServer;
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!!