Skip to content

Commit b2c8a69

Browse files
authored
chore: remove Node 8 references and some dead code (#9284)
* chore: remove Node 8 references and some dead code * import async hooks normally * bump node to 8.3 because V8 6.0 with Turbofan and better perf * update comments in pretty-format
1 parent 012fc8b commit b2c8a69

File tree

53 files changed

+89
-109
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+89
-109
lines changed

docs/CLI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Print debugging info about your Jest config.
158158

159159
### `--detectOpenHandles`
160160

161-
Attempt to collect and print open handles preventing Jest from exiting cleanly. Use this in cases where you need to use `--forceExit` in order for Jest to exit to potentially track down the reason. This implies `--runInBand`, making tests run serially. Implemented using [`async_hooks`](https://nodejs.org/api/async_hooks.html), so it only works in Node 8 and newer. This option has a significant performance penalty and should only be used for debugging.
161+
Attempt to collect and print open handles preventing Jest from exiting cleanly. Use this in cases where you need to use `--forceExit` in order for Jest to exit to potentially track down the reason. This implies `--runInBand`, making tests run serially. Implemented using [`async_hooks`](https://nodejs.org/api/async_hooks.html). This option has a significant performance penalty and should only be used for debugging.
162162

163163
### `--env=<environment>`
164164

jest.config.ci.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
'use strict';
99

10-
// Object spread is just node 8
11-
module.exports = Object.assign({}, require('./jest.config'), {
10+
module.exports = {
11+
...require('./jest.config'),
1212
coverageReporters: ['json'],
1313
reporters: [
1414
[
@@ -17,4 +17,4 @@ module.exports = Object.assign({}, require('./jest.config'), {
1717
],
1818
['jest-silent-reporter', {useDots: true}],
1919
],
20-
});
20+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@
144144
"logo": "https://opencollective.com/jest/logo.txt"
145145
},
146146
"engines": {
147-
"node": ">= 8"
147+
"node": ">= 8.3"
148148
}
149149
}

packages/babel-jest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@babel/core": "^7.0.0"
2727
},
2828
"engines": {
29-
"node": ">= 8"
29+
"node": ">= 8.3"
3030
},
3131
"publishConfig": {
3232
"access": "public"

packages/babel-plugin-jest-hoist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"directory": "packages/babel-plugin-jest-hoist"
88
},
99
"engines": {
10-
"node": ">= 8"
10+
"node": ">= 8.3"
1111
},
1212
"license": "MIT",
1313
"main": "build/index.js",

packages/babel-preset-jest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@babel/core": "^7.0.0"
1818
},
1919
"engines": {
20-
"node": ">= 8"
20+
"node": ">= 8.3"
2121
},
2222
"publishConfig": {
2323
"access": "public"

packages/diff-sequences/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"diff"
1717
],
1818
"engines": {
19-
"node": ">= 8"
19+
"node": ">= 8.3"
2020
},
2121
"main": "build/index.js",
2222
"types": "build/index.d.ts",

packages/eslint-config-fb-strict/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"eslint-plugin-react": "^7.1.0"
2121
},
2222
"engines": {
23-
"node": ">= 8"
23+
"node": ">= 8.3"
2424
},
2525
"publishConfig": {
2626
"access": "public"

packages/expect/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"immutable": "^4.0.0-rc.12"
2323
},
2424
"engines": {
25-
"node": ">= 8"
25+
"node": ">= 8.3"
2626
},
2727
"publishConfig": {
2828
"access": "public"

packages/jest-changed-files/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"throat": "^5.0.0"
1616
},
1717
"engines": {
18-
"node": ">= 8"
18+
"node": ">= 8.3"
1919
},
2020
"publishConfig": {
2121
"access": "public"

packages/jest-circus/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"jest-runtime": "^24.9.0"
3737
},
3838
"engines": {
39-
"node": ">= 8"
39+
"node": ">= 8.3"
4040
},
4141
"publishConfig": {
4242
"access": "public"

packages/jest-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"jest": "./bin/jest.js"
3030
},
3131
"engines": {
32-
"node": ">= 8"
32+
"node": ">= 8.3"
3333
},
3434
"repository": {
3535
"type": "git",

packages/jest-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@types/micromatch": "^3.1.0"
3535
},
3636
"engines": {
37-
"node": ">= 8"
37+
"node": ">= 8.3"
3838
},
3939
"publishConfig": {
4040
"access": "public"

packages/jest-console/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"slash": "^3.0.0"
1717
},
1818
"engines": {
19-
"node": ">= 8"
19+
"node": ">= 8.3"
2020
},
2121
"publishConfig": {
2222
"access": "public"

packages/jest-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@types/rimraf": "^2.0.2"
4343
},
4444
"engines": {
45-
"node": ">= 8"
45+
"node": ">= 8.3"
4646
},
4747
"repository": {
4848
"type": "git",

packages/jest-core/src/collectHandles.ts

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import * as asyncHooks from 'async_hooks';
89
import {Config} from '@jest/types';
910
import {formatExecError} from 'jest-message-util';
1011
import {ErrorWithStack} from 'jest-util';
1112
import stripAnsi = require('strip-ansi');
1213

13-
type AsyncHook = import('async_hooks').AsyncHook;
14-
1514
function stackIsFromUser(stack: string) {
1615
// Either the test file, or something required by it
1716
if (stack.includes('Runtime.requireModule')) {
@@ -43,58 +42,43 @@ export default function collectHandles(): () => Array<Error> {
4342
number,
4443
{error: Error; isActive: () => boolean}
4544
> = new Map();
46-
47-
let hook: AsyncHook;
48-
49-
try {
50-
const asyncHooks: typeof import('async_hooks') = require('async_hooks');
51-
hook = asyncHooks.createHook({
52-
destroy(asyncId) {
53-
activeHandles.delete(asyncId);
54-
},
55-
init: function initHook(
56-
asyncId,
57-
type,
58-
_triggerAsyncId,
59-
resource: {} | NodeJS.Timeout,
60-
) {
61-
if (type === 'PROMISE' || type === 'TIMERWRAP') {
62-
return;
63-
}
64-
const error = new ErrorWithStack(type, initHook);
65-
66-
if (stackIsFromUser(error.stack || '')) {
67-
let isActive: () => boolean;
68-
69-
if (type === 'Timeout' || type === 'Immediate') {
70-
if ('hasRef' in resource) {
71-
// Timer that supports hasRef (Node v11+)
72-
isActive = resource.hasRef.bind(resource);
73-
} else {
74-
// Timer that doesn't support hasRef
75-
isActive = alwaysActive;
76-
}
45+
const hook = asyncHooks.createHook({
46+
destroy(asyncId) {
47+
activeHandles.delete(asyncId);
48+
},
49+
init: function initHook(
50+
asyncId,
51+
type,
52+
_triggerAsyncId,
53+
resource: {} | NodeJS.Timeout,
54+
) {
55+
if (type === 'PROMISE' || type === 'TIMERWRAP') {
56+
return;
57+
}
58+
const error = new ErrorWithStack(type, initHook);
59+
60+
if (stackIsFromUser(error.stack || '')) {
61+
let isActive: () => boolean;
62+
63+
if (type === 'Timeout' || type === 'Immediate') {
64+
if ('hasRef' in resource) {
65+
// Timer that supports hasRef (Node v11+)
66+
isActive = resource.hasRef.bind(resource);
7767
} else {
78-
// Any other async resource
68+
// Timer that doesn't support hasRef
7969
isActive = alwaysActive;
8070
}
81-
82-
activeHandles.set(asyncId, {error, isActive});
71+
} else {
72+
// Any other async resource
73+
isActive = alwaysActive;
8374
}
84-
},
85-
});
86-
87-
hook.enable();
88-
} catch (e) {
89-
const nodeMajor = Number(process.versions.node.split('.')[0]);
90-
if (e.code === 'MODULE_NOT_FOUND' && nodeMajor < 8) {
91-
throw new Error(
92-
'You can only use --detectOpenHandles on Node 8 and newer.',
93-
);
94-
} else {
95-
throw e;
96-
}
97-
}
75+
76+
activeHandles.set(asyncId, {error, isActive});
77+
}
78+
},
79+
});
80+
81+
hook.enable();
9882

9983
return () => {
10084
hook.disable();

packages/jest-diff/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"strip-ansi": "^6.0.0"
2020
},
2121
"engines": {
22-
"node": ">= 8"
22+
"node": ">= 8.3"
2323
},
2424
"publishConfig": {
2525
"access": "public"

packages/jest-docblock/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"detect-newline": "^3.0.0"
1313
},
1414
"engines": {
15-
"node": ">= 8"
15+
"node": ">= 8.3"
1616
},
1717
"publishConfig": {
1818
"access": "public"

packages/jest-each/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"pretty-format": "^24.9.0"
2626
},
2727
"engines": {
28-
"node": ">= 8"
28+
"node": ">= 8.3"
2929
},
3030
"publishConfig": {
3131
"access": "public"

packages/jest-environment-jsdom/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@types/jsdom": "^12.2.4"
2222
},
2323
"engines": {
24-
"node": ">= 8"
24+
"node": ">= 8.3"
2525
},
2626
"publishConfig": {
2727
"access": "public"

packages/jest-environment-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"jest-util": "^24.9.0"
1818
},
1919
"engines": {
20-
"node": ">= 8"
20+
"node": ">= 8.3"
2121
},
2222
"publishConfig": {
2323
"access": "public"

packages/jest-environment/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"jest-mock": "^24.9.0"
1616
},
1717
"engines": {
18-
"node": ">= 8"
18+
"node": ">= 8.3"
1919
},
2020
"publishConfig": {
2121
"access": "public"

packages/jest-fake-timers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@types/lolex": "^5.1.0"
2121
},
2222
"engines": {
23-
"node": ">= 8"
23+
"node": ">= 8.3"
2424
},
2525
"publishConfig": {
2626
"access": "public"

packages/jest-get-type/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"directory": "packages/jest-get-type"
99
},
1010
"engines": {
11-
"node": ">= 8"
11+
"node": ">= 8.3"
1212
},
1313
"license": "MIT",
1414
"main": "build/index.js",

packages/jest-haste-map/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"fsevents": "^2.1.2"
3333
},
3434
"engines": {
35-
"node": ">= 8"
35+
"node": ">= 8.3"
3636
},
3737
"publishConfig": {
3838
"access": "public"

packages/jest-jasmine2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@types/babel__traverse": "^7.0.4"
3333
},
3434
"engines": {
35-
"node": ">= 8"
35+
"node": ">= 8.3"
3636
},
3737
"publishConfig": {
3838
"access": "public"

packages/jest-leak-detector/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"weak-napi": "^1.0.3"
1919
},
2020
"engines": {
21-
"node": ">= 8"
21+
"node": ">= 8.3"
2222
},
2323
"publishConfig": {
2424
"access": "public"

packages/jest-matcher-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"directory": "packages/jest-matcher-utils"
99
},
1010
"engines": {
11-
"node": ">= 8"
11+
"node": ">= 8.3"
1212
},
1313
"license": "MIT",
1414
"main": "build/index.js",

packages/jest-message-util/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"directory": "packages/jest-message-util"
88
},
99
"engines": {
10-
"node": ">= 8"
10+
"node": ">= 8.3"
1111
},
1212
"license": "MIT",
1313
"main": "build/index.js",

packages/jest-mock/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"directory": "packages/jest-mock"
88
},
99
"engines": {
10-
"node": ">= 8"
10+
"node": ">= 8.3"
1111
},
1212
"dependencies": {
1313
"@jest/types": "^24.9.0"

packages/jest-phabricator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@jest/test-result": "^24.9.0"
1212
},
1313
"engines": {
14-
"node": ">= 8"
14+
"node": ">= 8.3"
1515
},
1616
"license": "MIT",
1717
"main": "build/index.js",

packages/jest-regex-util/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"directory": "packages/jest-regex-util"
88
},
99
"engines": {
10-
"node": ">= 8"
10+
"node": ">= 8.3"
1111
},
1212
"license": "MIT",
1313
"main": "build/index.js",

0 commit comments

Comments
 (0)