How to use executor method in sinon

Best JavaScript code snippet using sinon

MemoryExecutorMixin-test.js

Source:MemoryExecutorMixin-test.js Github

copy

Full Screen

1const EventEmitter = require('events');2const { expect, assert } = require('chai');3const LeanES = require("../../../src/leanes/index.js").default;4const {5 initialize, partOf, nameBy, meta, constant, mixin, method6} = LeanES.NS;7describe('MemoryExecutorMixin', () => {8 describe('.new', () => {9 it('should create new memory resque executor', () => {10 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';11 const viewComponent = {12 id: 'view-component'13 };14 @initialize15 class Test extends LeanES {16 @nameBy static __filename = 'Test';17 @meta static object = {};18 @constant ROOT = `${__dirname}/../command/config`;19 }20 @initialize21 @mixin(LeanES.NS.MemoryExecutorMixin)22 @partOf(Test)23 class MemoryResqueExecutor extends LeanES.NS.Mediator {24 @nameBy static __filename = 'MemoryResqueExecutor';25 @meta static object = {};26 }27 const executor = MemoryResqueExecutor.new();28 executor.setName(executorName);29 executor.setViewComponent(viewComponent);30 assert.instanceOf(executor, MemoryResqueExecutor);31 });32 });33 describe('.listNotificationInterests', () => {34 it('should check notification interests list', () => {35 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';36 const viewComponent = {37 id: 'view-component'38 };39 @initialize40 class Test extends LeanES {41 @nameBy static __filename = 'Test';42 @meta static object = {};43 @constant ROOT = `${__dirname}/../command/config`;44 }45 @initialize46 @mixin(LeanES.NS.MemoryExecutorMixin)47 @partOf(Test)48 class MemoryResqueExecutor extends LeanES.NS.Mediator {49 @nameBy static __filename = 'MemoryResqueExecutor';50 @meta static object = {};51 }52 const executor = MemoryResqueExecutor.new();53 executor.setName(executorName);54 executor.setViewComponent(viewComponent);55 assert.deepEqual(executor.listNotificationInterests(), [LeanES.NS.JOB_RESULT, LeanES.NS.START_RESQUE]);56 });57 });58 describe('.stop', () => {59 it('should stop executor', () => {60 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';61 const viewComponent = {62 id: 'view-component'63 };64 @initialize65 class Test extends LeanES {66 @nameBy static __filename = 'Test';67 @meta static object = {};68 @constant ROOT = `${__dirname}/../command/config`;69 }70 @initialize71 @mixin(LeanES.NS.MemoryExecutorMixin)72 @partOf(Test)73 class MemoryResqueExecutor extends LeanES.NS.Mediator {74 @nameBy static __filename = 'MemoryResqueExecutor';75 @meta static object = {};76 }77 const executor = MemoryResqueExecutor.new();78 executor.setName(executorName);79 executor.setViewComponent(viewComponent);80 executor.stop();81 assert.isTrue(executor._isStopped);82 });83 });84 describe('.onRemove', () => {85 it('should handle remove event', async () => {86 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';87 const viewComponent = {88 id: 'view-component'89 };90 @initialize91 class Test extends LeanES {92 @nameBy static __filename = 'Test';93 @meta static object = {};94 @constant ROOT = `${__dirname}/../command/config`;95 }96 @initialize97 @mixin(LeanES.NS.MemoryExecutorMixin)98 @partOf(Test)99 class MemoryResqueExecutor extends LeanES.NS.Mediator {100 @nameBy static __filename = 'MemoryResqueExecutor';101 @meta static object = {};102 }103 const executor = MemoryResqueExecutor.new();104 executor.setName(executorName);105 executor.setViewComponent(viewComponent);106 await executor.onRemove();107 assert.isTrue(executor._isStopped);108 });109 });110 describe('.define', () => {111 it('should define processor (success)', async () => {112 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';113 const viewComponent = {114 id: 'view-component'115 };116 @initialize117 class Test extends LeanES {118 @nameBy static __filename = 'Test';119 @meta static object = {};120 @constant ROOT = `${__dirname}/../command/config`;121 }122 @initialize123 @mixin(LeanES.NS.MemoryExecutorMixin)124 @partOf(Test)125 class MemoryResqueExecutor extends LeanES.NS.Mediator {126 @nameBy static __filename = 'MemoryResqueExecutor';127 @meta static object = {};128 }129 const executor = MemoryResqueExecutor.new();130 executor.setName(executorName);131 executor.setViewComponent(viewComponent);132 executor._definedProcessors = {};133 executor._concurrencyCount = {};134 const QUEUE_NAME = 'TEST_QUEUE';135 const concurrency = 4;136 const testTrigger = new EventEmitter();137 executor.define(QUEUE_NAME, { concurrency }, (job, done) => {138 assert(job);139 testTrigger.once('DONE', (options) => {140 done(options);141 });142 });143 const processorData = executor._definedProcessors[QUEUE_NAME];144 assert.equal(processorData.concurrency, concurrency);145 const {146 listener,147 concurrency: processorConcurrency148 } = processorData;149 assert.equal(processorConcurrency, concurrency);150 const job = {151 status: 'scheduled'152 };153 listener(job);154 assert.equal(executor._concurrencyCount[QUEUE_NAME], 1);155 assert.propertyVal(job, 'status', 'running');156 assert.isDefined(job.startedAt);157 const promise = new Promise((resolve) => {158 testTrigger.once('DONE', resolve);159 });160 testTrigger.emit('DONE');161 await promise;162 assert.equal(executor._concurrencyCount[QUEUE_NAME], 0);163 assert.propertyVal(job, 'status', 'completed');164 });165 it('should define processor (fail)', async () => {166 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';167 const viewComponent = {168 id: 'view-component'169 };170 @initialize171 class Test extends LeanES {172 @nameBy static __filename = 'Test';173 @meta static object = {};174 @constant ROOT = `${__dirname}/../command/config`;175 }176 @initialize177 @mixin(LeanES.NS.MemoryExecutorMixin)178 @partOf(Test)179 class MemoryResqueExecutor extends LeanES.NS.Mediator {180 @nameBy static __filename = 'MemoryResqueExecutor';181 @meta static object = {};182 }183 const executor = MemoryResqueExecutor.new();184 executor.setName(executorName);185 executor.setViewComponent(viewComponent);186 executor._definedProcessors = {};187 executor._concurrencyCount = {};188 const QUEUE_NAME = 'TEST_QUEUE';189 const concurrency = 4;190 const testTrigger = new EventEmitter();191 executor.define(QUEUE_NAME, { concurrency }, (job, done) => {192 assert(job);193 testTrigger.once('DONE', (options) => {194 done(options);195 });196 });197 const processorData = executor._definedProcessors[QUEUE_NAME];198 assert.equal(processorData.concurrency, concurrency);199 const {200 listener,201 concurrency: processorConcurrency202 } = processorData;203 assert.equal(processorConcurrency, concurrency);204 const job = {205 status: 'scheduled'206 };207 listener(job);208 assert.equal(executor._concurrencyCount[QUEUE_NAME], 1);209 assert.propertyVal(job, 'status', 'running');210 assert.isDefined(job.startedAt);211 const promise = new Promise((resolve) => {212 testTrigger.once('DONE', resolve);213 });214 testTrigger.emit('DONE', {215 error: 'error'216 });217 await promise;218 assert.equal(executor._concurrencyCount[QUEUE_NAME], 0);219 assert.propertyVal(job, 'status', 'failed');220 assert.deepEqual(job.reason, {221 error: 'error'222 });223 });224 });225 describe('.defineProcessors', () => {226 let facade = null;227 afterEach(async () => {228 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;229 });230 it('should define processors', async () => {231 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_001';232 facade = LeanES.NS.Facade.getInstance(KEY);233 @initialize234 class Test extends LeanES {235 @nameBy static __filename = 'Test';236 @meta static object = {};237 @constant ROOT = `${__dirname}/../command/config`;238 }239 @initialize240 @mixin(LeanES.NS.MemoryResqueMixin)241 @partOf(Test)242 class TestResque extends LeanES.NS.Resque {243 @nameBy static __filename = 'TestResque';244 @meta static object = {};245 }246 @initialize247 @mixin(LeanES.NS.MemoryExecutorMixin)248 @partOf(Test)249 class MemoryResqueExecutor extends LeanES.NS.Mediator {250 @nameBy static __filename = 'MemoryResqueExecutor';251 @meta static object = {};252 }253 const resque = TestResque.new();254 resque.setName(LeanES.NS.RESQUE);255 facade.registerProxy(resque);256 resque.create('TEST_QUEUE_1', 4);257 resque.create('TEST_QUEUE_2', 4);258 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';259 const viewComponent = {260 id: 'view-component'261 };262 const executor = MemoryResqueExecutor.new();263 executor.setName(executorName);264 executor.setViewComponent(viewComponent);265 executor.initializeNotifier(KEY);266 executor.setViewComponent(new EventEmitter());267 executor._definedProcessors = {};268 executor._concurrencyCount = {};269 executor._resque = resque;270 await executor.defineProcessors();271 assert.property(executor._definedProcessors, 'TEST_QUEUE_1');272 assert.property(executor._definedProcessors, 'TEST_QUEUE_2');273 });274 });275 describe('.reDefineProcessors', () => {276 let facade = null;277 afterEach(async () => {278 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;279 });280 it('should redefine processors', async () => {281 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_009';282 facade = LeanES.NS.Facade.getInstance(KEY);283 @initialize284 class Test extends LeanES {285 @nameBy static __filename = 'Test';286 @meta static object = {};287 @constant ROOT = `${__dirname}/../command/config`;288 }289 @initialize290 @mixin(LeanES.NS.MemoryResqueMixin)291 @partOf(Test)292 class TestResque extends LeanES.NS.Resque {293 @nameBy static __filename = 'TestResque';294 @meta static object = {};295 }296 @initialize297 @mixin(LeanES.NS.MemoryExecutorMixin)298 @partOf(Test)299 class MemoryResqueExecutor extends LeanES.NS.Mediator {300 @nameBy static __filename = 'MemoryResqueExecutor';301 @meta static object = {};302 }303 const resque = TestResque.new();304 resque.setName(LeanES.NS.RESQUE);305 facade.registerProxy(resque);306 resque.create('TEST_QUEUE_1', 4);307 resque.create('TEST_QUEUE_2', 4);308 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';309 const viewComponent = {310 id: 'view-component'311 };312 const executor = MemoryResqueExecutor.new();313 executor.setName(executorName);314 executor.setViewComponent(viewComponent);315 executor.initializeNotifier(KEY);316 executor.setViewComponent(new EventEmitter());317 executor._definedProcessors = {};318 executor._concurrencyCount = {};319 executor._resque = resque;320 await executor.defineProcessors();321 assert.property(executor._definedProcessors, 'TEST_QUEUE_1');322 assert.property(executor._definedProcessors, 'TEST_QUEUE_2');323 delete executor._definedProcessors;324 await executor.reDefineProcessors();325 assert.property(executor._definedProcessors, 'TEST_QUEUE_1');326 assert.property(executor._definedProcessors, 'TEST_QUEUE_2');327 });328 });329 describe('.onRegister', () => {330 let facade = null;331 afterEach(async () => {332 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;333 });334 it('should setup executor on register', async () => {335 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_002';336 facade = LeanES.NS.Facade.getInstance(KEY);337 const trigger = new EventEmitter();338 @initialize339 class Test extends LeanES {340 @nameBy static __filename = 'Test';341 @meta static object = {};342 @constant ROOT = `${__dirname}/../command/config`;343 }344 @initialize345 @mixin(LeanES.NS.MemoryResqueMixin)346 @partOf(Test)347 class TestResque extends LeanES.NS.Resque {348 @nameBy static __filename = 'TestResque';349 @meta static object = {};350 }351 @initialize352 @mixin(LeanES.NS.MemoryExecutorMixin)353 @partOf(Test)354 class MemoryResqueExecutor extends LeanES.NS.Mediator {355 @nameBy static __filename = 'MemoryResqueExecutor';356 @meta static object = {};357 @method async defineProcessors(...args) {358 await super.defineProcessors(...args);359 trigger.emit('PROCESSORS_DEFINED');360 }361 }362 const resque = TestResque.new();363 resque.setName(LeanES.NS.RESQUE);364 facade.registerProxy(resque);365 resque.create('TEST_QUEUE_1', 4);366 resque.create('TEST_QUEUE_2', 4);367 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';368 const viewComponent = {369 id: 'view-component'370 };371 const executor = MemoryResqueExecutor.new();372 executor.setName(executorName);373 executor.setViewComponent(viewComponent);374 const promise = new Promise((resolve) => {375 trigger.once('PROCESSORS_DEFINED', resolve);376 });377 facade.registerMediator(executor);378 await promise;379 assert.property(executor._definedProcessors, 'TEST_QUEUE_1');380 assert.property(executor._definedProcessors, 'TEST_QUEUE_2');381 });382 });383 describe('.recursion', () => {384 let facade = null;385 afterEach(async () => {386 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;387 });388 it('should recursively call cycle part', async () => {389 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_004';390 facade = LeanES.NS.Facade.getInstance(KEY);391 const trigger = new EventEmitter();392 let test = null;393 @initialize394 class Test extends LeanES {395 @nameBy static __filename = 'Test';396 @meta static object = {};397 @constant ROOT = `${__dirname}/../command/config`;398 }399 @initialize400 @mixin(LeanES.NS.MemoryResqueMixin)401 @partOf(Test)402 class TestResque extends LeanES.NS.Resque {403 @nameBy static __filename = 'TestResque';404 @meta static object = {};405 }406 @initialize407 @mixin(LeanES.NS.MemoryExecutorMixin)408 @partOf(Test)409 class MemoryResqueExecutor extends LeanES.NS.Mediator {410 @nameBy static __filename = 'MemoryResqueExecutor';411 @meta static object = {};412 @method async defineProcessors(...args) {413 await super.defineProcessors(...args);414 trigger.emit('PROCESSORS_DEFINED');415 }416 @method cyclePart(...args) {417 test = true;418 trigger.emit('CYCLE_PART');419 }420 }421 const resque = TestResque.new();422 resque.setName(LeanES.NS.RESQUE);423 facade.registerProxy(resque);424 resque.create(LeanES.NS.DELAYED_JOBS_QUEUE, 4);425 const executor = MemoryResqueExecutor.new(LeanES.NS.RESQUE_EXECUTOR);426 let promise = new Promise((resolve) => {427 trigger.once('PROCESSORS_DEFINED', resolve);428 });429 facade.registerMediator(executor);430 await promise;431 promise = new Promise((resolve) => {432 trigger.once('CYCLE_PART', resolve);433 });434 executor._isStopped = false;435 await executor.recursion();436 await promise;437 assert.isNotNull(test);438 });439 });440 describe('.start', () => {441 let facade = null;442 afterEach(async () => {443 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;444 });445 it('should call recursion', async () => {446 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_005';447 facade = LeanES.NS.Facade.getInstance(KEY);448 const trigger = new EventEmitter();449 let test = null;450 @initialize451 class Test extends LeanES {452 @nameBy static __filename = 'Test';453 @meta static object = {};454 @constant ROOT = `${__dirname}/../command/config`;455 }456 @initialize457 @mixin(LeanES.NS.MemoryResqueMixin)458 @partOf(Test)459 class TestResque extends LeanES.NS.Resque {460 @nameBy static __filename = 'TestResque';461 @meta static object = {};462 }463 @initialize464 @mixin(LeanES.NS.MemoryExecutorMixin)465 @partOf(Test)466 class MemoryResqueExecutor extends LeanES.NS.Mediator {467 @nameBy static __filename = 'MemoryResqueExecutor';468 @meta static object = {};469 @method async defineProcessors(...args) {470 await super.defineProcessors(...args);471 trigger.emit('PROCESSORS_DEFINED');472 }473 @method cyclePart(...args) {474 test = true;475 trigger.emit('CYCLE_PART');476 }477 }478 const resque = TestResque.new();479 resque.setName(LeanES.NS.RESQUE);480 facade.registerProxy(resque);481 resque.create(LeanES.NS.DELAYED_JOBS_QUEUE, 4);482 const executor = MemoryResqueExecutor.new(LeanES.NS.RESQUE_EXECUTOR);483 let promise = new Promise((resolve) => {484 trigger.once('PROCESSORS_DEFINED', resolve);485 });486 facade.registerMediator(executor);487 await promise;488 promise = new Promise((resolve) => {489 trigger.once('CYCLE_PART', resolve);490 });491 await executor.start();492 await promise;493 assert.isNotNull(test);494 });495 });496 describe('.handleNotification', () => {497 let facade = null;498 afterEach(async () => {499 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;500 });501 it('should start resque', async () => {502 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_006';503 facade = LeanES.NS.Facade.getInstance(KEY);504 const trigger = new EventEmitter();505 let test = null;506 @initialize507 class Test extends LeanES {508 @nameBy static __filename = 'Test';509 @meta static object = {};510 @constant ROOT = `${__dirname}/../command/config`;511 }512 @initialize513 @mixin(LeanES.NS.MemoryResqueMixin)514 @partOf(Test)515 class TestResque extends LeanES.NS.Resque {516 @nameBy static __filename = 'TestResque';517 @meta static object = {};518 }519 @initialize520 @mixin(LeanES.NS.MemoryExecutorMixin)521 @partOf(Test)522 class MemoryResqueExecutor extends LeanES.NS.Mediator {523 @nameBy static __filename = 'MemoryResqueExecutor';524 @meta static object = {};525 @method start() {526 test = true;527 trigger.emit('CYCLE_PART');528 }529 }530 const resque = TestResque.new();531 resque.setName(LeanES.NS.RESQUE);532 facade.registerProxy(resque);533 resque.create(LeanES.NS.DELAYED_JOBS_QUEUE, 4);534 const executor = MemoryResqueExecutor.new();535 executor.setName(LeanES.NS.RESQUE_EXECUTOR);536 facade.registerMediator(executor);537 const promise = new Promise(function (resolve) {538 trigger.once('CYCLE_PART', resolve);539 });540 facade.sendNotification(LeanES.NS.START_RESQUE);541 await promise;542 assert.isNotNull(test);543 });544 it('should get result', async () => {545 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_007';546 facade = LeanES.NS.Facade.getInstance(KEY);547 @initialize548 class Test extends LeanES {549 @nameBy static __filename = 'Test';550 @meta static object = {};551 @constant ROOT = `${__dirname}/../command/config`;552 }553 @initialize554 @mixin(LeanES.NS.MemoryResqueMixin)555 @partOf(Test)556 class TestResque extends LeanES.NS.Resque {557 @nameBy static __filename = 'TestResque';558 @meta static object = {};559 }560 @initialize561 @mixin(LeanES.NS.MemoryExecutorMixin)562 @partOf(Test)563 class MemoryResqueExecutor extends LeanES.NS.Mediator {564 @nameBy static __filename = 'MemoryResqueExecutor';565 @meta static object = {};566 }567 const resque = TestResque.new();568 resque.setName(LeanES.NS.RESQUE);569 facade.registerProxy(resque);570 resque.create(LeanES.NS.DELAYED_JOBS_QUEUE, 4);571 const executor = MemoryResqueExecutor.new();572 executor.setName(LeanES.NS.RESQUE_EXECUTOR);573 facade.registerMediator(executor);574 const type = 'TEST_TYPE';575 const promise = new Promise((resolve) => {576 executor.getViewComponent().once(type, resolve);577 });578 const body = {579 test: 'test'580 };581 facade.sendNotification(LeanES.NS.JOB_RESULT, body, type);582 const data = await promise;583 assert.deepEqual(data, body);584 });585 });586 describe('.cyclePart', () => {587 let facade = null;588 afterEach(async () => {589 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;590 });591 it('should start cycle part', async () => {592 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_008';593 facade = LeanES.NS.Facade.getInstance(KEY);594 const trigger = new EventEmitter();595 @initialize596 class Test extends LeanES {597 @nameBy static __filename = 'Test';598 @meta static object = {};599 @constant ROOT = `${__dirname}/command/config`;600 }601 @initialize602 @mixin(LeanES.NS.MemoryResqueMixin)603 @partOf(Test)604 class TestResque extends LeanES.NS.Resque {605 @nameBy static __filename = 'TestResque';606 @meta static object = {};607 }608 @initialize609 @mixin(LeanES.NS.MemoryExecutorMixin)610 @partOf(Test)611 class MemoryResqueExecutor extends LeanES.NS.Mediator {612 @nameBy static __filename = 'MemoryResqueExecutor';613 @meta static object = {};614 }615 @initialize616 @partOf(Test)617 class TestScript extends LeanES.NS.Script {618 @nameBy static __filename = 'TestScript';619 @meta static object = {};620 @method async body(data: ?any): Promise<?any> {621 trigger.emit('CYCLE_PART', data);622 return data623 }624 }625 facade.registerCommand('TEST_SCRIPT', TestScript);626 const resque = TestResque.new();627 resque.setName(LeanES.NS.RESQUE);628 facade.registerProxy(resque);629 await resque.create(LeanES.NS.DELAYED_JOBS_QUEUE, 4);630 const queue = await resque.get(LeanES.NS.DELAYED_JOBS_QUEUE);631 const executor = MemoryResqueExecutor.new();632 executor.setName(LeanES.NS.RESQUE_EXECUTOR);633 facade.registerMediator(executor);634 const promise = new Promise((resolve) => {635 trigger.once('CYCLE_PART', resolve);636 });637 const DELAY_UNTIL = Date.now() + 1000;638 const body = {639 arg1: 'ARG_1',640 arg2: 'ARG_2',641 arg3: 'ARG_3'642 };643 await queue.push('TEST_SCRIPT', body, DELAY_UNTIL);644 facade.sendNotification(LeanES.NS.START_RESQUE);645 const data = await promise;646 assert.deepEqual(data, body);647 });648 });649 describe('.fullQueueName', () => {650 let facade = null;651 afterEach(async () => {652 facade != null ? typeof facade.remove === "function" ? await facade.remove() : void 0 : void 0;653 });654 it('should get full queue name', async () => {655 const KEY = 'TEST_MEMORY_RESQUE_EXECUTOR_010';656 facade = LeanES.NS.Facade.getInstance(KEY);657 @initialize658 class Test extends LeanES {659 @nameBy static __filename = 'Test';660 @meta static object = {};661 @constant ROOT = `${__dirname}/../command/config`;662 }663 @initialize664 @mixin(LeanES.NS.MemoryResqueMixin)665 @partOf(Test)666 class TestResque extends LeanES.NS.Resque {667 @nameBy static __filename = 'TestResque';668 @meta static object = {};669 }670 @initialize671 @mixin(LeanES.NS.MemoryExecutorMixin)672 @partOf(Test)673 class MemoryResqueExecutor extends LeanES.NS.Mediator {674 @nameBy static __filename = 'MemoryResqueExecutor';675 @meta static object = {};676 }677 const resque = TestResque.new();678 resque.setName(LeanES.NS.RESQUE);679 facade.registerProxy(resque);680 resque.create('TEST_QUEUE_1', 4);681 resque.create('TEST_QUEUE_2', 4);682 const executorName = 'TEST_MEMORY_RESQUE_EXECUTOR';683 const viewComponent = {684 id: 'view-component'685 };686 const executor = MemoryResqueExecutor.new();687 executor.setName(executorName);688 executor.setViewComponent(viewComponent);689 facade.registerMediator(executor);690 const fullQueueName = executor.fullQueueName('TEST_QUEUE_1');691 assert.equal(fullQueueName, 'Test|>TEST_QUEUE_1');692 });693 });...

Full Screen

Full Screen

lokiWorker.js

Source:lokiWorker.js Github

copy

Full Screen

1// @flow2// don't import whole `utils` to keep worker size small3import logError from '../../../utils/common/logError'4import invariant from '../../../utils/common/invariant'5import LokiExecutor from './executor'6import { actions, type WorkerAction, type WorkerResponse } from '../common'7const ExecutorProto = LokiExecutor.prototype8const executorMethods = {9 [actions.SETUP]: ExecutorProto.setUp,10 [actions.FIND]: ExecutorProto.find,11 [actions.QUERY]: ExecutorProto.query,12 [actions.COUNT]: ExecutorProto.count,13 [actions.BATCH]: ExecutorProto.batch,14 [actions.UNSAFE_RESET_DATABASE]: ExecutorProto.unsafeResetDatabase,15 [actions.GET_LOCAL]: ExecutorProto.getLocal,16 [actions.SET_LOCAL]: ExecutorProto.setLocal,17 [actions.REMOVE_LOCAL]: ExecutorProto.removeLocal,18 [actions.GET_DELETED_RECORDS]: ExecutorProto.getDeletedRecords,19 [actions.DESTROY_DELETED_RECORDS]: ExecutorProto.destroyDeletedRecords,20}21export default class LokiWorker {22 workerContext: DedicatedWorkerGlobalScope23 executor: ?LokiExecutor24 queue: WorkerAction[] = []25 _actionsExecuting: number = 026 constructor(workerContext: DedicatedWorkerGlobalScope): void {27 this.workerContext = workerContext28 this.workerContext.onmessage = (e: MessageEvent) => {29 const action: WorkerAction = (e.data: any)30 this.enqueue(action)31 }32 }33 enqueue(action: WorkerAction): void {34 this.queue.push(action)35 if (this.queue.length === 1) {36 this.executeNext()37 }38 }39 executeNext(): void {40 const action = this.queue[0]41 invariant(this._actionsExecuting === 0, 'worker should not have ongoing actions') // sanity check42 this.processAction(action)43 }44 onActionDone(response: WorkerResponse): void {45 invariant(this._actionsExecuting === 1, 'worker should be executing 1 action') // sanity check46 this._actionsExecuting = 047 this.queue.shift()48 try {49 this.workerContext.postMessage(response)50 } catch (error) {51 logError(error)52 }53 if (this.queue.length) {54 this.executeNext()55 }56 }57 processAction(action: WorkerAction): void {58 try {59 this._actionsExecuting += 160 const { type, payload, id } = action61 invariant(type in actions, `Unknown worker action ${type}`)62 if (type === actions.SETUP || type === actions.UNSAFE_RESET_DATABASE) {63 this.processActionAsync(action)64 } else {65 // run action66 invariant(this.executor, `Cannot run actions because executor is not set up`)67 const runExecutorAction = executorMethods[type].bind(this.executor)68 const response = runExecutorAction(...payload)69 this.onActionDone({ id, result: { value: response } })70 }71 } catch (error) {72 // Main process only receives error message — this logError is to retain call stack73 logError(error)74 this.onActionDone({ id: action.id, result: { error } })75 }76 }77 async processActionAsync(action: WorkerAction): Promise<void> {78 try {79 const { type, payload, id } = action80 if (type === actions.SETUP) {81 // app just launched, set up executor with options sent82 invariant(!this.executor, `Loki executor already set up - cannot set up again`)83 const [options] = payload84 const executor = new LokiExecutor(options)85 // set up, make this.executor available only if successful86 await executor.setUp()87 this.executor = executor88 this.onActionDone({ id, result: { value: null } })89 } else {90 // run action91 invariant(this.executor, `Cannot run actions because executor is not set up`)92 const runExecutorAction = executorMethods[type].bind(this.executor)93 const response = await runExecutorAction(...payload)94 this.onActionDone({ id, result: { value: response } })95 }96 } catch (error) {97 // Main process only receives error message — this logError is to retain call stack98 logError(error)99 this.onActionDone({ id: action.id, result: { error } })100 }101 }...

Full Screen

Full Screen

capability-executor-not-callable.js

Source:capability-executor-not-callable.js Github

copy

Full Screen

...42var checkPoint = "";43assert.throws(TypeError, function() {44 constructorFunction = function(executor) {45 checkPoint += "a";46 executor();47 checkPoint += "b";48 };49 promise.then();50}, "executor called with no arguments");51assert.sameValue(checkPoint, "ab", "executor called with no arguments");52var checkPoint = "";53assert.throws(TypeError, function() {54 constructorFunction = function(executor) {55 checkPoint += "a";56 executor(undefined, undefined);57 checkPoint += "b";58 };59 promise.then();60}, "executor called with (undefined, undefined)");61assert.sameValue(checkPoint, "ab", "executor called with (undefined, undefined)");62var checkPoint = "";63assert.throws(TypeError, function() {64 constructorFunction = function(executor) {65 checkPoint += "a";66 executor(undefined, function() {});67 checkPoint += "b";68 };69 promise.then();70}, "executor called with (undefined, function)");71assert.sameValue(checkPoint, "ab", "executor called with (undefined, function)");72var checkPoint = "";73assert.throws(TypeError, function() {74 constructorFunction = function(executor) {75 checkPoint += "a";76 executor(function() {}, undefined);77 checkPoint += "b";78 };79 promise.then();80}, "executor called with (function, undefined)");81assert.sameValue(checkPoint, "ab", "executor called with (function, undefined)");82var checkPoint = "";83assert.throws(TypeError, function() {84 constructorFunction = function(executor) {85 checkPoint += "a";86 executor(123, "invalid value");87 checkPoint += "b";88 };89 promise.then();90}, "executor called with (Number, String)");...

Full Screen

Full Screen

capability-executor-called-twice.js

Source:capability-executor-called-twice.js Github

copy

Full Screen

...31}(function() {});32var checkPoint = "";33constructorFunction = function(executor) {34 checkPoint += "a";35 executor();36 checkPoint += "b";37 executor(function() {}, function() {});38 checkPoint += "c";39};40promise.then();41assert.sameValue(checkPoint, "abc", "executor initially called with no arguments");42var checkPoint = "";43constructorFunction = function(executor) {44 checkPoint += "a";45 executor(undefined, undefined);46 checkPoint += "b";47 executor(function() {}, function() {});48 checkPoint += "c";49};50promise.then();51assert.sameValue(checkPoint, "abc", "executor initially called with (undefined, undefined)");52var checkPoint = "";53assert.throws(TypeError, function() {54 constructorFunction = function(executor) {55 checkPoint += "a";56 executor(undefined, function() {});57 checkPoint += "b";58 executor(function() {}, function() {});59 checkPoint += "c";60 };61 promise.then();62}, "executor initially called with (undefined, function)");63assert.sameValue(checkPoint, "ab", "executor initially called with (undefined, function)");64var checkPoint = "";65assert.throws(TypeError, function() {66 constructorFunction = function(executor) {67 checkPoint += "a";68 executor(function() {}, undefined);69 checkPoint += "b";70 executor(function() {}, function() {});71 checkPoint += "c";72 };73 promise.then();74}, "executor initially called with (function, undefined)");75assert.sameValue(checkPoint, "ab", "executor initially called with (function, undefined)");76var checkPoint = "";77assert.throws(TypeError, function() {78 constructorFunction = function(executor) {79 checkPoint += "a";80 executor("invalid value", 123);81 checkPoint += "b";82 executor(function() {}, function() {});83 checkPoint += "c";84 };85 promise.then();86}, "executor initially called with (String, Number)");...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var myFunc = require('./myFunc.js');4var myFunc2 = require('./myFunc2.js');5var myFunc3 = require('./myFunc3.js');6describe('myFunc', function() {7 it('should return 2', function() {8 var stub = sinon.stub(myFunc, 'add', function(a, b) {9 return a + b;10 });11 var result = myFunc.add(1, 1);12 assert.equal(result, 2);13 stub.restore();14 });15});16describe('myFunc2', function() {17 it('should return 2', function() {18 var stub = sinon.stub(myFunc2, 'add').callsFake(function(a, b) {19 return a + b;20 });21 var result = myFunc2.add(1, 1);22 assert.equal(result, 2);23 stub.restore();24 });25});26describe('myFunc3', function() {27 it('should return 2', function() {28 var stub = sinon.stub(myFunc3, 'add').callsFake(function(a, b) {29 return a + b;30 });31 var result = myFunc3.add(1, 1);32 assert.equal(result, 2);33 stub.restore();34 });35});36module.exports = {37 add: function(a, b) {38 return a + b;39 }40};41module.exports = {42 add: function(a, b) {43 return a + b;44 }45};46module.exports = {47 add: function(a, b) {48 return a + b;49 }50};51at Function.Module._resolveFilename (module.js:470:15)52at Function.Module._load (module.js:418:25)53at Module.require (module.js:498:17)54at require (internal/module.js:20:19)55at Object.<anonymous> (/Users/abhishek/Documents/NodeJS/sinonExamples/test.js:6:16)56at Module._compile (module.js:571:32)

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var chai = require('chai');3var expect = chai.expect;4describe('Test', function() {5 it('should execute executor', function() {6 var executor = sinon.stub();7 executor();8 expect(executor.calledOnce).to.be.true;9 });10});11 1 passing (8ms)12var sinon = require('sinon');13var chai = require('chai');14var expect = chai.expect;15describe('Test', function() {16 it('should return a value', function() {17 var stub = sinon.stub();18 stub.returns(42);19 expect(stub()).to.equal(42);20 });21});22 1 passing (8ms)23var sinon = require('sinon');24var chai = require('chai');25var expect = chai.expect;26describe('Test', function() {27 it('should throw an error', function() {28 var stub = sinon.stub();29 stub.throws();30 expect(stub).to.throw(Error);31 });32});33 1 passing (8ms)34var sinon = require('sinon');35var chai = require('chai');36var expect = chai.expect;37describe('Test', function() {38 it('should return a value after a specified delay', function() {39 var stub = sinon.stub();40 stub.withArgs(100).returns(42);

Full Screen

Using AI Code Generation

copy

Full Screen

1var executor = sinon.stub().returns(10);2var stub = sinon.stub().callsFake(executor);3stub();4assert.equal(executor.callCount, 1);5var executor = sinon.stub().returns(10);6var stub = sinon.stub().callsFake(executor);7stub();8assert.equal(executor.callCount, 1);9var executor = sinon.stub().returns(10);10var stub = sinon.stub().callsFake(executor);11stub();12assert.equal(executor.callCount, 1);13var executor = sinon.stub().returns(10);14var stub = sinon.stub().callsFake(executor);15stub();16assert.equal(executor.callCount, 1);17var executor = sinon.stub().returns(10);18var stub = sinon.stub().callsFake(executor);19stub();20assert.equal(executor.callCount, 1);21var executor = sinon.stub().returns(10);22var stub = sinon.stub().callsFake(executor);23stub();24assert.equal(executor.callCount, 1);25var executor = sinon.stub().returns(10);26var stub = sinon.stub().callsFake(executor);27stub();28assert.equal(executor.callCount, 1);29var executor = sinon.stub().returns(10);30var stub = sinon.stub().callsFake(executor);31stub();32assert.equal(executor.callCount, 1);33var executor = sinon.stub().returns(10);34var stub = sinon.stub().callsFake(executor);35stub();36assert.equal(executor.callCount, 1);37var executor = sinon.stub().returns(10);38var stub = sinon.stub().callsFake(executor);39stub();40assert.equal(executor.callCount, 1);41var executor = sinon.stub().returns(10);42var stub = sinon.stub().callsFake(executor);43stub();44assert.equal(executor.callCount, 1);45var executor = sinon.stub().returns(10);46var stub = sinon.stub().callsFake(executor);47stub();48assert.equal(executor.callCount, 1);

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var expect = require('chai').expect;3var myModule = require('../myModule');4describe('myModule', function() {5 var executor = sinon.stub();6 it('should execute executor', function() {7 myModule(executor);8 expect(executor.called).to.be.true;9 });10});11module.exports = function(executor) {12 executor();13};

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var executor = require('../executor.js');4var executor = new executor();5describe('executor', function() {6 describe('execute', function() {7 it('should return a promise', function() {8 var promise = executor.execute();9 assert(promise instanceof Promise);10 });11 it('should resolve with 1 when passed 1', function() {12 var promise = executor.execute(1);13 promise.then(function(result) {14 assert.equal(result, 1);15 });16 });17 });18});19var executor = module.exports = function() {20 this.execute = function(input) {21 return new Promise(function(resolve, reject) {22 resolve(input);23 });24 }25};26Uncaught AssertionError: expected {} to be an instance of Promise27var Promise = require('promise');28var Promise = require('bluebird');29var Promise = require('es6-promise').Promise;30var Promise = require('q').Promise;31var Promise = require('rsvp').Promise;32var Promise = require('when').Promise;33var Promise = require('promise');34var Promise = require('bluebird');35var Promise = require('es6-promise').Promise;36var Promise = require('q').Promise;37var Promise = require('rsvp').Promise;38var Promise = require('when').Promise;39var executor = module.exports = function() {40 this.execute = function(input) {41 return new Promise(function(resolve, reject) {42 resolve(input);43 });44 }45};46Uncaught AssertionError: expected {} to be an instance of Promise47var executor = module.exports = function() {48 this.execute = function(input) {49 return new Promise(function(resolve, reject) {50 resolve(input);51 });52 }53};54Uncaught AssertionError: expected {} to

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var myModule = require('./myModule.js');4var myModuleInstance = myModule();5sinon.stub(myModuleInstance, 'myMethod', function() {6 return 'stubbed';7});8var result = myModuleInstance.myMethod();9assert.equal(result, 'stubbed');10myModuleInstance.myMethod.restore();11module.exports = function() {12 var myMethod = function() {13 return 'original';14 };15 return {16 };17};18var sinon = require('sinon');19var assert = require('assert');20var myModule = require('./myModule.js');21var myModuleInstance = myModule();22sinon.stub(myModuleInstance, 'myMethod', function() {23 return 'stubbed';24});25var result = myModuleInstance.myMethod();26assert.equal(result, 'stubbed');27myModuleInstance.myMethod.restore();28sinon.stub(require('module1'), 'method1', function() {29 return 'stubbed';30});31sinon.stub(require('module2'), 'method2', function() {32 return 'stubbed';33});34module.exports = function() {35 var myMethod = function() {36 return 'original';37 };38 return {39 };40};

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var executor = require('./executor');4describe('executor', function() {5 it('should call the callback function with the result', function() {6 var callback = sinon.spy();7 executor(callback);8 assert(callback.calledWith(42));9 });10});11module.exports = function(callback) {12 callback(42);13};14{15 "scripts": {16 },17 "repository": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const sinon = require('sinon');2const { expect } = require('chai');3const db = require('../db');4describe('db', () => {5 describe('get', () => {6 it('should return the value of the key', () => {7 sinon.stub(db, 'get').callsFake((key, cb) => {8 cb(null, 'value');9 });10 db.get('key', (err, value) => {11 expect(value).to.equal('value');12 });13 });14 });15});16const db = {17 get(key, cb) {18 setTimeout(() => {19 cb(null, 'value');20 }, 1000);21 }22};23module.exports = db;

Full Screen

Using AI Code Generation

copy

Full Screen

1test('test', function () {2 var spy = sinon.spy();3 spy();4 assert(spy.called);5});6test('test', function () {7 var spy = sinon.spy();8 spy();9 assert(spy.called);10});11test('test', function () {12 var spy = sinon.spy();13 spy();14 assert(spy.called);15});16test('test', function () {17 var spy = sinon.spy();18 spy();19 assert(spy.called);20});21test('test', function () {22 var spy = sinon.spy();23 spy();24 assert(spy.called);25});26test('test', function () {27 var spy = sinon.spy();28 spy();29 assert(spy.called);30});31test('test', function () {32 var spy = sinon.spy();33 spy();34 assert(spy.called);35});36test('test', function () {37 var spy = sinon.spy();38 spy();39 assert(spy.called);40});41test('test', function () {

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