MCPcopy
hub / github.com/jestjs/jest / makeConcurrent

Function makeConcurrent

packages/jest-jasmine2/src/jasmineAsyncInstall.ts:193–253  ·  view source on GitHub ↗
(
  originalFn: (
    description: Global.TestNameLike,
    fn: QueueableFn['fn'],
    timeout?: number,
  ) => Spec,
  env: Jasmine['currentEnv_'],
  mutex: ReturnType<typeof pLimit>,
)

Source from the content-addressed store, hash-verified

191}
192
193function makeConcurrent(
194 originalFn: (
195 description: Global.TestNameLike,
196 fn: QueueableFn['fn'],
197 timeout?: number,
198 ) => Spec,
199 env: Jasmine['currentEnv_'],
200 mutex: ReturnType<typeof pLimit>,
201): Global.ItConcurrentBase {
202 const concurrentFn = function (
203 specName: Global.TestNameLike,
204 fn: Global.ConcurrentTestFn,
205 timeout?: number,
206 ) {
207 let promise: Promise<unknown> = Promise.resolve();
208
209 const spec = originalFn.call(env, specName, () => promise, timeout);
210 if (env != null && !env.specFilter(spec)) {
211 return spec;
212 }
213
214 try {
215 promise = mutex(() => {
216 const promise = fn();
217 if (isPromise(promise)) {
218 return promise;
219 }
220 throw new Error(
221 `Jest: concurrent test "${spec.getFullName()}" must return a Promise.`,
222 );
223 });
224 } catch (error) {
225 promise = Promise.reject(error);
226 }
227 // Avoid triggering the uncaught promise rejection handler in case the test errors before
228 // being awaited on.
229 // eslint-disable-next-line @typescript-eslint/no-empty-function
230 promise.catch(() => {});
231
232 return spec;
233 };
234
235 // eslint-disable-next-line unicorn/consistent-function-scoping
236 const failing = () => {
237 throw new Error(
238 'Jest: `failing` tests are only supported in `jest-circus`.',
239 );
240 };
241
242 failing.each = () => {
243 throw new Error(
244 'Jest: `failing` tests are only supported in `jest-circus`.',
245 );
246 };
247 // each is bound after the function is made concurrent, so for now it is made noop
248 // eslint-disable-next-line @typescript-eslint/no-empty-function,unicorn/consistent-function-scoping
249 concurrentFn.each = () => () => {};
250 concurrentFn.failing = failing;

Callers 1

jasmineAsyncInstallFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected