Skip to content

Commit

Permalink
chore: remove Node 8 references and some dead code (#9284)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thymikee authored Dec 9, 2019
1 parent 012fc8b commit b2c8a69
Show file tree
Hide file tree
Showing 53 changed files with 89 additions and 109 deletions.
2 changes: 1 addition & 1 deletion docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Print debugging info about your Jest config.

### `--detectOpenHandles`

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.
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.

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

Expand Down
6 changes: 3 additions & 3 deletions jest.config.ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

'use strict';

// Object spread is just node 8
module.exports = Object.assign({}, require('./jest.config'), {
module.exports = {
...require('./jest.config'),
coverageReporters: ['json'],
reporters: [
[
Expand All @@ -17,4 +17,4 @@ module.exports = Object.assign({}, require('./jest.config'), {
],
['jest-silent-reporter', {useDots: true}],
],
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@
"logo": "https://opencollective.com/jest/logo.txt"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
}
}
2 changes: 1 addition & 1 deletion packages/babel-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@babel/core": "^7.0.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"publishConfig": {
"access": "public"
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": ">= 8"
"node": ">= 8.3"
},
"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 @@ -17,7 +17,7 @@
"@babel/core": "^7.0.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"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": ">= 8"
"node": ">= 8.3"
},
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-fb-strict/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"eslint-plugin-react": "^7.1.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"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 @@ -22,7 +22,7 @@
"immutable": "^4.0.0-rc.12"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"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 @@ -15,7 +15,7 @@
"throat": "^5.0.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"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 @@ -36,7 +36,7 @@
"jest-runtime": "^24.9.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"jest": "./bin/jest.js"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"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 @@ -34,7 +34,7 @@
"@types/micromatch": "^3.1.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"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 @@ -16,7 +16,7 @@
"slash": "^3.0.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"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 @@ -42,7 +42,7 @@
"@types/rimraf": "^2.0.2"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"repository": {
"type": "git",
Expand Down
84 changes: 34 additions & 50 deletions packages/jest-core/src/collectHandles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

import * as asyncHooks from 'async_hooks';
import {Config} from '@jest/types';
import {formatExecError} from 'jest-message-util';
import {ErrorWithStack} from 'jest-util';
import stripAnsi = require('strip-ansi');

type AsyncHook = import('async_hooks').AsyncHook;

function stackIsFromUser(stack: string) {
// Either the test file, or something required by it
if (stack.includes('Runtime.requireModule')) {
Expand Down Expand Up @@ -43,58 +42,43 @@ export default function collectHandles(): () => Array<Error> {
number,
{error: Error; isActive: () => boolean}
> = new Map();

let hook: AsyncHook;

try {
const asyncHooks: typeof import('async_hooks') = require('async_hooks');
hook = asyncHooks.createHook({
destroy(asyncId) {
activeHandles.delete(asyncId);
},
init: function initHook(
asyncId,
type,
_triggerAsyncId,
resource: {} | NodeJS.Timeout,
) {
if (type === 'PROMISE' || type === 'TIMERWRAP') {
return;
}
const error = new ErrorWithStack(type, initHook);

if (stackIsFromUser(error.stack || '')) {
let isActive: () => boolean;

if (type === 'Timeout' || type === 'Immediate') {
if ('hasRef' in resource) {
// Timer that supports hasRef (Node v11+)
isActive = resource.hasRef.bind(resource);
} else {
// Timer that doesn't support hasRef
isActive = alwaysActive;
}
const hook = asyncHooks.createHook({
destroy(asyncId) {
activeHandles.delete(asyncId);
},
init: function initHook(
asyncId,
type,
_triggerAsyncId,
resource: {} | NodeJS.Timeout,
) {
if (type === 'PROMISE' || type === 'TIMERWRAP') {
return;
}
const error = new ErrorWithStack(type, initHook);

if (stackIsFromUser(error.stack || '')) {
let isActive: () => boolean;

if (type === 'Timeout' || type === 'Immediate') {
if ('hasRef' in resource) {
// Timer that supports hasRef (Node v11+)
isActive = resource.hasRef.bind(resource);
} else {
// Any other async resource
// Timer that doesn't support hasRef
isActive = alwaysActive;
}

activeHandles.set(asyncId, {error, isActive});
} else {
// Any other async resource
isActive = alwaysActive;
}
},
});

hook.enable();
} catch (e) {
const nodeMajor = Number(process.versions.node.split('.')[0]);
if (e.code === 'MODULE_NOT_FOUND' && nodeMajor < 8) {
throw new Error(
'You can only use --detectOpenHandles on Node 8 and newer.',
);
} else {
throw e;
}
}

activeHandles.set(asyncId, {error, isActive});
}
},
});

hook.enable();

return () => {
hook.disable();
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 @@ -19,7 +19,7 @@
"strip-ansi": "^6.0.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"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 @@ -12,7 +12,7 @@
"detect-newline": "^3.0.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"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 @@ -25,7 +25,7 @@
"pretty-format": "^24.9.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"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 @@ -21,7 +21,7 @@
"@types/jsdom": "^12.2.4"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-environment-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"jest-util": "^24.9.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-environment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"jest-mock": "^24.9.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-fake-timers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/lolex": "^5.1.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-get-type/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"directory": "packages/jest-get-type"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"license": "MIT",
"main": "build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"fsevents": "^2.1.2"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@types/babel__traverse": "^7.0.4"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-leak-detector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"weak-napi": "^1.0.3"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-matcher-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"directory": "packages/jest-matcher-utils"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"license": "MIT",
"main": "build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-message-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"directory": "packages/jest-message-util"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"license": "MIT",
"main": "build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"directory": "packages/jest-mock"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"dependencies": {
"@jest/types": "^24.9.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-phabricator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@jest/test-result": "^24.9.0"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"license": "MIT",
"main": "build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-regex-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"directory": "packages/jest-regex-util"
},
"engines": {
"node": ">= 8"
"node": ">= 8.3"
},
"license": "MIT",
"main": "build/index.js",
Expand Down
Loading

0 comments on commit b2c8a69

Please sign in to comment.