How to use workerTask method in stryker-parent

Best JavaScript code snippet using stryker-parent

worker-task.specs.ts

Source:worker-task.specs.ts Github

copy

Full Screen

1import {WorkerTask} from "../../../src/common/task/worker-task";2import {ITaskDefinition} from "../../../src/common/task/task-definition";3import {functionId} from "../../../src/common/function/function-id";4describe("WorkerTask", function () {5 let workerTask: WorkerTask<number>;6 const taskDefinition: ITaskDefinition = {7 main: {8 ______serializedFunctionCall: true,9 functionId: functionId("test", 2),10 parameters: [5, 10]11 },12 usedFunctionIds: [functionId("test", 2)]13 };14 beforeEach(function () {15 workerTask = new WorkerTask<number>(taskDefinition);16 });17 describe("isCanceled", function () {18 it("is false by default", function () {19 expect(workerTask.isCanceled).toBe(false);20 });21 it("is true if if the task has been resolved", function () {22 // arrange23 workerTask.cancel();24 // act25 workerTask.resolve(10);26 // assert27 expect(workerTask.isCanceled).toBe(true);28 });29 it("is true if if the task has been resolved as canceled", function () {30 // arrange31 workerTask.cancel();32 // act33 workerTask.resolveCancelled();34 // assert35 expect(workerTask.isCanceled).toBe(true);36 });37 });38 describe("isCancellationRequested", function () {39 it("is false by default", function () {40 expect(workerTask.isCancellationRequested).toBe(false);41 });42 it("is true if the user requested cancellation", function () {43 // act44 workerTask.cancel();45 // assert46 expect(workerTask.isCancellationRequested).toBe(true);47 });48 });49 describe("resolve", function () {50 it("triggers the then handlers", function (done) {51 // arrange52 const handler = jasmine.createSpy("thenHandler");53 workerTask.then(handler);54 // act55 workerTask.resolve(10);56 workerTask.then(function () {57 // assert58 expect(handler).toHaveBeenCalledWith(10);59 done();60 }, done.fail);61 });62 it("triggers the catch handlers if the task has been canceled in the meantime", function (done) {63 // arrange64 const catchHandler = jasmine.createSpy("catchHandler");65 workerTask.catch(catchHandler);66 workerTask.cancel();67 // act68 workerTask.resolve(10);69 workerTask.then(() => done.fail("Then handler called, but catch handler should have been called"), function () {70 // assert71 expect(catchHandler).toHaveBeenCalledWith("Task has been canceled");72 expect(workerTask.isCanceled).toBe(true);73 done();74 });75 });76 });77 describe("resolveCanceled", function () {78 it("triggers the catch handlers when the task is resolved canceled", function (done) {79 // arrange80 const catchHandler = jasmine.createSpy("catchHandler");81 workerTask.catch(catchHandler);82 workerTask.cancel();83 // act84 workerTask.resolveCancelled();85 workerTask.then(() => done.fail("Then handler called, but catch handler should have been called"), function () {86 // assert87 expect(catchHandler).toHaveBeenCalledWith("Task has been canceled");88 done();89 });90 });91 it("marks the task as cancelled", function (done) {92 const catchHandler = jasmine.createSpy("catchHandler");93 workerTask.catch(catchHandler);94 workerTask.cancel();95 // act96 workerTask.resolveCancelled();97 workerTask.then(() => done.fail("Then handler called, but catch handler should have been called"), function () {98 // assert99 expect(workerTask.isCanceled).toBe(true);100 done();101 });102 });103 });104 describe("reject", function () {105 it("triggers the catch handlers", function (done) {106 // arrange107 const catchHandler = jasmine.createSpy("catchHandler");108 workerTask.catch(catchHandler);109 workerTask.cancel();110 // act111 workerTask.reject("Error");112 workerTask.then(() => done.fail("Then handler called, but catch handler should have been called"), function () {113 // assert114 expect(catchHandler).toHaveBeenCalledWith("Error");115 done();116 });117 });118 });119 describe("catch", function () {120 let doneFn: DoneFn;121 let unhandledRejctionHandler: () => void;122 beforeEach(function () {123 unhandledRejctionHandler = function () {124 doneFn.fail("Promise has rejection handler and therefore global unrejected handler should not be called");125 };126 window.addEventListener("unhandledrejection", unhandledRejctionHandler);127 });128 afterEach(function () {129 window.removeEventListener("unhandledrejection", unhandledRejctionHandler);130 });131 it("does not trigger 'unhandled exception in promise' if catch handler is registered", function (done) {132 // arrange133 doneFn = done;134 workerTask.catch(() => done());135 // act136 workerTask.reject("Error occurred");137 });138 });...

Full Screen

Full Screen

thread.js

Source:thread.js Github

copy

Full Screen

1// namespaces2var dwv = dwv || {};3dwv.utils = dwv.utils || {};4/**5 * Thread Pool.6 * Highly inspired from {@link http://www.smartjava.org/content/html5-easily-parallelize-jobs-using-web-workers-and-threadpool}.7 * @constructor8 * @param {Number} size The size of the pool.9 */10dwv.utils.ThreadPool = function (size) {11 // closure to self12 var self = this;13 // task queue14 this.taskQueue = [];15 // worker queue16 this.workerQueue = [];17 // pool size18 this.poolSize = size;19 /**20 * Initialise.21 */22 this.init = function () {23 // create 'size' number of worker threads24 for (var i = 0; i < size; ++i) {25 self.workerQueue.push(new dwv.utils.WorkerThread(self));26 }27 };28 /**29 * Add a worker task to the queue.30 * Will be run when a thread is made available.31 * @return {Object} workerTask The task to add.32 */33 this.addWorkerTask = function (workerTask) {34 if (self.workerQueue.length > 0) {35 // get the worker thread from the front of the queue36 var workerThread = self.workerQueue.shift();37 workerThread.run(workerTask);38 } else {39 // no free workers, add to queue40 self.taskQueue.push(workerTask);41 }42 };43 /**44 * Free a worker thread.45 * @param {Object} workerThread The thread to free.46 */47 this.freeWorkerThread = function (workerThread) {48 self.onworkerend();49 if (self.taskQueue.length > 0) {50 // don't put back in queue, but execute next task51 var workerTask = self.taskQueue.shift();52 workerThread.run(workerTask);53 } else {54 // no task to run, add to queue55 self.workerQueue.push(workerThread);56 // the work is done when the queue is back to its initial size57 if ( self.workerQueue.length === size ) {58 self.onpoolworkend();59 }60 }61 };62};63/**64 * Handle a pool work end event.65 */66dwv.utils.ThreadPool.prototype.onpoolworkend = function ()67{68 // default does nothing.69};70/**71 * Handle a pool worker end event.72 */73dwv.utils.ThreadPool.prototype.onworkerend = function ()74{75 // default does nothing.76};77/**78 * Worker thread.79 * @external Worker80 * @constructor81 * @param {Object} parentPool The parent pool.82 */83dwv.utils.WorkerThread = function (parentPool) {84 // closure to self85 var self = this;86 // parent pool87 this.parentPool = parentPool;88 // associated task89 this.workerTask = {};90 // associated web worker91 var worker;92 /**93 * Run a worker task94 * @param {Object} workerTask The task to run.95 */96 this.run = function (workerTask) {97 // closure to task98 this.workerTask = workerTask;99 // create a new web worker100 if (this.workerTask.script !== null) {101 worker = new Worker(workerTask.script);102 worker.addEventListener('message', ontaskend, false);103 // launch the worker104 worker.postMessage(workerTask.startMessage);105 }106 };107 /**108 * Handle once the task is done.109 * For now assume we only get a single callback from a worker110 * which also indicates the end of this worker.111 * @param {Object} event The callback event.112 */113 function ontaskend(event) {114 // pass to original callback115 self.workerTask.callback(event);116 // stop the worker117 worker.terminate();118 // tell the parent pool this thread is free119 self.parentPool.freeWorkerThread(self);120 }121};122/**123 * Worker task.124 * @constructor125 * @param {String} script The worker script.126 * @param {Function} parentPool The worker callback.127 * @param {Object} message The data to pass to the worker.128 */129dwv.utils.WorkerTask = function (script, callback, message) {130 // worker script131 this.script = script;132 // worker callback133 this.callback = callback;134 // worker start message135 this.startMessage = message;...

Full Screen

Full Screen

WorkerPool.ts

Source:WorkerPool.ts Github

copy

Full Screen

1export class WorkerTask {2 data: ArrayBuffer;3 assetName: string | undefined;4 spriteName: string | undefined;5 resolve: (value: any) => void;6}7export class WorkerThread {8 private parentPool: WorkerPool;9 private workerTask: WorkerTask;10 constructor(pool: WorkerPool) {11 this.parentPool = pool;12 }13 run(workerTask: WorkerTask): void {14 this.workerTask = workerTask;15 // create a new web worker16 const worker: Worker = new this.parentPool.AssetWorker();17 worker.addEventListener('message', (message: any) => {18 this.workerTask.resolve(message.data);19 this.workerDone();20 });21 worker.postMessage({22 buffer: workerTask.data,23 assetName: workerTask.assetName,24 spriteName: workerTask.spriteName25 },[workerTask.data]);26 }27 workerDone() {28 // we should use a seperate thread to add the worker29 this.parentPool.freeWorkerThread(this);30 }31}32export class WorkerPool {33 private workerQueue: WorkerThread[];34 private taskQueue: WorkerTask[];35 AssetWorker: any;36 constructor(size: number) {37 this.AssetWorker = require("worker-loader?name=assetWorker.js!./assetWorker");38 this.workerQueue = new Array<WorkerThread>();39 this.taskQueue = new Array<WorkerTask>();40 for (let i = 0; i < size; i++) {41 this.workerQueue.push(new WorkerThread(this));42 }43 }44 addWorkerTask(workerTask: WorkerTask): void {45 // get the worker from the front of the queue46 let workerThread = this.workerQueue.shift();47 if (workerThread) {48 workerThread.run(workerTask);49 } else {50 // no free workers51 this.taskQueue.push(workerTask);52 }53 }54 freeWorkerThread(workerThread: WorkerThread): void {55 let workerTask = this.taskQueue.shift();56 if (workerTask) {57 // don't put back in queue, but execute next task58 workerThread.run(workerTask);59 } else {60 this.workerQueue.push(workerThread);61 }62 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const workerTask = require('stryker-parent').workerTask;2workerTask(function (input, callback) {3 callback(result);4});5module.exports = function (config) {6 config.set({7 karma: {8 config: {9 { pattern: 'test.js', included: true }10 }11 }12 });13};

Full Screen

Using AI Code Generation

copy

Full Screen

1var workerTask = require('stryker-parent').workerTask;2workerTask(function (input, done) {3 done(null, 'some result');4});5module.exports = function(config) {6 config.set({7 });8};

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2var workerTask = stryker.workerTask;3var log = stryker.log;4var Stryker = require('stryker/src/Stryker');5var strykerConfig = require('./stryker.conf.js');6workerTask(function (config) {7 var stryker = new Stryker(config);8 stryker.runMutationTest();9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var workerTask = require('stryker-parent').workerTask;2workerTask('worker.js', 'hello')3.then(function (response) {4 console.log(response);5});6var workerTask = require('stryker-parent').workerTask;7workerTask(function (message) {8 return 'Hello ' + message;9});

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 stryker-parent 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