Best JavaScript code snippet using stryker-parent
child-process-proxy-worker.ts
Source:child-process-proxy-worker.ts
1import path from 'path';2import { errorToString } from '@stryker-mutator/util';3import { getLogger, Logger } from 'log4js';4import { buildChildProcessInjector } from '../di';5import { LogConfigurator } from '../logging';6import { deserialize, serialize } from '../utils/string-utils';7import { autoStart, CallMessage, ParentMessage, ParentMessageKind, WorkerMessage, WorkerMessageKind, InitMessage } from './message-protocol';8export class ChildProcessProxyWorker {9 private log?: Logger;10 public realSubject: any;11 constructor() {12 // Make sure to bind the methods in order to ensure the `this` pointer13 this.handleMessage = this.handleMessage.bind(this);14 process.on('message', this.handleMessage);15 }16 private send(value: ParentMessage) {17 if (process.send) {18 const str = serialize(value);19 process.send(str);20 }21 }22 private handleMessage(serializedMessage: string) {23 const message = deserialize<WorkerMessage>(serializedMessage);24 switch (message.kind) {25 case WorkerMessageKind.Init:26 this.handleInit(message);27 this.removeAnyAdditionalMessageListeners(this.handleMessage);28 break;29 case WorkerMessageKind.Call:30 this.handleCall(message);31 this.removeAnyAdditionalMessageListeners(this.handleMessage);32 break;33 case WorkerMessageKind.Dispose:34 const sendCompleted = () => {35 this.send({ kind: ParentMessageKind.DisposeCompleted });36 };37 LogConfigurator.shutdown().then(sendCompleted).catch(sendCompleted);38 break;39 }40 }41 private handleInit(message: InitMessage) {42 LogConfigurator.configureChildProcess(message.loggingContext);43 this.log = getLogger(ChildProcessProxyWorker.name);44 this.handlePromiseRejections();45 let injector = buildChildProcessInjector(message.options);46 const locals = message.additionalInjectableValues as Record<string, unknown>;47 for (const token in locals) {48 injector = injector.provideValue(token, locals[token]);49 }50 // we want it sync51 // eslint-disable-next-line @typescript-eslint/no-require-imports52 const RealSubjectClass = require(message.requirePath)[message.requireName];53 const workingDir = path.resolve(message.workingDirectory);54 if (process.cwd() !== workingDir) {55 this.log.debug(`Changing current working directory for this process to ${workingDir}`);56 process.chdir(workingDir);57 }58 // eslint-disable-next-line @typescript-eslint/no-unsafe-argument59 this.realSubject = injector.injectClass(RealSubjectClass);60 this.send({ kind: ParentMessageKind.Initialized });61 }62 private async handleCall(message: CallMessage) {63 try {64 const result = await this.doCall(message);65 this.send({66 correlationId: message.correlationId,67 kind: ParentMessageKind.Result,68 result,69 });70 } catch (err) {71 this.send({72 correlationId: message.correlationId,73 error: errorToString(err),74 kind: ParentMessageKind.Rejection,75 });76 }77 }78 private doCall(message: CallMessage): PromiseLike<Record<string, unknown>> | Record<string, unknown> | undefined {79 if (typeof this.realSubject[message.methodName] === 'function') {80 return this.realSubject[message.methodName](...message.args);81 } else {82 return this.realSubject[message.methodName];83 }84 }85 /**86 * Remove any addition message listeners that might me eavesdropping.87 * the @ngtools/webpack plugin listens to messages and throws an error whenever it could not handle a message88 * @see https://github.com/angular/angular-cli/blob/f776d3cf7982b64734c57fe4407434e9f4ec09f7/packages/%40ngtools/webpack/src/type_checker.ts#L7989 * @param exceptListener The listener that should remain90 */91 private removeAnyAdditionalMessageListeners(exceptListener: NodeJS.MessageListener) {92 process.listeners('message').forEach((listener) => {93 if (listener !== exceptListener) {94 this.log?.debug(95 "Removing an additional message listener, we don't want eavesdropping on our inter-process communication: %s",96 listener.toString()97 );98 process.removeListener('message', listener);99 }100 });101 }102 /**103 * During mutation testing, it's to be expected that promise rejections are not handled synchronously anymore (or not at all)104 * Let's handle those events so future versions of node don't crash105 * See issue 350: https://github.com/stryker-mutator/stryker-js/issues/350106 */107 private handlePromiseRejections() {108 const unhandledRejections: Array<Promise<unknown>> = [];109 process.on('unhandledRejection', (reason, promise) => {110 const unhandledPromiseId = unhandledRejections.push(promise);111 this.log?.debug(`UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: ${unhandledPromiseId}): ${reason}`);112 });113 process.on('rejectionHandled', (promise) => {114 const unhandledPromiseId = unhandledRejections.indexOf(promise) + 1;115 this.log?.debug(`PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: ${unhandledPromiseId})`);116 });117 }118}119// Prevent side effects for merely requiring the file120// Only actually start the child worker when it is requested121if (process.argv.includes(autoStart)) {122 new ChildProcessProxyWorker();...
Using AI Code Generation
1const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;2const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;3const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;4const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;5const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;6const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;7const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;8const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;9const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;10const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;11const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;12const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;13const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;14const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;15const unhandledPromiseId = require('stry
Using AI Code Generation
1const { unhandledPromiseId } = require('stryker-parent');2console.log(unhandledPromiseId);3const { unhandledPromiseId } = require('stryker-parent');4console.log(unhandledPromiseId);5const { unhandledPromiseId } = require('stryker-parent');6console.log(unhandledPromiseId);7const { unhandledPromiseId } = require('stryker-parent');8console.log(unhandledPromiseId);9const { unhandledPromiseId } = require('stryker-parent');10console.log(unhandledPromiseId);11const { unhandledPromiseId } = require('stryker-parent');12console.log(unhandledPromiseId);13const { unhandledPromiseId } = require('stryker-parent');14console.log(unhandledPromiseId);15const { unhandledPromiseId } = require('stryker-parent');16console.log(unhandledPromiseId);17const { unhandledPromiseId } = require('stryker-parent');18console.log(unhandledPromiseId);19const { unhandledPromiseId } = require('stryker-parent');20console.log(unhandledPromiseId);21const { unhandledPromiseId } = require('stryker-parent');22console.log(unhandledPromiseId);23const { unhandledPromiseId } = require('stryker-parent');24console.log(unhandledPromiseId);
Using AI Code Generation
1const { unhandledPromiseId } = require('stryker-parent');2console.log(unhandledPromiseId());3const { unhandledPromiseId } = require('stryker');4console.log(unhandledPromiseId());5{6 "scripts": {7 },8 "dependencies": {9 }10}
Using AI Code Generation
1var unhandledPromiseId = require('stryker-parent').unhandledPromiseId;2var promise = new Promise(function (resolve, reject) {3 setTimeout(function () {4 resolve('Hello World');5 }, 100);6});7promise.then(function (value) {8 console.log(value);9});10setTimeout(function () {11 console.log('unhandled promise id:' + unhandledPromiseId());12}, 1000);
Using AI Code Generation
1const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;2const Promise = require('bluebird');3const promise = Promise.resolve();4setTimeout(() => {5 promise.then(() => {6 });7}, 1000);8console.log(unhandledPromiseId(promise));
Using AI Code Generation
1const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;2const promise = new Promise(resolve => resolve());3const id = unhandledPromiseId(promise);4const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;5const promise = new Promise(resolve => resolve());6const id = unhandledPromiseId(promise);7const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;8const promise = new Promise(resolve => resolve());9const id = unhandledPromiseId(promise);10const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;11const promise = new Promise(resolve => resolve());12const id = unhandledPromiseId(promise);13const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;14const promise = new Promise(resolve => resolve());15const id = unhandledPromiseId(promise);16const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;17const promise = new Promise(resolve => resolve());18const id = unhandledPromiseId(promise);19const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;20const promise = new Promise(resolve => resolve());21const id = unhandledPromiseId(promise);22const unhandledPromiseId = require('stryker-parent').unhandledPromiseId;23const promise = new Promise(resolve
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!