diff --git a/CHANGELOG.md b/CHANGELOG.md index f5e306f654f9..3ec5b8b40551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- `[jest-changed-files]` Fix a lock-up after repeated invocations ([#12757](https://github.com/facebook/jest/issues/12757)) - `[@jest/expect-utils]` Fix deep equality of ImmutableJS OrderedSets ([#12977](https://github.com/facebook/jest/pull/12977)) ### Chore & Maintenance diff --git a/e2e/babel-plugin-jest-hoist/babel.config.js b/e2e/babel-plugin-jest-hoist/babel.config.js index eb10f8afde70..fbbefe910f9a 100644 --- a/e2e/babel-plugin-jest-hoist/babel.config.js +++ b/e2e/babel-plugin-jest-hoist/babel.config.js @@ -17,5 +17,5 @@ module.exports = { }, ], plugins: ['jest-hoist'], - presets: ['@babel/preset-env'], + presets: [['@babel/preset-env', {targets: {node: 'current'}}]], }; diff --git a/e2e/runJest.ts b/e2e/runJest.ts index dc4f2bf0790c..5463175d70ae 100644 --- a/e2e/runJest.ts +++ b/e2e/runJest.ts @@ -160,7 +160,7 @@ type StdErrAndOutString = {stderr: string; stdout: string}; type ConditionFunction = (arg: StdErrAndOutString) => boolean; type CheckerFunction = (arg: StdErrAndOutString) => void; -// Runs `jest` continously (watch mode) and allows the caller to wait for +// Runs `jest` continuously (watch mode) and allows the caller to wait for // conditions on stdout and stderr and to end the process. export const runContinuous = function ( dir: string, diff --git a/e2e/transform/transform-runner/runner.ts b/e2e/transform/transform-runner/runner.ts index 325956eae108..3dd269ac5ac1 100644 --- a/e2e/transform/transform-runner/runner.ts +++ b/e2e/transform/transform-runner/runner.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import throat from 'throat'; +import pLimit from 'p-limit'; import {Test, TestResult, createEmptyTestResult} from '@jest/test-result'; import type {Config} from '@jest/types'; import type { @@ -32,7 +32,7 @@ export default class BaseTestRunner { onResult: OnTestSuccess, onFailure: OnTestFailure, ): Promise { - const mutex = throat(1); + const mutex = pLimit(1); return tests.reduce( (promise, test) => mutex(() => diff --git a/package.json b/package.json index 9e7678426d1a..3c3ee0b4e611 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "mock-fs": "^5.1.2", "netlify-plugin-cache": "^1.0.3", "node-notifier": "^10.0.0", + "p-limit": "^3.1.0", "pkg-dir": "^5.0.0", "prettier": "^2.1.1", "progress": "^2.0.0", @@ -78,7 +79,6 @@ "strip-ansi": "^6.0.0", "strip-json-comments": "^3.1.1", "tempy": "^1.0.0", - "throat": "^6.0.1", "ts-node": "^10.5.0", "type-fest": "^2.11.2", "typescript": "^4.7.3", diff --git a/packages/jest-changed-files/package.json b/packages/jest-changed-files/package.json index 38ead81110d7..dc7b4f2878df 100644 --- a/packages/jest-changed-files/package.json +++ b/packages/jest-changed-files/package.json @@ -18,7 +18,7 @@ }, "dependencies": { "execa": "^5.0.0", - "throat": "^6.0.1" + "p-limit": "^3.1.0" }, "engines": { "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" diff --git a/packages/jest-changed-files/src/index.ts b/packages/jest-changed-files/src/index.ts index 96ec1bf80d5a..d7bb623859a5 100644 --- a/packages/jest-changed-files/src/index.ts +++ b/packages/jest-changed-files/src/index.ts @@ -6,7 +6,7 @@ * */ -import throat from 'throat'; +import pLimit = require('p-limit'); import git from './git'; import hg from './hg'; import type {ChangedFilesPromise, Options, Repos, SCMAdapter} from './types'; @@ -21,7 +21,7 @@ function notEmpty(value: T | null | undefined): value is T { // This is an arbitrary number. The main goal is to prevent projects with // many roots (50+) from spawning too many processes at once. -const mutex = throat(5); +const mutex = pLimit(5); const findGitRoot = (dir: string) => mutex(() => git.getRoot(dir)); const findHgRoot = (dir: string) => mutex(() => hg.getRoot(dir)); diff --git a/packages/jest-circus/package.json b/packages/jest-circus/package.json index 76949ec6a0a0..478506927f9f 100644 --- a/packages/jest-circus/package.json +++ b/packages/jest-circus/package.json @@ -33,10 +33,10 @@ "jest-runtime": "^28.1.2", "jest-snapshot": "^28.1.2", "jest-util": "^28.1.1", + "p-limit": "^3.1.0", "pretty-format": "^28.1.1", "slash": "^3.0.0", - "stack-utils": "^2.0.3", - "throat": "^6.0.1" + "stack-utils": "^2.0.3" }, "devDependencies": { "@babel/core": "^7.11.6", diff --git a/packages/jest-circus/src/run.ts b/packages/jest-circus/src/run.ts index 8d8242b6c203..562a49aa38e3 100644 --- a/packages/jest-circus/src/run.ts +++ b/packages/jest-circus/src/run.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import throat from 'throat'; +import pLimit = require('p-limit'); import type {Circus} from '@jest/types'; import {dispatch, getState} from './state'; import {RETRY_TIMES} from './types'; @@ -46,7 +46,7 @@ const _runTestsForDescribeBlock = async ( if (isRootBlock) { const concurrentTests = collectConcurrentTests(describeBlock); - const mutex = throat(getState().maxConcurrency); + const mutex = pLimit(getState().maxConcurrency); for (const test of concurrentTests) { try { const promise = mutex(test.fn); diff --git a/packages/jest-jasmine2/package.json b/packages/jest-jasmine2/package.json index 155909394c6e..8e1c54ea5c6d 100644 --- a/packages/jest-jasmine2/package.json +++ b/packages/jest-jasmine2/package.json @@ -32,8 +32,8 @@ "jest-runtime": "^28.1.2", "jest-snapshot": "^28.1.2", "jest-util": "^28.1.1", - "pretty-format": "^28.1.1", - "throat": "^6.0.1" + "p-limit": "^3.1.0", + "pretty-format": "^28.1.1" }, "devDependencies": { "@types/co": "^4.6.2" diff --git a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts index b4023ba58474..c4d2a115046d 100644 --- a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts +++ b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts @@ -12,7 +12,7 @@ import co from 'co'; import isGeneratorFn from 'is-generator-fn'; -import throat from 'throat'; +import pLimit = require('p-limit'); import type {Config, Global} from '@jest/types'; import isError from './isError'; import type Spec from './jasmine/Spec'; @@ -192,7 +192,7 @@ function makeConcurrent( timeout?: number, ) => Spec, env: Jasmine['currentEnv_'], - mutex: ReturnType, + mutex: ReturnType, ): Global.ItConcurrentBase { const concurrentFn = function ( specName: Global.TestNameLike, @@ -242,7 +242,7 @@ export default function jasmineAsyncInstall( global: Global.Global, ): void { const jasmine = global.jasmine; - const mutex = throat(globalConfig.maxConcurrency); + const mutex = pLimit(globalConfig.maxConcurrency); const env = jasmine.getEnv(); env.it = promisifyIt(env.it, env, jasmine); diff --git a/packages/jest-runner/package.json b/packages/jest-runner/package.json index 8878f7ca3b8f..1c85ff209c7d 100644 --- a/packages/jest-runner/package.json +++ b/packages/jest-runner/package.json @@ -36,8 +36,8 @@ "jest-util": "^28.1.1", "jest-watcher": "^28.1.1", "jest-worker": "^28.1.1", - "source-map-support": "0.5.13", - "throat": "^6.0.1" + "p-limit": "^3.1.0", + "source-map-support": "0.5.13" }, "devDependencies": { "@tsd/typescript": "~4.7.3", diff --git a/packages/jest-runner/src/index.ts b/packages/jest-runner/src/index.ts index 15273df93dbe..46233f1a60b5 100644 --- a/packages/jest-runner/src/index.ts +++ b/packages/jest-runner/src/index.ts @@ -7,7 +7,7 @@ import chalk = require('chalk'); import Emittery = require('emittery'); -import throat from 'throat'; +import pLimit = require('p-limit'); import type { Test, TestEvents, @@ -54,7 +54,7 @@ export default class TestRunner extends EmittingTestRunner { async #createInBandTestRun(tests: Array, watcher: TestWatcher) { process.env.JEST_WORKER_ID = '1'; - const mutex = throat(1); + const mutex = pLimit(1); return tests.reduce( (promise, test) => mutex(() => @@ -116,7 +116,7 @@ export default class TestRunner extends EmittingTestRunner { if (worker.getStdout()) worker.getStdout().pipe(process.stdout); if (worker.getStderr()) worker.getStderr().pipe(process.stderr); - const mutex = throat(this._globalConfig.maxWorkers); + const mutex = pLimit(this._globalConfig.maxWorkers); // Send test suites to workers continuously instead of all at once to track // the start time of individual tests. diff --git a/scripts/buildTs.mjs b/scripts/buildTs.mjs index c8fb4267c076..5d7293f29a5e 100644 --- a/scripts/buildTs.mjs +++ b/scripts/buildTs.mjs @@ -12,8 +12,8 @@ import chalk from 'chalk'; import execa from 'execa'; import globby from 'globby'; import fs from 'graceful-fs'; +import pLimit from 'p-limit'; import stripJsonComments from 'strip-json-comments'; -import throat from 'throat'; import {getPackages} from './buildUtils.mjs'; (async () => { @@ -130,9 +130,10 @@ import {getPackages} from './buildUtils.mjs'; const typesNodeReferenceDirective = `${typesReferenceDirective}="node" />`; try { + const mutex = pLimit(cpus); await Promise.all( - packagesWithTs.map( - throat(cpus, async ({packageDir, pkg}) => { + packagesWithTs.map(({packageDir, pkg}) => + mutex(async () => { const buildDir = path.resolve(packageDir, 'build/**/*.d.ts'); const globbed = await globby([buildDir]); diff --git a/yarn.lock b/yarn.lock index 37a5f74d13eb..b92c0f025de4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2722,6 +2722,7 @@ __metadata: mock-fs: ^5.1.2 netlify-plugin-cache: ^1.0.3 node-notifier: ^10.0.0 + p-limit: ^3.1.0 pkg-dir: ^5.0.0 prettier: ^2.1.1 progress: ^2.0.0 @@ -2735,7 +2736,6 @@ __metadata: strip-ansi: ^6.0.0 strip-json-comments: ^3.1.1 tempy: ^1.0.0 - throat: ^6.0.1 ts-node: ^10.5.0 type-fest: ^2.11.2 typescript: ^4.7.3 @@ -13111,7 +13111,7 @@ __metadata: resolution: "jest-changed-files@workspace:packages/jest-changed-files" dependencies: execa: ^5.0.0 - throat: ^6.0.1 + p-limit: ^3.1.0 languageName: unknown linkType: soft @@ -13142,10 +13142,10 @@ __metadata: jest-runtime: ^28.1.2 jest-snapshot: ^28.1.2 jest-util: ^28.1.1 + p-limit: ^3.1.0 pretty-format: ^28.1.1 slash: ^3.0.0 stack-utils: ^2.0.3 - throat: ^6.0.1 languageName: unknown linkType: soft @@ -13388,8 +13388,8 @@ __metadata: jest-runtime: ^28.1.2 jest-snapshot: ^28.1.2 jest-util: ^28.1.1 + p-limit: ^3.1.0 pretty-format: ^28.1.1 - throat: ^6.0.1 languageName: unknown linkType: soft @@ -13606,8 +13606,8 @@ __metadata: jest-util: ^28.1.1 jest-watcher: ^28.1.1 jest-worker: ^28.1.1 + p-limit: ^3.1.0 source-map-support: 0.5.13 - throat: ^6.0.1 tsd-lite: ^0.5.1 languageName: unknown linkType: soft @@ -16930,7 +16930,7 @@ __metadata: languageName: node linkType: hard -"p-limit@npm:^3.0.2": +"p-limit@npm:^3.0.2, p-limit@npm:^3.1.0": version: 3.1.0 resolution: "p-limit@npm:3.1.0" dependencies: