-
-
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
feat(jest-worker): add JestWorkerFarm
helper type
#12753
Conversation
export type { | ||
ChangeEvent, | ||
HasteMap as HasteMapObject, | ||
IModuleMap, | ||
SerializableModuleMap, | ||
} from './types'; |
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.
Just cleaned up type exports.
@@ -148,7 +152,7 @@ export default class CoverageReporter extends BaseReporter { | |||
forkOptions: {serialization: 'json'}, | |||
maxRetries: 2, | |||
numWorkers: this._globalConfig.maxWorkers, | |||
}); | |||
}) as JestWorkerFarm<CoverageWorker>; |
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.
Type casting is needed for now. Will work without casting after implementing createWorkerFarm()
.
OnCustomMessage, | ||
OnEnd, | ||
OnStart, | ||
PromiseWithCustomMessage, | ||
QueueChildMessage, | ||
TaskQueue, | ||
WorkerCallback, | ||
WorkerFarmOptions, |
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.
This rename is not a breaking change, because the type was not exposed before.
type Promisify<T extends FunctionLike> = ReturnType<T> extends Promise<infer R> | ||
? (...args: Parameters<T>) => Promise<R> | ||
: (...args: Parameters<T>) => Promise<ReturnType<T>>; |
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.
The exposed methods always return a Promise
.
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.
very nice!
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. |
Split from #12680
Summary
While working on #12680, I came up with
JestWorkerFarm
helper type. It is likejest.Mocked
, but for worker farms.It is necessary, because
Worker
class gets extended with exposed methods, but the type of the class does not know nothing about these. So for example,JestWorkerFarm<typeof import('./someWorker')>
returns the correct type fornew Worker(require.resolve('./someWorker'))
. Picking exposed method is supported by passing an object type (in this case, the helper makes sure that users do not override reserved keys).Useful internally. I would be happy to implement it for one of my projects too.
Test plan
Type tests added.