Skip to content

Commit

Permalink
chore: upgrade node version (#14460)
Browse files Browse the repository at this point in the history
Co-authored-by: Simen Bekkhus <[email protected]>
  • Loading branch information
eryue0220 and SimenB authored Sep 19, 2023
1 parent 76a47d8 commit 3374790
Show file tree
Hide file tree
Showing 80 changed files with 116 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ workflows:
matrix:
parameters:
# For some reason, v20 fails to run yarn install…
node-version: ['14', '16', '18', '19']
node-version: ['16', '18']
- test-jest-jasmine
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [14.x, 16.x, 18.x, 19.x, 20.x]
node-version: [16.x, 18.x, 20.x]
shard: ['1/4', '2/4', '3/4', '4/4']
name: Node v${{ matrix.node-version }} on ${{ inputs.os }} (${{ matrix.shard }})
runs-on: ${{ inputs.os }}
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### Chore & Maintenance

- `[*]` [**BREAKING**] Drop support for Node.js versions 14 and 19 ([#14460](https://github.com/jestjs/jest/pull/14460))

## 29.7.0

### Features
Expand Down
2 changes: 1 addition & 1 deletion constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ gen_enforced_field(WorkspaceCwd, 'publishConfig.access', null) :-
workspace_field(WorkspaceCwd, 'private', true).

% Enforces the engines.node field for public workspace
gen_enforced_field(WorkspaceCwd, 'engines.node', '^14.15.0 || ^16.10.0 || >=18.0.0') :-
gen_enforced_field(WorkspaceCwd, 'engines.node', '^16.10.0 || ^18.12.0 || >=20.0.0') :-
\+ workspace_field(WorkspaceCwd, 'private', true).

% Enforces the main and types field to start with ./
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@types/babel__core": "^7.1.14",
"@types/babel__generator": "^7.0.0",
"@types/babel__template": "^7.0.2",
"@types/node": "~14.14.45",
"@types/node": "^16.10.0",
"@types/which": "^3.0.0",
"@types/ws": "8.5.1",
"@typescript-eslint/eslint-plugin": "^5.14.0",
Expand Down Expand Up @@ -170,10 +170,10 @@
"logo": "https://opencollective.com/jest/logo.txt"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"resolutions": {
"@types/node": "~14.14.45",
"@types/node": "~16.18.0",
"@types/react": "^18.2.21",
"ansi-escapes/type-fest": "^2.0.0",
"babel-jest": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@babel/core": "^7.8.0"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-jest/src/__tests__/getCacheKey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ afterEach(() => {
jest.resetModules();

if (process.version === 'new-node-version') {
// @ts-expect-error: Testing purpose
process.version = processVersion;
}

Expand Down Expand Up @@ -194,6 +195,7 @@ describe('getCacheKey', () => {
test('if node version is changing', () => {
// @ts-expect-error: Testing purpose
delete process.version;
// @ts-expect-error: Testing purpose
process.version = 'new-node-version';

const newCacheKey = getCacheKey!(sourceText, sourcePath, transformOptions);
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-jest-hoist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"directory": "packages/babel-plugin-jest-hoist"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"license": "MIT",
"main": "./build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@babel/core": "^7.0.0"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"prompts": "^2.0.1"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/diff-sequences/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"diff"
],
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/expect-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"tsd-lite": "^0.7.0"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"tsd-lite": "^0.7.0"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-changed-files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"p-limit": "^3.1.0"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"tempy": "^1.0.0"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
11 changes: 7 additions & 4 deletions packages/jest-circus/src/eventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Circus} from '@jest/types';
import type {Circus, Global} from '@jest/types';
import {invariant} from 'jest-util';
import {
injectGlobalErrorHandlers,
Expand Down Expand Up @@ -217,7 +217,7 @@ const eventHandler: Circus.EventHandler = (event, state) => {
case 'test_retry': {
const logErrorsBeforeRetry: boolean =
// eslint-disable-next-line no-restricted-globals
global[LOG_ERRORS_BEFORE_RETRY] || false;
((global as Global.Global)[LOG_ERRORS_BEFORE_RETRY] as any) || false;
if (logErrorsBeforeRetry) {
event.test.retryReasons.push(...event.test.errors);
}
Expand All @@ -227,8 +227,11 @@ const eventHandler: Circus.EventHandler = (event, state) => {
case 'run_start': {
state.hasStarted = true;
/* eslint-disable no-restricted-globals */
global[TEST_TIMEOUT_SYMBOL] &&
(state.testTimeout = global[TEST_TIMEOUT_SYMBOL]);
if ((global as Global.Global)[TEST_TIMEOUT_SYMBOL]) {
state.testTimeout = (global as Global.Global)[
TEST_TIMEOUT_SYMBOL
] as number;
}
/* eslint-enable */
break;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-circus/src/globalErrorHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import type * as Process from 'process';
import type {Circus} from '@jest/types';
import {dispatchSync} from './state';

Expand All @@ -14,7 +15,7 @@ const uncaught: NodeJS.UncaughtExceptionListener &
};

export const injectGlobalErrorHandlers = (
parentProcess: NodeJS.Process,
parentProcess: typeof Process,
): Circus.GlobalErrorHandlers => {
const uncaughtException = process.listeners('uncaughtException').slice();
const unhandledRejection = process.listeners('unhandledRejection').slice();
Expand All @@ -26,7 +27,7 @@ export const injectGlobalErrorHandlers = (
};

export const restoreGlobalErrorHandlers = (
parentProcess: NodeJS.Process,
parentProcess: typeof Process,
originalErrorHandlers: Circus.GlobalErrorHandlers,
): void => {
parentProcess.removeListener('uncaughtException', uncaught);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import type * as Process from 'process';
import type {JestEnvironment} from '@jest/environment';
import {JestExpect, jestExpect} from '@jest/expect';
import {
Expand Down Expand Up @@ -51,7 +52,7 @@ export const initialize = async ({
globalConfig: Config.GlobalConfig;
localRequire: <T = unknown>(path: string) => T;
testPath: string;
parentProcess: NodeJS.Process;
parentProcess: typeof Process;
sendMessageToJest?: TestFileEvent;
setGlobalsForRuntime: (globals: RuntimeGlobals) => void;
}): Promise<{
Expand Down
7 changes: 4 additions & 3 deletions packages/jest-circus/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {AsyncLocalStorage} from 'async_hooks';
import pLimit = require('p-limit');
import {jestExpect} from '@jest/expect';
import type {Circus} from '@jest/types';
import type {Circus, Global} from '@jest/types';
import {invariant} from 'jest-util';
import shuffleArray, {RandomNumberGenerator, rngBuilder} from './shuffleArray';
import {dispatch, getState} from './state';
Expand Down Expand Up @@ -61,8 +61,9 @@ const _runTestsForDescribeBlock = async (
}

// Tests that fail and are retried we run after other tests
// eslint-disable-next-line no-restricted-globals
const retryTimes = parseInt(global[RETRY_TIMES], 10) || 0;
const retryTimes =
// eslint-disable-next-line no-restricted-globals
parseInt((global as Global.Global)[RETRY_TIMES] as string, 10) || 0;
const deferredRetryTests = [];

if (rng) {
Expand Down
9 changes: 5 additions & 4 deletions packages/jest-circus/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Circus} from '@jest/types';
import type {Circus, Global} from '@jest/types';
import eventHandler from './eventHandler';
import formatNodeAssertErrors from './formatNodeAssertErrors';
import {STATE_SYM} from './types';
Expand Down Expand Up @@ -39,14 +39,15 @@ const createState = (): Circus.State => {

/* eslint-disable no-restricted-globals */
export const resetState = (): void => {
global[STATE_SYM] = createState();
(global as Global.Global)[STATE_SYM] = createState();
};

resetState();

export const getState = (): Circus.State => global[STATE_SYM];
export const getState = (): Circus.State =>
(global as Global.Global)[STATE_SYM] as Circus.State;
export const setState = (state: Circus.State): Circus.State =>
(global[STATE_SYM] = state);
((global as Global.Global)[STATE_SYM] = state);
/* eslint-enable */

export const dispatch = async (event: Circus.AsyncEvent): Promise<void> => {
Expand Down
14 changes: 0 additions & 14 deletions packages/jest-circus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Circus} from '@jest/types';

export const STATE_SYM = Symbol('JEST_STATE_SYMBOL');
export const RETRY_TIMES = Symbol.for('RETRY_TIMES');
// To pass this value from Runtime object to state we need to use global[sym]
export const TEST_TIMEOUT_SYMBOL = Symbol.for('TEST_TIMEOUT_SYMBOL');
export const LOG_ERRORS_BEFORE_RETRY = Symbol.for('LOG_ERRORS_BEFORE_RETRY');

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace NodeJS {
interface Global {
[STATE_SYM]: Circus.State;
[RETRY_TIMES]: string;
[TEST_TIMEOUT_SYMBOL]: number;
[LOG_ERRORS_BEFORE_RETRY]: boolean;
}
}
}
2 changes: 1 addition & 1 deletion packages/jest-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"jest": "./bin/jest.js"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"typescript": "^5.0.4"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@jest/test-utils": "workspace:^"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
}
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"repository": {
"type": "git",
Expand Down
1 change: 0 additions & 1 deletion packages/jest-core/src/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ export default async function runJest({
...testSchedulerContext,
});

// @ts-expect-error - second arg is unsupported (but harmless) in Node 14
performance.mark('jest/scheduleAndRun:start', {
detail: {numTests: allTests.length},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-create-cache-key-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"jest-util": "workspace:^"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"license": "MIT",
"main": "./build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-diff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"strip-ansi": "^6.0.0"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-docblock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@types/node": "*"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"pretty-format": "workspace:^"
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-environment-jsdom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}
},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class JSDOMEnvironment implements JestEnvironment<number> {
throw new Error('JSDOM did not return a Window object');
}

// @ts-expect-error - for "universal" code (code should use `globalThis`)
// TODO: remove at some point - for "universal" code (code should use `globalThis`)
global.global = global;

// Node's error-message stack size is limited at 10, but it's pretty useful
Expand Down
Loading

0 comments on commit 3374790

Please sign in to comment.