MCPcopy
hub / github.com/webpack/webpack / createDisposableFn

Function createDisposableFn

test/helpers/createLazyTestEnv.js:22–44  ·  view source on GitHub ↗
(fn, isTest)

Source from the content-addressed store, hash-verified

20 * @returns {((done: AnyFn) => void) | (() => unknown) | null} wrapped function
21 */
22 const createDisposableFn = (fn, isTest) => {
23 if (!fn) return null;
24 /** @type {AnyFn | null} */
25 let f = fn;
26 const rfn =
27 f.length >= 1
28 ? (/** @type {AnyFn} */ done) => {
29 /** @type {AnyFn} */
30 (f)((/** @type {unknown[]} */ ...args) => {
31 if (isTest) runTests++;
32 done(...args);
33 });
34 }
35 : () => {
36 const r = /** @type {AnyFn} */ (f)();
37 if (isTest) runTests++;
38 return r;
39 };
40 disposables.push(() => {
41 f = null;
42 });
43 return rfn;
44 };
45
46 describe(
47 nameSuffix ? `exported tests ${nameSuffix}` : "exported tests",

Callers 3

itFunction · 0.85
beforeEachFunction · 0.85
afterEachFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by 1

itFunction · 0.68