Skip to content

Commit 30f70cb

Browse files
authoredJun 30, 2022
fix: Switch from throat to p-limit (#12960)
1 parent 9931a58 commit 30f70cb

File tree

15 files changed

+33
-31
lines changed

15 files changed

+33
-31
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixes
66

7+
- `[jest-changed-files]` Fix a lock-up after repeated invocations ([#12757](https://github.com/facebook/jest/issues/12757))
78
- `[@jest/expect-utils]` Fix deep equality of ImmutableJS OrderedSets ([#12977](https://github.com/facebook/jest/pull/12977))
89

910
### Chore & Maintenance

‎e2e/babel-plugin-jest-hoist/babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ module.exports = {
1717
},
1818
],
1919
plugins: ['jest-hoist'],
20-
presets: ['@babel/preset-env'],
20+
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
2121
};

‎e2e/runJest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ type StdErrAndOutString = {stderr: string; stdout: string};
160160
type ConditionFunction = (arg: StdErrAndOutString) => boolean;
161161
type CheckerFunction = (arg: StdErrAndOutString) => void;
162162

163-
// Runs `jest` continously (watch mode) and allows the caller to wait for
163+
// Runs `jest` continuously (watch mode) and allows the caller to wait for
164164
// conditions on stdout and stderr and to end the process.
165165
export const runContinuous = function (
166166
dir: string,

‎e2e/transform/transform-runner/runner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import throat from 'throat';
8+
import pLimit from 'p-limit';
99
import {Test, TestResult, createEmptyTestResult} from '@jest/test-result';
1010
import type {Config} from '@jest/types';
1111
import type {
@@ -32,7 +32,7 @@ export default class BaseTestRunner {
3232
onResult: OnTestSuccess,
3333
onFailure: OnTestFailure,
3434
): Promise<void> {
35-
const mutex = throat(1);
35+
const mutex = pLimit(1);
3636
return tests.reduce(
3737
(promise, test) =>
3838
mutex(() =>

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"mock-fs": "^5.1.2",
6666
"netlify-plugin-cache": "^1.0.3",
6767
"node-notifier": "^10.0.0",
68+
"p-limit": "^3.1.0",
6869
"pkg-dir": "^5.0.0",
6970
"prettier": "^2.1.1",
7071
"progress": "^2.0.0",
@@ -78,7 +79,6 @@
7879
"strip-ansi": "^6.0.0",
7980
"strip-json-comments": "^3.1.1",
8081
"tempy": "^1.0.0",
81-
"throat": "^6.0.1",
8282
"ts-node": "^10.5.0",
8383
"type-fest": "^2.11.2",
8484
"typescript": "^4.7.3",

‎packages/jest-changed-files/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"dependencies": {
2020
"execa": "^5.0.0",
21-
"throat": "^6.0.1"
21+
"p-limit": "^3.1.0"
2222
},
2323
"engines": {
2424
"node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0"

‎packages/jest-changed-files/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
import throat from 'throat';
9+
import pLimit = require('p-limit');
1010
import git from './git';
1111
import hg from './hg';
1212
import type {ChangedFilesPromise, Options, Repos, SCMAdapter} from './types';
@@ -21,7 +21,7 @@ function notEmpty<T>(value: T | null | undefined): value is T {
2121

2222
// This is an arbitrary number. The main goal is to prevent projects with
2323
// many roots (50+) from spawning too many processes at once.
24-
const mutex = throat(5);
24+
const mutex = pLimit(5);
2525

2626
const findGitRoot = (dir: string) => mutex(() => git.getRoot(dir));
2727
const findHgRoot = (dir: string) => mutex(() => hg.getRoot(dir));

‎packages/jest-circus/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
"jest-runtime": "^28.1.2",
3434
"jest-snapshot": "^28.1.2",
3535
"jest-util": "^28.1.1",
36+
"p-limit": "^3.1.0",
3637
"pretty-format": "^28.1.1",
3738
"slash": "^3.0.0",
38-
"stack-utils": "^2.0.3",
39-
"throat": "^6.0.1"
39+
"stack-utils": "^2.0.3"
4040
},
4141
"devDependencies": {
4242
"@babel/core": "^7.11.6",

‎packages/jest-circus/src/run.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import throat from 'throat';
8+
import pLimit = require('p-limit');
99
import type {Circus} from '@jest/types';
1010
import {dispatch, getState} from './state';
1111
import {RETRY_TIMES} from './types';
@@ -46,7 +46,7 @@ const _runTestsForDescribeBlock = async (
4646

4747
if (isRootBlock) {
4848
const concurrentTests = collectConcurrentTests(describeBlock);
49-
const mutex = throat(getState().maxConcurrency);
49+
const mutex = pLimit(getState().maxConcurrency);
5050
for (const test of concurrentTests) {
5151
try {
5252
const promise = mutex(test.fn);

‎packages/jest-jasmine2/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"jest-runtime": "^28.1.2",
3333
"jest-snapshot": "^28.1.2",
3434
"jest-util": "^28.1.1",
35-
"pretty-format": "^28.1.1",
36-
"throat": "^6.0.1"
35+
"p-limit": "^3.1.0",
36+
"pretty-format": "^28.1.1"
3737
},
3838
"devDependencies": {
3939
"@types/co": "^4.6.2"

‎packages/jest-jasmine2/src/jasmineAsyncInstall.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import co from 'co';
1414
import isGeneratorFn from 'is-generator-fn';
15-
import throat from 'throat';
15+
import pLimit = require('p-limit');
1616
import type {Config, Global} from '@jest/types';
1717
import isError from './isError';
1818
import type Spec from './jasmine/Spec';
@@ -192,7 +192,7 @@ function makeConcurrent(
192192
timeout?: number,
193193
) => Spec,
194194
env: Jasmine['currentEnv_'],
195-
mutex: ReturnType<typeof throat>,
195+
mutex: ReturnType<typeof pLimit>,
196196
): Global.ItConcurrentBase {
197197
const concurrentFn = function (
198198
specName: Global.TestNameLike,
@@ -242,7 +242,7 @@ export default function jasmineAsyncInstall(
242242
global: Global.Global,
243243
): void {
244244
const jasmine = global.jasmine;
245-
const mutex = throat(globalConfig.maxConcurrency);
245+
const mutex = pLimit(globalConfig.maxConcurrency);
246246

247247
const env = jasmine.getEnv();
248248
env.it = promisifyIt(env.it, env, jasmine);

‎packages/jest-runner/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"jest-util": "^28.1.1",
3737
"jest-watcher": "^28.1.1",
3838
"jest-worker": "^28.1.1",
39-
"source-map-support": "0.5.13",
40-
"throat": "^6.0.1"
39+
"p-limit": "^3.1.0",
40+
"source-map-support": "0.5.13"
4141
},
4242
"devDependencies": {
4343
"@tsd/typescript": "~4.7.3",

‎packages/jest-runner/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import chalk = require('chalk');
99
import Emittery = require('emittery');
10-
import throat from 'throat';
10+
import pLimit = require('p-limit');
1111
import type {
1212
Test,
1313
TestEvents,
@@ -54,7 +54,7 @@ export default class TestRunner extends EmittingTestRunner {
5454

5555
async #createInBandTestRun(tests: Array<Test>, watcher: TestWatcher) {
5656
process.env.JEST_WORKER_ID = '1';
57-
const mutex = throat(1);
57+
const mutex = pLimit(1);
5858
return tests.reduce(
5959
(promise, test) =>
6060
mutex(() =>
@@ -116,7 +116,7 @@ export default class TestRunner extends EmittingTestRunner {
116116
if (worker.getStdout()) worker.getStdout().pipe(process.stdout);
117117
if (worker.getStderr()) worker.getStderr().pipe(process.stderr);
118118

119-
const mutex = throat(this._globalConfig.maxWorkers);
119+
const mutex = pLimit(this._globalConfig.maxWorkers);
120120

121121
// Send test suites to workers continuously instead of all at once to track
122122
// the start time of individual tests.

‎scripts/buildTs.mjs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import chalk from 'chalk';
1212
import execa from 'execa';
1313
import globby from 'globby';
1414
import fs from 'graceful-fs';
15+
import pLimit from 'p-limit';
1516
import stripJsonComments from 'strip-json-comments';
16-
import throat from 'throat';
1717
import {getPackages} from './buildUtils.mjs';
1818

1919
(async () => {
@@ -130,9 +130,10 @@ import {getPackages} from './buildUtils.mjs';
130130
const typesNodeReferenceDirective = `${typesReferenceDirective}="node" />`;
131131

132132
try {
133+
const mutex = pLimit(cpus);
133134
await Promise.all(
134-
packagesWithTs.map(
135-
throat(cpus, async ({packageDir, pkg}) => {
135+
packagesWithTs.map(({packageDir, pkg}) =>
136+
mutex(async () => {
136137
const buildDir = path.resolve(packageDir, 'build/**/*.d.ts');
137138

138139
const globbed = await globby([buildDir]);

‎yarn.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -2722,6 +2722,7 @@ __metadata:
27222722
mock-fs: ^5.1.2
27232723
netlify-plugin-cache: ^1.0.3
27242724
node-notifier: ^10.0.0
2725+
p-limit: ^3.1.0
27252726
pkg-dir: ^5.0.0
27262727
prettier: ^2.1.1
27272728
progress: ^2.0.0
@@ -2735,7 +2736,6 @@ __metadata:
27352736
strip-ansi: ^6.0.0
27362737
strip-json-comments: ^3.1.1
27372738
tempy: ^1.0.0
2738-
throat: ^6.0.1
27392739
ts-node: ^10.5.0
27402740
type-fest: ^2.11.2
27412741
typescript: ^4.7.3
@@ -13111,7 +13111,7 @@ __metadata:
1311113111
resolution: "jest-changed-files@workspace:packages/jest-changed-files"
1311213112
dependencies:
1311313113
execa: ^5.0.0
13114-
throat: ^6.0.1
13114+
p-limit: ^3.1.0
1311513115
languageName: unknown
1311613116
linkType: soft
1311713117

@@ -13142,10 +13142,10 @@ __metadata:
1314213142
jest-runtime: ^28.1.2
1314313143
jest-snapshot: ^28.1.2
1314413144
jest-util: ^28.1.1
13145+
p-limit: ^3.1.0
1314513146
pretty-format: ^28.1.1
1314613147
slash: ^3.0.0
1314713148
stack-utils: ^2.0.3
13148-
throat: ^6.0.1
1314913149
languageName: unknown
1315013150
linkType: soft
1315113151

@@ -13388,8 +13388,8 @@ __metadata:
1338813388
jest-runtime: ^28.1.2
1338913389
jest-snapshot: ^28.1.2
1339013390
jest-util: ^28.1.1
13391+
p-limit: ^3.1.0
1339113392
pretty-format: ^28.1.1
13392-
throat: ^6.0.1
1339313393
languageName: unknown
1339413394
linkType: soft
1339513395

@@ -13606,8 +13606,8 @@ __metadata:
1360613606
jest-util: ^28.1.1
1360713607
jest-watcher: ^28.1.1
1360813608
jest-worker: ^28.1.1
13609+
p-limit: ^3.1.0
1360913610
source-map-support: 0.5.13
13610-
throat: ^6.0.1
1361113611
tsd-lite: ^0.5.1
1361213612
languageName: unknown
1361313613
linkType: soft
@@ -16930,7 +16930,7 @@ __metadata:
1693016930
languageName: node
1693116931
linkType: hard
1693216932

16933-
"p-limit@npm:^3.0.2":
16933+
"p-limit@npm:^3.0.2, p-limit@npm:^3.1.0":
1693416934
version: 3.1.0
1693516935
resolution: "p-limit@npm:3.1.0"
1693616936
dependencies:

0 commit comments

Comments
 (0)
Please sign in to comment.