-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Part 1] Individual Test Case Report - Support custom messages #10293
[Part 1] Individual Test Case Report - Support custom messages #10293
Conversation
fix: minor fixes and code refactorings update: add `unstable_api` for eventEmitter
Co-authored-by: ran shapiro <ran.shapiro@atos.net>
… with coverage, by caching micromatch and avoiding recreating RegExp instances (jestjs#10131) Co-authored-by: Christoph Nakazawa <cpojer@fb.com>
(Typo) Removed word "to"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay!
packages/jest-worker/src/Farm.ts
Outdated
method: string, | ||
...args: Array<any> | ||
): PromiseWithCustomMessage<unknown> { | ||
const customMessageListeners: Set<OnCustomMessage> = new Set(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const customMessageListeners: Set<OnCustomMessage> = new Set(); | |
const customMessageListeners = new Set<OnCustomMessage>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okayy, I think I missed these changes which I committed at a later stage in the previous PR; when I split it. Sorry for the repeat suggestions 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries!
packages/jest-worker/src/Farm.ts
Outdated
const addCustomMessageListener = (listener: OnCustomMessage) => { | ||
customMessageListeners.add(listener); | ||
return () => { | ||
// Check if the following check is required |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to loop, just call the delete
packages/jest-worker/src/Farm.ts
Outdated
|
||
const onEnd: OnEnd = (error: Error | null, result: unknown) => { | ||
customMessageListeners.clear(); | ||
return error ? reject(error) : resolve(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep if-else
packages/jest-worker/src/index.ts
Outdated
WorkerPoolInterface, | ||
WorkerPoolOptions, | ||
} from './types'; | ||
import _messageParent from './workers/messageParent'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import _messageParent from './workers/messageParent'; | |
export {default as messageParent} from './workers/messageParent'; |
packages/jest-worker/src/index.ts
Outdated
@@ -146,3 +148,6 @@ export default class JestWorker { | |||
return this._workerPool.end(); | |||
} | |||
} | |||
|
|||
export type {PromiseWithCustomMessage}; | |||
export const messageParent = _messageParent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const messageParent = _messageParent; |
|
||
const isWorkerThread = () => { | ||
try { | ||
const {isMainThread, parentPort} = require('worker_threads'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do import
on this - we only support node 10 and up these days
f8fbd6b
to
45492fa
Compare
packages/jest-worker/src/Farm.ts
Outdated
const onEnd: OnEnd = (error: Error | null, result: unknown) => { | ||
customMessageListeners.clear(); | ||
if (error) { | ||
return reject(error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return
does nothing
parentProcess: NodeJS.Process = process, | ||
): void => { | ||
if (isWorkerThread()) { | ||
const {parentPort} = require('worker_threads'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to require
here
import {isMainThread, parentPort} from 'worker_threads'; | ||
import {PARENT_MESSAGE_CUSTOM} from '../types'; | ||
|
||
const isWorkerThread = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can just be const isWorkerThread = !isMainThread && parentPort
. If we want it to be lazy, at least ditch the try-catch
Huh, seems we need the try catch for |
Yeah for node v10 LTS it requires the expiremental flag |
@SimenB Do I open a PR for adding this? |
Nah, we should just keep the |
🎉🎉🎉 |
Btw, could you send a PR updating the readme of |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary ⚡
PART 1 of 2
Aim: Support custom messages for jest worker
Ref: #9662
Test plan ⚡
An extension from #9662
Closes #9662
Acknowledgements
@sauravhiremath for his super awesome contribution 🚀 🚀
@rogeliog for laying down the foundation for this PR. 🚀
@SimenB and @jevakallio for their time and reviews 👏