How to use execute method in mountebank

Best JavaScript code snippet using mountebank

commands.js

Source:commands.js Github

copy

Full Screen

...85importClass(org.ow2.proactive_grid_cloud_portal.cli.cmd.AbstractCommand);86importClass(com.google.common.collect.ObjectArrays);87var currentContext = ApplicationContextImpl.currentContext();88function url(url) {89 execute(new SetUrlCommand('' + url));90}91function silent() {92 execute(new SetSilentCommand());93}94function exit() {95 currentContext.setProperty(AbstractIModeCommand.TERMINATE, true);96}97function printWelcomeMsg() {98 print('Type help() for interactive help \r\n');99 if (getUser(currentContext) == null && getCredFile(currentContext) == null) {100 print('Warning: You are not currently logged in.\r\n');101 }102}103function prints() {104 execute(new PrintSessionCommand());105}106function printError(error, currentContext) {107 print("An error occurred while executing the command:\r\n" + error.message + "\r\n");108 if (AbstractCommand.isDebugModeEnabled(currentContext)) {109 if (error.javaException != null) {110 error.javaException.printStackTrace();111 } else {112 error.printStackTrace(); // if executed with JDK8113 }114 }115}116function reconnect() {117 if (getCredFile(currentContext) != null) {118 loginwithcredentials(getCredFile(currentContext));119 } else if (getUser(currentContext) != null) {120 login(getUser(currentContext));121 } else {122 print('use either login(username) or loginwithcredentials(cred-file) function\r\n')123 }124}125function debug(flag) {126 execute(new SetDebugModeCommand(string(flag)));127}128function string(obj) {129 return '' + obj;130}131function getUser(context) {132 return context.getProperty(LoginCommand.USERNAME, stringClass);133}134function getCredFile(context) {135 return context.getProperty(LoginWithCredentialsCommand.CRED_FILE, stringClass);136}137function execute(cmd) {138 var tryAfterReLogin = false;139 try {140 cmd.execute(currentContext);141 } catch (e) {142 if (e.javaException instanceof CLIException143 && (e.javaException.reason() == CLIException.REASON_UNAUTHORIZED_ACCESS)144 && currentContext.getProperty(AbstractLoginCommand.PROP_PERSISTED_SESSION, java.lang.Boolean.TYPE, false)) {145 tryAfterReLogin = true;146 } else {147 printError(e, currentContext);148 }149 }150 if (tryAfterReLogin) {151 currentContext.setProperty(AbstractLoginCommand.PROP_RENEW_SESSION, java.lang.Boolean.TRUE);152 try {153 if (getCredFile(currentContext) != null) {154 execute(new LoginWithCredentialsCommand(getCredFile(currentContext)));155 } else if (getUser(currentContext) != null) {156 execute(new LoginCommand(getUser(currentContext)));157 }158 cmd.execute(currentContext);159 } catch (e) {160 printError(e, currentContext);161 }162 }163}164function schedulerlogin(user) {165 currentContext.setSessionId('');166 execute(new LoginSchedCommand('' + user));167}168function login(user) {169 currentContext.setProperty(AbstractLoginCommand.PROP_RENEW_SESSION, true);170 execute(new LoginCommand('' + user));171}172function loginwithcredentials(pathname) {173 currentContext.setProperty(AbstractLoginCommand.PROP_RENEW_SESSION, true);174 execute(new LoginWithCredentialsCommand('' + pathname));175}176// scheduler177function schedulerhelp() {178 execute(new SchedJsHelpCommand());179}180function putcredential(key, value) {181 execute(new PutThirdPartyCredentialCommand(string(key), string(value)));182}183function removecredential(key) {184 execute(new RemoveThirdPartyCredentialCommand(string(key)));185}186function listcredentials() {187 execute(new ThirdPartyCredentialKeySetCommand());188}189function submit(pathname, variables, genericInfos) {190 if (typeof genericInfos == 'undefined') {191 if (typeof variables == 'undefined') {192 execute(new SubmitJobCommand('' + pathname));193 } else {194 execute(new SubmitJobCommand('' + pathname, '' + variables));195 }196 } else {197 execute(new SubmitJobCommand('' + pathname, '' + variables, '' + genericInfos));198 }199}200function resubmit(pathname, variables, genericInfos) {201 if (typeof variables == 'undefined') {202 execute(new ReSubmitJobCommand([string(pathname)]));203 } else {204 execute(new ReSubmitJobCommand(new Array([string(pathname)], variables, genericInfos)));205 }206}207function submitarchive(pathname, variables) {208 if (typeof variables == 'undefined') {209 execute(new SubmitJobCommand([string(pathname)]));210 } else {211 execute(new SubmitJobCommand(ObjectArrays.concat([string(pathname)], variables, java.lang.String)));212 }213}214function jobpriority(jobId, priority) {215 execute(new ChangeJobPriorityCommand('' + jobId, '' + priority));216}217function pausejob(jobId) {218 execute(new PauseJobCommand('' + jobId));219}220function resumejob(jobId) {221 execute(new ResumeJobCommand('' + jobId));222}223function resumeAllPausedTasks(jobId) {224 execute(new ResumeAllPausedTasksCommand('' + jobId));225}226function restartAllInErrorTasks(jobId) {227 execute(new RestartAllInErrorTasksCommand('' + jobId));228}229function resumeAllPausedTasksAndRestartAllInErrorTasks(jobId) {230 execute(new ResumeAllPausedTasksAndRestartAllInErrorTasksCommand('' + jobId));231}232function killjob(jobId) {233 execute(new KillJobCommand('' + jobId));234}235function removejob(jobId) {236 execute(new RemoveJobCommand('' + jobId));237}238function jobstate(jobId) {239 execute(new GetJobStateCommand('' + jobId));240}241function listjobs(x, y) {242 if (typeof x == 'undefined') {243 execute(new ListJobCommand());244 } else if (typeof y == 'undefined') {245 execute(new ListJobCommand('latest=' + x));246 } else {247 execute(new ListJobCommand(['from=' + x, 'limit=' + y]));248 }249}250/*251 * The following parameters have different meaning whether252 * listtasks is called with 1,2,3 or 4 parameters.253 * 1 parameter : arg1 is the jobId254 * 2 parameters : arg1 is the jobId255 * arg2 is the tag256 * 3 parameters : arg1 is the jobId257 * arg2 is the offset258 * arg3 is the limit259 * 4 parameters : arg1 is the jobId260 * arg2 is the tag261 * arg3 is the offset262 * arg4 is the limit263 * 264 */265function listtasks(arg1, arg2, arg3, arg4) {266 // There is only one parameter, the jobId267 if (arguments.length == 1 && typeof arg1 != 'undefined') {268 execute(ListJobTasksCommand.LJTCommandBuilder.newInstance().jobId(arg1).instance());269 }270 // Two arguments: jobId and tag271 if (arguments.length == 2 && typeof arg1 != 'undefined'272 && typeof arg2 != 'undefined') {273 execute(ListJobTasksCommand.LJTCommandBuilder.newInstance().jobId(arg1).tag(arg2).instance());274 }275 // Three parameters: jobId, offset and limit276 if (arguments.length == 3 && typeof arg1 != 'undefined'277 && typeof arg2 != 'undefined' && typeof arg3 != 'undefined') {278 execute(ListJobTasksCommand.LJTCommandBuilder.newInstance().jobId(arg1).offset(arg2).limit(arg3).instance());279 }280 // Four parameters: jobId, tag, offset and limit281 // We don't parse any parameters after the fourth one282 if (arguments.length >= 4 && typeof arg1 != 'undefined'283 && typeof arg2 != 'undefined' && typeof arg3 != 'undefined'284 && typeof arg4 != 'undefined') {285 execute(ListJobTasksCommand.LJTCommandBuilder.newInstance().jobId(arg1).tag(arg2).offset(arg3).limit(arg4).instance());286 }287}288function schedulerstats() {289 execute(new SchedStatsCommand());290}291function jobresult(jobId, tag) {292 if(typeof tag == 'undefined'){293 execute(new GetJobResultCommand('' + jobId));294 }295 else{296 execute(new GetJobResultCommand('' + jobId, tag));297 }298}299function joboutput(jobId, tag) {300 if(typeof tag == 'undefined'){301 execute(new GetJobOutputCommand('' + jobId));302 }303 else{304 execute(new GetJobOutputCommand('' + jobId, tag));305 }306}307function jobcontent(jobId) {308 execute(new GetJobContentCommand('' + jobId))309}310function taskresult(jobId, taskId) {311 execute(new GetTaskResultCommand('' + jobId, '' + taskId));312}313function taskoutput(jobId, taskId) {314 execute(new GetTaskOutputCommand('' + jobId, '' + taskId));315}316/*317 * The following parameters have different meaning whether318 * taskstates is called with 1,2,3 or 4 parameters.319 * 1 parameter : arg1 is the jobId320 * 2 parameters : arg1 is the jobId321 * arg2 is the tag322 * 3 parameters : arg1 is the jobId323 * arg2 is the offset324 * arg3 is the limit325 * 4 parameters : arg1 is the jobId326 * arg2 is the tag327 * arg3 is the offset328 * arg4 is the limit329 * 330 */331function taskstates(arg1, arg2, arg3, arg4){332 // There is only one parameter, the jobId333 if (arguments.length == 1 && typeof arg1 != 'undefined') {334 execute(new ListTaskStatesCommand(arg1));335 }336 // Two arguments: jobId and tag337 if (arguments.length == 2 && typeof arg1 != 'undefined'338 && typeof arg2 != 'undefined') {339 execute(new ListTaskStatesCommand(arg1, arg2));340 }341 // Three parameters: jobId, offset and limit342 if (arguments.length == 3 && typeof arg1 != 'undefined'343 && typeof arg2 != 'undefined' && typeof arg3 != 'undefined') {344 execute(new ListTaskStatesCommand(arg1, arg2, arg3));345 }346 // Four parameters: jobId, tag, offset and limit347 // We don't parse any parameters after the fourth one348 if (arguments.length >= 4 && typeof arg1 != 'undefined'349 && typeof arg2 != 'undefined' && typeof arg3 != 'undefined'350 && typeof arg4 != 'undefined') {351 execute(new ListTaskStatesCommand(arg1, arg2, arg3, arg4));352 }353}354function preempttask(jobId, taskId) {355 execute(new PreemptTaskCommand('' + jobId, '' + taskId));356}357function restarttask(jobId, taskId) {358 execute(new RestartTaskCommand('' + jobId, '' + taskId));359}360function restartInErrorTask(jobId, taskId) {361 execute(new RestartInErrorTaskCommand('' + jobId, '' + taskId));362}363function restartRunningTask(jobId, taskId) {364 execute(new RestartRunningTaskCommand('' + jobId, '' + taskId));365}366function uploadfile(spaceName, filePath, fileName, localFile) {367 execute(new UploadFileCommand(string(spaceName), string(filePath),string(fileName), string(localFile)));368}369function downloadfile(spaceName, pathName, localFile) {370 execute(new DownloadFileCommand(string(spaceName), string(pathName), string(localFile))) ;371}372function livelog(jobId) {373 execute(new LiveLogCommand(string(jobId)));374}375function installpackage(packagePath) {376 execute(new InstallPackageCommand(string(packagePath)));377}378function start() {379 execute(new StartCommand());380}381function stop() {382 execute(new StopCommand());383}384function pause() {385 execute(new PauseCommand());386}387function resume() {388 execute(new ResumeCommand());389}390function freeze() {391 execute(new FreezeCommand());392}393function kill() {394 execute(new KillCommand());395}396function script(path, args) {397 execute(new EvalScriptCommand('' + path, '' + args));398}399function linkrm(rmUrl) {400 execute(new LinkRmCommand('' + rmUrl));401}402// rm403function rmhelp() {404 execute(new RmJsHelpCommand());405}406function addnode(nodeUrl, nodeSource) {407 if (nodeSource) {408 execute(new AddNodeCommand('' + nodeUrl, '' + nodeSource));409 } else {410 execute(new AddNodeCommand('' + nodeUrl));411 }412}413function removenode(nodeUrl, preempt) {414 execute(new RemoveNodeCommand('' + nodeUrl, preempt));415}416function definens(nodeSource, infrastructure, policy, nodesRecoverable) {417 execute(new SetInfrastructureCommand(infrastructure));418 execute(new SetPolicyCommand(policy));419 if(typeof nodesRecoverable == 'undefined'){420 execute(new DefineNodeSourceCommand('' + nodeSource));421 }422 else{423 execute(new DefineNodeSourceCommand('' + nodeSource, '' + nodesRecoverable));424 }425}426function editns(nodeSource, infrastructure, policy, nodesRecoverable) {427 execute(new SetInfrastructureCommand(infrastructure));428 execute(new SetPolicyCommand(policy));429 execute(new EditNodeSourceCommand('' + nodeSource, '' + nodesRecoverable));430}431function updatensparam(nodeSource, infrastructure, policy) {432 execute(new SetInfrastructureCommand(infrastructure));433 execute(new SetPolicyCommand(policy));434 execute(new UpdateDynamicParametersCommand('' + nodeSource));435}436function createns(nodeSource, infrastructure, policy, nodesRecoverable) {437 execute(new SetInfrastructureCommand(infrastructure));438 execute(new SetPolicyCommand(policy));439 if(typeof nodesRecoverable == 'undefined'){440 execute(new CreateNodeSourceCommand('' + nodeSource));441 }442 else{443 execute(new CreateNodeSourceCommand('' + nodeSource, '' + nodesRecoverable));444 }445}446function deployns(nodeSourceName) {447 execute(new DeployNodeSourceCommand('' + nodeSourceName));448}449function undeployns(nodeSourceName, preempt) {450 if(typeof preempt == 'undefined'){451 execute(new UndeployNodeSourceCommand('' + nodeSourceName));452 } else {453 execute(new UndeployNodeSourceCommand('' + nodeSourceName, preempt));454 }455}456function removens(nodeSource, preempt) {457 execute(new RemoveNodeSourceCommand('' + nodeSource, preempt));458}459function locknodes(nodeUrl) {460 var result = [];461 for (var i = 0; i < arguments.length; i++) {462 result[i] = arguments[i];463 }464 execute(new LockNodeCommand(result));465}466function unlocknodes(nodeUrl) {467 var result = [];468 for (var i = 0; i < arguments.length; i++) {469 result[i] = arguments[i];470 }471 execute(new UnlockNodeCommand(result));472}473function listnodes(nodeSource) {474 if (nodeSource) {475 execute(new ListNodeCommand('' + nodeSource));476 } else {477 execute(new ListNodeCommand());478 }479}480function listns() {481 execute(new ListNodeSourceCommand());482}483function nodeinfo(nodeUrl) {484 execute(new GetNodeInfoCommand('' + nodeUrl));485}486function rmthreaddump() {487 execute(new GetRMThreadDumpCommand());488}489function nodethreaddump(nodeUrl) {490 execute(new GetNodeThreadDumpCommand('' + nodeUrl));491}492function listinfrastructures() {493 execute(new ListInfrastructureCommand());494}495function listpolicies() {496 execute(new ListPolicyCommand());497}498function topology() {499 execute(new GetTopologyCommand());500}501function rmstats() {502 execute(new RmStatsCommand());503}504function shutdown() {505 execute(new ShutdownCommand());506}507function help() {508 execute(new JsHelpCommand());509}510function version() {511 execute(new JsVersionCommand())512}...

Full Screen

Full Screen

JobSchedulerSpec.js

Source:JobSchedulerSpec.js Github

copy

Full Screen

...37 var js = new JobScheduler([2.0, // JobType.TEXTURE38 0.0, // JobType.PROGRAM39 0.0]); // JobType.BUFFER40 var job = new MockJob();41 var executed = js.execute(job, JobType.TEXTURE);42 expect(executed).toEqual(true);43 expect(job.executed).toEqual(true);44 expect(js._totalUsedThisFrame).toEqual(1.0);45 expect(js._budgets[JobType.TEXTURE].total).toEqual(2.0);46 expect(js._budgets[JobType.TEXTURE].usedThisFrame).toEqual(1.0);47 });48 it('disableThisFrame does not execute a job', function() {49 var js = new JobScheduler([2.0, 0.0, 0.0]);50 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);51 js.disableThisFrame();52 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(false);53 });54 it('executes different job types', function() {55 var js = new JobScheduler([1.0, 1.0, 1.0]);56 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);57 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(true);58 expect(js.execute(new MockJob(), JobType.BUFFER)).toEqual(true);59 expect(js._totalUsedThisFrame).toEqual(3.0);60 var budgets = js._budgets;61 expect(budgets[JobType.TEXTURE].usedThisFrame).toEqual(1.0);62 expect(budgets[JobType.PROGRAM].usedThisFrame).toEqual(1.0);63 expect(budgets[JobType.BUFFER].usedThisFrame).toEqual(1.0);64 });65 it('executes a second job', function() {66 var js = new JobScheduler([2.0, 0.0, 0.0]);67 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);68 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);69 expect(js._totalUsedThisFrame).toEqual(2.0);70 expect(js._budgets[JobType.TEXTURE].usedThisFrame).toEqual(2.0);71 });72 it('does not execute second job (exceeds total time)', function() {73 var js = new JobScheduler([1.0, 0.0, 0.0]);74 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);75 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(false);76 expect(js._budgets[JobType.TEXTURE].starvedThisFrame).toEqual(true);77 });78 it('executes a second job (TEXTURE steals PROGRAM budget)', function() {79 var js = new JobScheduler([1.0, 1.0, 0.0]);80 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);81 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);82 expect(js._totalUsedThisFrame).toEqual(2.0);83 var budgets = js._budgets;84 expect(budgets[JobType.TEXTURE].usedThisFrame).toEqual(1.0);85 expect(budgets[JobType.TEXTURE].starvedThisFrame).toEqual(true);86 expect(budgets[JobType.PROGRAM].usedThisFrame).toEqual(0.0);87 expect(budgets[JobType.PROGRAM].stolenFromMeThisFrame).toEqual(1.0);88 expect(budgets[JobType.PROGRAM].starvedThisFrame).toEqual(false);89 // There are no budgets left to steal from90 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(false);91 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(true); // Allowed once per frame92 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(false);93 expect(budgets[JobType.PROGRAM].starvedThisFrame).toEqual(true);94 });95 it('does not steal in the same frame', function() {96 var js = new JobScheduler([1.0, 1.0, 1.0]);97 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);98 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(true);99 expect(js.execute(new MockJob(), JobType.BUFFER)).toEqual(true);100 // Exhaust budget for all job types in the first frame101 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(false);102 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(false);103 expect(js.execute(new MockJob(), JobType.BUFFER)).toEqual(false);104 // In this next frame, no job type can steal from another since105 // they all exhausted their budgets in the previous frame106 js.resetBudgets();107 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);108 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(false);109 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(true);110 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(false);111 expect(js.execute(new MockJob(), JobType.BUFFER)).toEqual(true);112 expect(js.execute(new MockJob(), JobType.BUFFER)).toEqual(false);113 });114 it('does not steal from starving job types over multiple frames', function() {115 var js = new JobScheduler([1.0, 1.0, 0.0]);116 // Exhaust in first frame117 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);118 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true); // Stolen from PROGRAM119 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(false);120 js.resetBudgets();121 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(true);122 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(false); // Can't steal from TEXTURE123 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);124 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(false);125 js.resetBudgets();126 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(true);127 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(false); // Can't steal from TEXTURE yet128 js.resetBudgets();129 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(true);130 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(true); // Can steal from TEXTURE since it wasn't exhausted last frame131 });132 it('Allows progress on all job types once per frame', function() {133 var js = new JobScheduler([1.0, 1.0, 1.0]);134 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true);135 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true); // Steal from PROGRAM136 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true); // Steal from BUFFER137 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(false);138 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(true); // Still gets to make progress once this frame139 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(false);140 expect(js.execute(new MockJob(), JobType.BUFFER)).toEqual(true); // Still gets to make progress once this frame141 expect(js.execute(new MockJob(), JobType.BUFFER)).toEqual(false);142 });143 it('Long job still allows progress on other job types once per frame', function() {144 // Job duration is always 1.0 in the tests so shorten budget145 var js = new JobScheduler([0.5, 0.2, 0.2]);146 expect(js.execute(new MockJob(), JobType.TEXTURE)).toEqual(true); // Goes over total budget147 expect(js.execute(new MockJob(), JobType.PROGRAM)).toEqual(true); // Still gets to make progress once this frame148 expect(js.execute(new MockJob(), JobType.BUFFER)).toEqual(true); // Still gets to make progress once this frame149 });150 it('constructor throws when budgets.length is not JobType.NUMBER_OF_JOB_TYPES', function() {151 expect(function() {152 return new JobScheduler([1.0]);153 }).toThrowDeveloperError();154 });...

Full Screen

Full Screen

test-authorizer.js

Source:test-authorizer.js Github

copy

Full Screen

1function terminateTest()2{3 if (window.layoutTestController)4 layoutTestController.notifyDone();5}6function logAndTerminateTest(message, error)7{8 log(message + ": " + error.message);9 terminateTest();10}11function cleanup(db)12{13 db.transaction(function(tx) {14 tx.executeSql("DROP TABLE IF EXISTS Test;");15 tx.executeSql("DROP INDEX IF EXISTS TestIndex;");16 tx.executeSql("DROP VIEW IF EXISTS TestView;");17 tx.executeSql("DROP TRIGGER IF EXISTS TestTrigger;");18 }, function(error) { logAndTerminateTest("Cleanup failed", error); });19}20function statementSuccessCallback(statementType)21{22 log(statementType + " statement succeeded.");23}24function statementErrorCallback(statementType, error)25{26 log(statementType + " statement failed: " + error.message);27 return false;28}29function executeStatement(tx, statement, operation)30{31 tx.executeSql(statement, [],32 function(result) { statementSuccessCallback(operation); },33 function(tx, error) { return statementErrorCallback(operation, error); });34}35function createTableCallback(tx)36{37 executeStatement(tx, "CREATE TABLE Test (Foo int);", "SQLITE_CREATE_TABLE");38}39function createStatementsCallback(tx)40{41 executeStatement(tx, "CREATE INDEX TestIndex ON Test (Foo);", "SQLITE_CREATE_INDEX");42 // Even though the following query should trigger a SQLITE_CREATE_TEMP_INDEX operation43 // (according to http://www.sqlite.org/tempfiles.html), it doesn't, and I'm not aware44 // of any other way to trigger this operation. So we'll skip it for now.45 //executeStatement(tx, "SELECT * FROM Test WHERE Foo IN (1, 2, 3);", "SQLITE_CREATE_TEMP_INDEX");46 executeStatement(tx, "CREATE TEMP TABLE TestTempTable (Foo int);", "SQLITE_CREATE_TEMP_TABLE");47 executeStatement(tx, "CREATE TEMP TRIGGER TestTempTrigger INSERT ON Test BEGIN SELECT COUNT(*) FROM Test; END;", "SQLITE_CREATE_TEMP_TRIGGER");48 executeStatement(tx, "CREATE TEMP VIEW TestTempView AS SELECT COUNT(*) FROM Test;", "SQLITE_CREATE_TEMP_VIEW");49 executeStatement(tx, "CREATE TRIGGER TestTrigger INSERT ON Test BEGIN SELECT COUNT(*) FROM Test; END;", "SQLITE_CREATE_TRIGGER");50 executeStatement(tx, "CREATE VIEW TestView AS SELECT COUNT(*) FROM Test;", "SQLITE_CREATE_VIEW");51 executeStatement(tx, "CREATE VIRTUAL TABLE TestVirtualTable USING MissingModule;", "SQLITE_CREATE_VTABLE");52}53function otherStatementsCallback(tx)54{55 executeStatement(tx, "SELECT COUNT(*) FROM Test;", "SQLITE_READ");56 executeStatement(tx, "SELECT COUNT(*) FROM Test;", "SQLITE_SELECT");57 executeStatement(tx, "DELETE FROM Test;", "SQLITE_DELETE");58 executeStatement(tx, "INSERT INTO Test VALUES (1);", "SQLITE_INSERT");59 executeStatement(tx, "UPDATE Test SET Foo = 2 WHERE Foo = 1;", "SQLITE_UPDATE");60 executeStatement(tx, "PRAGMA cache_size;", "SQLITE_PRAGMA");61 executeStatement(tx, "ALTER TABLE Test RENAME TO TestTable;", "SQLITE_ALTER_TABLE");62 // Rename the table back to its original name63 executeStatement(tx, "ALTER TABLE TestTable RENAME To Test;", "SQLITE_ALTER_TABLE");64 executeStatement(tx, "BEGIN TRANSACTION;", "SQLITE_TRANSACTION");65 executeStatement(tx, "ATTACH main AS TestMain;", "SQLITE_ATTACH");66 executeStatement(tx, "DETACH TestMain;", "SQLITE_DETACH");67 executeStatement(tx, "REINDEX;", "SQLITE_REINDEX");68 executeStatement(tx, "ANALYZE;", "SQLITE_ANALYZE");69 // SQLITE_FUNCTION: allowed write mode70 // There is no SQL/Javascript API to add user-defined functions to SQLite,71 // so we cannot test this operation72}73function dropStatementsCallback(tx)74{75 executeStatement(tx, "DROP INDEX TestIndex;", "SQLITE_DROP_INDEX");76 // SQLITE_DROP_TEMP_INDEX: allowed in write mode77 // Not sure how to test this: temp indexes are automatically dropped when78 // the database is closed, but HTML5 doesn't specify a closeDatabase() call.79 executeStatement(tx, "DROP TABLE TestTempTable;", "SQLITE_DROP_TEMP_TABLE");80 executeStatement(tx, "DROP TRIGGER TestTempTrigger;", "SQLITE_DROP_TEMP_TRIGGER");81 executeStatement(tx, "DROP VIEW TestTempView;", "SQLITE_DROP_TEMP_VIEW");82 executeStatement(tx, "DROP TRIGGER TestTrigger;", "SQLITE_DROP_TRIGGER");83 executeStatement(tx, "DROP VIEW TestView;", "SQLITE_DROP_VIEW");84 // SQLITE_DROP_VTABLE: allowed in write mode85 // Not sure how to test this: we cannot create a virtual table because we do not86 // have SQL/Javascript APIs to register a module that implements a virtual table.87 // Therefore, trying to drop a virtual table will always fail (no such table)88 // before even getting to the authorizer.89 executeStatement(tx, "DROP TABLE Test;", "SQLITE_DROP_TABLE");90}91function testReadWriteMode(db)92{93 db.transaction(function(tx) {94 createTableCallback(tx);95 createStatementsCallback(tx);96 otherStatementsCallback(tx);97 dropStatementsCallback(tx);98 },99 function(error) { logAndTerminateTest("Write transaction failed", error); },100 function() { log("Write transaction succeeded."); });101}102function testReadOnlyMode(db)103{104 // Test the 'CREATE TABLE' operation; it should be disallowed105 db.readTransaction(createTableCallback,106 function(error) { logAndTerminateTest("Read 'CREATE TABLE' transaction failed", error); });107 // In order to test all other 'CREATE' operations, we must create the table first108 db.transaction(createTableCallback,109 function(error) { logAndTerminateTest("Write 'CREATE TABLE' transaction failed", error); });110 db.readTransaction(createStatementsCallback,111 function(error) { logAndTerminateTest("Read 'CREATE' transaction failed", error); });112 // In order to test the 'DROP' and 'other' operations, we need to first create the respective entities113 db.transaction(createStatementsCallback,114 function(error) { logAndTerminateTest("Write 'CREATE' transaction failed", error); });115 db.readTransaction(otherStatementsCallback,116 function(error) { logAndTerminateTest("Read 'other' transaction failed", error); });117 // Hack: insert an empty write transaction to guaratee that these transactions are executed sequentially118 db.transaction(function(tx) { });119 db.readTransaction(dropStatementsCallback,120 function(error) { logAndTerminateTest("Read 'DROP' transaction failed", error); },121 function() { log("Read transactions succeeded."); terminateTest(); });122}123function runTest()124{125 var db = openDatabaseWithSuffix("AuthorizerTest", "1.0", "Tests the database authorizer.", 32768);126 cleanup(db);127 testReadWriteMode(db);128 testReadOnlyMode(db);...

Full Screen

Full Screen

test-authorizer-sync.js

Source:test-authorizer-sync.js Github

copy

Full Screen

1function cleanup(db)2{3 db.transaction(function(tx) {4 tx.executeSql("DROP TABLE IF EXISTS Test");5 tx.executeSql("DROP INDEX IF EXISTS TestIndex");6 tx.executeSql("DROP VIEW IF EXISTS TestView");7 tx.executeSql("DROP TRIGGER IF EXISTS TestTrigger");8 });9}10function executeStatement(tx, statement, operation)11{12 try {13 tx.executeSql(statement);14 postMessage(operation + " allowed.");15 } catch (err) {16 postMessage(operation + " not allowed: " + err + " (" + err.code + ")");17 }18}19function createTableCallback(tx)20{21 executeStatement(tx, "CREATE TABLE Test (Foo int)", "SQLITE_CREATE_TABLE");22}23function createStatementsCallback(tx)24{25 executeStatement(tx, "CREATE INDEX TestIndex ON Test (Foo)", "SQLITE_CREATE_INDEX");26 // Even though the following query should trigger a SQLITE_CREATE_TEMP_INDEX operation27 // (according to http://www.sqlite.org/tempfiles.html), it doesn't, and I'm not aware28 // of any other way to trigger this operation. So we'll skip it for now.29 //executeStatement(tx, "SELECT * FROM Test WHERE Foo IN (1, 2, 3)", "SQLITE_CREATE_TEMP_INDEX");30 executeStatement(tx, "CREATE TEMP TABLE TestTempTable (Foo int)", "SQLITE_CREATE_TEMP_TABLE");31 executeStatement(tx, "CREATE TEMP TRIGGER TestTempTrigger INSERT ON Test BEGIN SELECT COUNT(*) FROM Test; END", "SQLITE_CREATE_TEMP_TRIGGER");32 executeStatement(tx, "CREATE TEMP VIEW TestTempView AS SELECT COUNT(*) FROM Test", "SQLITE_CREATE_TEMP_VIEW");33 executeStatement(tx, "CREATE TRIGGER TestTrigger INSERT ON Test BEGIN SELECT COUNT(*) FROM Test; END", "SQLITE_CREATE_TRIGGER");34 executeStatement(tx, "CREATE VIEW TestView AS SELECT COUNT(*) FROM Test", "SQLITE_CREATE_VIEW");35 // We should try to create a virtual table using fts3, when WebKit's sqlite library supports it.36 executeStatement(tx, "CREATE VIRTUAL TABLE TestVirtualTable USING UnsupportedModule", "SQLITE_CREATE_VTABLE");37}38function otherStatementsCallback(tx)39{40 executeStatement(tx, "SELECT COUNT(*) FROM Test", "SQLITE_READ");41 executeStatement(tx, "SELECT COUNT(*) FROM Test", "SQLITE_SELECT");42 executeStatement(tx, "DELETE FROM Test", "SQLITE_DELETE");43 executeStatement(tx, "INSERT INTO Test VALUES (1)", "SQLITE_INSERT");44 executeStatement(tx, "UPDATE Test SET Foo = 2 WHERE Foo = 1", "SQLITE_UPDATE");45 executeStatement(tx, "PRAGMA cache_size", "SQLITE_PRAGMA");46 executeStatement(tx, "ALTER TABLE Test RENAME TO TestTable", "SQLITE_ALTER_TABLE");47 // Rename the table back to its original name48 executeStatement(tx, "ALTER TABLE TestTable RENAME To Test", "SQLITE_ALTER_TABLE");49 executeStatement(tx, "BEGIN TRANSACTION", "SQLITE_TRANSACTION");50 executeStatement(tx, "ATTACH main AS TestMain", "SQLITE_ATTACH");51 executeStatement(tx, "DETACH TestMain", "SQLITE_DETACH");52 executeStatement(tx, "REINDEX", "SQLITE_REINDEX");53 executeStatement(tx, "ANALYZE", "SQLITE_ANALYZE");54 // SQLITE_FUNCTION: allowed in write mode55 // There is no SQL/Javascript API to add user-defined functions to SQLite,56 // so we cannot test this operation57}58function dropStatementsCallback(tx)59{60 executeStatement(tx, "DROP INDEX TestIndex", "SQLITE_DROP_INDEX");61 // SQLITE_DROP_TEMP_INDEX: allowed in write mode62 // Not sure how to test this: temp indexes are automatically dropped when63 // the database is closed, but HTML5 doesn't specify a closeDatabase() call.64 executeStatement(tx, "DROP TABLE TestTempTable", "SQLITE_DROP_TEMP_TABLE");65 executeStatement(tx, "DROP TRIGGER TestTempTrigger", "SQLITE_DROP_TEMP_TRIGGER");66 executeStatement(tx, "DROP VIEW TestTempView", "SQLITE_DROP_TEMP_VIEW");67 executeStatement(tx, "DROP TRIGGER TestTrigger", "SQLITE_DROP_TRIGGER");68 executeStatement(tx, "DROP VIEW TestView", "SQLITE_DROP_VIEW");69 // SQLITE_DROP_VTABLE: allowed in write mode70 // Not sure how to test this: we cannot create a virtual table because we do not71 // have SQL/Javascript APIs to register a module that implements a virtual table.72 // Therefore, trying to drop a virtual table will always fail (no such table)73 // before even getting to the authorizer.74 executeStatement(tx, "DROP TABLE Test", "SQLITE_DROP_TABLE");75}76function testReadWriteMode(db)77{78 db.transaction(function(tx) {79 postMessage("Beginning write transaction:");80 createTableCallback(tx);81 createStatementsCallback(tx);82 otherStatementsCallback(tx);83 dropStatementsCallback(tx);84 postMessage("Write transaction succeeded.\n");85 });86}87function testReadOnlyMode(db)88{89 postMessage("Beginning read transactions:");90 // Test the 'CREATE TABLE' operation; it should be disallowed91 db.readTransaction(createTableCallback);92 // In order to test all other 'CREATE' operations, we must create the table first93 db.transaction(createTableCallback);94 db.readTransaction(createStatementsCallback);95 // In order to test the 'DROP' and 'other' operations, we need to first create the respective entities96 db.transaction(createStatementsCallback);97 db.readTransaction(otherStatementsCallback);98 db.readTransaction(dropStatementsCallback);99 postMessage("Read transactions succeeded.");100}101var db = openDatabaseSync("TestAuthorizerTest", "1.0", "Test the database authorizer.", 1);102cleanup(db);103testReadWriteMode(db);104testReadOnlyMode(db);...

Full Screen

Full Screen

actions.js

Source:actions.js Github

copy

Full Screen

...19 contentTypeValues: () => fromJS({requestContentType: "one", responseContentType: "two"})20 }21 }22 // When23 let executeFn = execute({ path: "/one", method: "get"})24 executeFn(system)25 // Then26 expect(system.specActions.executeRequest.calls[0].arguments[0]).toEqual({27 fetch: 1,28 method: "get",29 pathName: "/one",30 parameters: {31 values: 232 },33 requestContentType: "one",34 responseContentType: "two",35 spec: {36 spec: 137 }38 })39 })40 xit("should allow passing _extra_ properties to executeRequest", function(){41 // Given42 const system = {43 fn: {},44 specActions: {45 executeRequest: createSpy()46 },47 specSelectors: {48 spec: () => fromJS({}),49 parameterValues: () => fromJS({}),50 contentTypeValues: () => fromJS({})51 }52 }53 // When54 let executeFn = execute({ hi: "hello" })55 executeFn(system)56 // Then57 expect(system.specActions.executeRequest.calls[0].arguments[0]).toInclude({hi: "hello"})58 })59 })60 describe("executeRequest", function(){61 xit("should call fn.execute with arg ", function(){62 const system = {63 fn: {64 execute: createSpy().andReturn(Promise.resolve())65 },66 specActions: {67 setResponse: createSpy()68 }...

Full Screen

Full Screen

createCommandSpec.js

Source:createCommandSpec.js Github

copy

Full Screen

1defineSuite([2 'Widgets/createCommand',3 'Specs/getArguments',4 'ThirdParty/knockout'5 ], function(6 createCommand,7 getArguments,8 knockout) {9 'use strict';10 var spyFunction;11 var spyFunctionReturnValue = 5;12 beforeEach(function() {13 spyFunction = jasmine.createSpy('spyFunction').and.returnValue(spyFunctionReturnValue);14 });15 it('works with default value of canExecute', function() {16 var command = createCommand(spyFunction);17 expect(command.canExecute).toBe(true);18 expect(command()).toBe(spyFunctionReturnValue);19 expect(spyFunction).toHaveBeenCalled();20 });21 it('throws when canExecute value is false', function() {22 var command = createCommand(spyFunction, false);23 expect(function() {24 command();25 }).toThrowDeveloperError();26 expect(spyFunction).not.toHaveBeenCalled();27 });28 it('throws without a func parameter', function() {29 expect(function() {30 return createCommand(undefined);31 }).toThrowDeveloperError();32 });33 it('works with custom canExecute observable', function() {34 var canExecute = knockout.observable(false);35 var command = createCommand(spyFunction, canExecute);36 expect(command.canExecute).toBe(false);37 expect(function() {38 command();39 }).toThrowDeveloperError();40 expect(spyFunction).not.toHaveBeenCalled();41 canExecute(true);42 expect(command.canExecute).toBe(true);43 expect(command()).toBe(spyFunctionReturnValue);44 expect(spyFunction).toHaveBeenCalled();45 });46 it('calls pre/post events', function() {47 var command = createCommand(spyFunction);48 var myArg = {};49 var beforeExecuteSpy = jasmine.createSpy('beforeExecute');50 command.beforeExecute.addEventListener(beforeExecuteSpy);51 var afterExecuteSpy = jasmine.createSpy('afterExecute');52 command.afterExecute.addEventListener(afterExecuteSpy);53 expect(command(myArg)).toBe(spyFunctionReturnValue);54 expect(beforeExecuteSpy.calls.count()).toEqual(1);55 expect(beforeExecuteSpy).toHaveBeenCalledWith({56 cancel : false,57 args : getArguments(myArg)58 });59 expect(afterExecuteSpy.calls.count()).toEqual(1);60 expect(afterExecuteSpy).toHaveBeenCalledWith(spyFunctionReturnValue);61 });62 it('cancels a command if beforeExecute sets cancel to true', function() {63 var command = createCommand(spyFunction);64 var myArg = {};65 var beforeExecuteSpy = jasmine.createSpy('beforeExecute').and.callFake(function(info) {66 info.cancel = true;67 });68 command.beforeExecute.addEventListener(beforeExecuteSpy);69 var afterExecuteSpy = jasmine.createSpy('afterExecute');70 command.afterExecute.addEventListener(afterExecuteSpy);71 expect(command(myArg)).toBeUndefined();72 expect(beforeExecuteSpy.calls.count()).toEqual(1);73 expect(afterExecuteSpy).not.toHaveBeenCalled();74 });...

Full Screen

Full Screen

job.js

Source:job.js Github

copy

Full Screen

1const matchUtils = require('./match');2const compileUtils = require('./compile');3const executeUtils = require('./execute');4const codeStatusUtils = require('./codeStatus');5const compileBoxUtils = require('./compileBox');6const CompileQueue = require('../models').compilequeue;7const ExecuteQueue = require('../models').executequeue;8const sendJob = async () => {9 const idleCompileBoxId = await compileBoxUtils.getIdleCompileBox();10 if (idleCompileBoxId === -1) return;11 const compileJob = await compileUtils.getOldestCompileJob();12 const executeJob = await executeUtils.getOldestExecuteJob();13 let jobtype;14 if (compileJob && executeJob) {15 if (compileJob.createdAt.getTime() > executeJob.createdAt.getTime()) {16 jobtype = 'execute';17 } else {18 jobtype = 'compile';19 }20 } else if (compileJob && !executeJob) {21 jobtype = 'compile';22 } else if (executeJob && !compileJob) {23 jobtype = 'execute';24 } else {25 return;26 }27 if (jobtype === 'compile') {28 const { userId, commitHash } = compileJob;29 await compileUtils.setCompileQueueJobStatus(compileJob.id, 'COMPILING');30 await compileUtils.sendCompileJob(userId, idleCompileBoxId, commitHash);31 await codeStatusUtils.setUserCodeStatus(userId, 'Idle');32 await CompileQueue.destroy({33 where: { id: compileJob.id },34 });35 } else {36 await executeUtils.setExecuteQueueJobStatus(executeJob.id, 'EXECUTING');37 const {38 popFromQueue,39 matchId,40 score1,41 score2,42 interestingness,43 } = await executeUtils.sendExecuteJob(44 executeJob.gameId,45 idleCompileBoxId,46 executeJob.userId1,47 executeJob.userId2,48 executeJob.aiId,49 executeJob.mapId,50 executeJob.type,51 executeJob.dll1Path,52 executeJob.dll2Path,53 );54 if (popFromQueue) {55 await ExecuteQueue.destroy({56 where: {57 id: executeJob.id,58 },59 });60 if (executeJob.type === 'USER_MATCH') {61 await matchUtils.updateMatchResults(matchId, score1, score2, interestingness);62 }63 }64 }65 sendJob();66};67const startJobs = async () => {68 const compileJobs = (await CompileQueue.update({ status: 'QUEUED' }, { where: {} }))[0];69 const executeJobs = (await ExecuteQueue.update({ status: 'QUEUED' }, { where: {} }))[0];70 for (let i = 0; i < compileJobs + executeJobs; i += 1) {71 sendJob();72 }73};74module.exports = {75 sendJob,76 startJobs,...

Full Screen

Full Screen

createCommand.js

Source:createCommand.js Github

copy

Full Screen

1define([2 '../Core/defaultValue',3 '../Core/defined',4 '../Core/defineProperties',5 '../Core/DeveloperError',6 '../Core/Event',7 '../ThirdParty/knockout'8 ], function(9 defaultValue,10 defined,11 defineProperties,12 DeveloperError,13 Event,14 knockout) {15 'use strict';16 /**17 * Create a Command from a given function, for use with ViewModels.18 *19 * A Command is a function with an extra <code>canExecute</code> observable property to determine20 * whether the command can be executed. When executed, a Command function will check the21 * value of <code>canExecute</code> and throw if false. It also provides events for when22 * a command has been or is about to be executed.23 *24 * @exports createCommand25 *26 * @param {Function} func The function to execute.27 * @param {Boolean} [canExecute=true] A boolean indicating whether the function can currently be executed.28 */29 function createCommand(func, canExecute) {30 //>>includeStart('debug', pragmas.debug);31 if (!defined(func)) {32 throw new DeveloperError('func is required.');33 }34 //>>includeEnd('debug');35 canExecute = defaultValue(canExecute, true);36 var beforeExecute = new Event();37 var afterExecute = new Event();38 function command() {39 //>>includeStart('debug', pragmas.debug);40 if (!command.canExecute) {41 throw new DeveloperError('Cannot execute command, canExecute is false.');42 }43 //>>includeEnd('debug');44 var commandInfo = {45 args : arguments,46 cancel : false47 };48 var result;49 beforeExecute.raiseEvent(commandInfo);50 if (!commandInfo.cancel) {51 result = func.apply(null, arguments);52 afterExecute.raiseEvent(result);53 }54 return result;55 }56 command.canExecute = canExecute;57 knockout.track(command, ['canExecute']);58 defineProperties(command, {59 beforeExecute : {60 value : beforeExecute61 },62 afterExecute : {63 value : afterExecute64 }65 });66 return command;67 }68 return createCommand;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var imposter = {3 {4 {5 is: {6 }7 }8 }9};10mb.create(imposter, function (error, imposter) {11 if (error) {12 console.error(error);13 }14 else {15 }16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var port = 2525;3 {4 {5 {6 is: {7 headers: {8 },9 body: JSON.stringify({message: 'Hello World'})10 }11 }12 }13 }14];15mb.create(port, imposters, function () {16 console.log('mountebank running on port', port);17});18var mb = require('mountebank');19var port = 2525;20 {21 {22 {23 is: {24 headers: {25 },26 body: JSON.stringify({message: 'Hello World'})27 }28 }29 }30 }31];32mb.create(port, imposters, function () {33 console.log('mountebank running on port', port);34});35var mb = require('mountebank');36var port = 2525;37 {38 {39 {40 is: {41 headers: {42 },43 body: JSON.stringify({message: 'Hello World'})44 }45 }46 }47 }48];49mb.create(port, imposters, function () {50 console.log('mountebank running on port', port);51});52var mb = require('mountebank');53var port = 2525;54 {55 {56 {57 is: {58 headers: {59 },

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var imposters = {3 {4 {5 is: {6 }7 }8 }9};10mb.create(imposters, function (error, imposter) {11 console.log(imposter.port);12});13var mb = require('mountebank');14var imposters = {15 {16 {17 is: {18 }19 }20 }21};22mb.create(imposters, function (error, imposter) {23 console.log(imposter.port);24});25var mb = require('mountebank');26var imposters = {27 {28 {29 is: {30 }31 }32 }33};34mb.create(imposters, function (error, imposter) {35 console.log(imposter.port);36});37var mb = require('mountebank');38var imposters = {39 {40 {41 is: {42 }43 }44 }45};46mb.create(imposters, function (error, imposter) {47 console.log(imposter.port);48});49var mb = require('mountebank');50var imposters = {51 {52 {53 is: {54 }55 }56 }57};58mb.create(imposters, function (error, imposter) {59 console.log(imposter.port);60});61var mb = require('mountebank');62var imposters = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const mb = require('mountebank');2const port = 2525;3const imposters = {4 {5 {6 is: {7 headers: {8 },9 }10 }11 }12};13mb.create(port, imposters)14 .then(() => console.log('Imposter created'))15 .catch(err => console.error(`Error creating imposter: ${err.message}`));16{17 {18 {19 "is": {20 "headers": {21 },22 }23 }24 }25}

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var stub = {3 {4 is: {5 headers: {6 },7 body: {8 "data": {9 }10 }11 }12 }13};14var imposter = {15};16var predicate = {17 equals: {18 }19};20var proxy = {21 {22 matches: {23 }24 }25};26var imposter = {27 _links: {28 self: {29 }30 },31 {32 query: {},33 headers: {34 'Accept-Language': 'en-US,en;q=0.9'35 },36 body: {},37 _links: {38 self: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2request.post({3 json: {4 {5 {6 equals: {7 }8 }9 {10 is: {11 headers: {12 },13 body: JSON.stringify({ message: 'Hello World!' })14 }15 }16 }17 }18});19const request = require('supertest');20const app = require('../app');21describe('Test the root path', () => {22 test('It should response the GET method', () => {23 return request(app)24 .post('/test')25 .then(response => {26 expect(response.statusCode).toBe(200);27 });28 });29});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var mbHelper = mb.create();3var imposter = {4 stubs: [{5 responses: [{6 is: {7 }8 }]9 }]10};11mbHelper.createImposter(imposter).then(function (imposter) {12 console.log(imposter.port);13});14var mb = require('mountebank');15var imposter = {16 stubs: [{17 responses: [{18 is: {19 }20 }]21 }]22};23mb.createImposter(imposter, function (error, imposter) {24 console.log(imposter.port);25});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var fs = require('fs');3var path = require('path');4var http = require('http');5var imposter = JSON.parse(fs.readFileSync(path.join(__dirname, 'imposter.json'), 'utf8'));6var port = 2525;7mb.create(port, imposter, function (error, imposter) {8if (error) {9console.error('Failed to create imposter', error);10} else {11console.log('Imposter created');12}13});14{15{16{17"is": {18}19}20}21}22{23"scripts": {24},25"dependencies": {26}27}

Full Screen

Using AI Code Generation

copy

Full Screen

1var http = require('http');2var options = {3 headers: {4 }5};6var req = http.request(options, function(res) {7 res.setEncoding('utf8');8 res.on('data', function (chunk) {9 console.log("body: " + chunk);10 });11});12req.write(JSON.stringify({13 {14 {15 "is": {16 "headers": {17 },18 "body": "{\"message\": \"Hello world\"}"19 }20 }21 }22}));23req.end();24var mb = require('mountebank');25var imposter = {26 {27 {28 is: {29 headers: {30 },31 body: '{"message": "Hello world"}'32 }33 }34 }35};36mb.create(imposter, function (error, imposter) {37 console.log(imposter.port);38});39var mb = require('mountebank');40mb.get(4545, function (error, imposter) {41 console.log(imposter.stubs);42});43var mb = require('mountebank');44mb.del(4545, function (error, imposter) {45 console.log(imposter);46});

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 mountebank 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