-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
96 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {ProjectConfig} from 'types/Config'; | ||
|
||
// This works for nodes without the async_hooks as the require's lazy | ||
// $FlowFixMe: Node core module | ||
import asyncHooks from 'async_hooks'; | ||
|
||
import { | ||
formatStackTrace, | ||
separateMessageFromStack, | ||
} from '../../jest-message-util/build'; | ||
|
||
// Inspired by https://github.com/mafintosh/why-is-node-running/blob/master/index.js | ||
// Extracted as we want to format the result ourselves | ||
export default function collectHandles(): () => Array<Error> { | ||
const activeHandles: Map<string, Error> = new Map(); | ||
|
||
function initHook(asyncId, type) { | ||
if (type === 'TIMERWRAP') return; | ||
const error = new Error(type); | ||
|
||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(error, initHook); | ||
} | ||
|
||
if (error.stack.includes('Runtime.requireModule')) { | ||
activeHandles.set(asyncId, error); | ||
} | ||
} | ||
|
||
let hook; | ||
|
||
try { | ||
hook = asyncHooks.createHook({ | ||
destroy(asyncId) { | ||
activeHandles.delete(asyncId); | ||
}, | ||
init: initHook, | ||
}); | ||
|
||
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; | ||
} | ||
} | ||
|
||
return () => { | ||
hook.disable(); | ||
|
||
const result = Array.from(activeHandles.values()); | ||
|
||
activeHandles.clear(); | ||
|
||
return result; | ||
}; | ||
} | ||
|
||
export function formatHandleErrors( | ||
errors: Array<Error>, | ||
config: ProjectConfig, | ||
): Array<string> { | ||
return errors.map(err => { | ||
const {message, stack} = separateMessageFromStack(err.stack); | ||
|
||
return ( | ||
message + '\n\n' + formatStackTrace(stack, config, {noStackTrace: false}) | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8790,10 +8790,6 @@ stack-utils@^1.0.1: | |
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-1.0.1.tgz#d4f33ab54e8e38778b0ca5cfd3b3afb12db68620" | ||
|
||
[email protected]: | ||
version "0.0.2" | ||
resolved "https://registry.yarnpkg.com/stackback/-/stackback-0.0.2.tgz#1ac8a0d9483848d1695e418b6d031a3c3ce68e3b" | ||
|
||
stacktrace-parser@^0.1.3: | ||
version "0.1.4" | ||
resolved "https://registry.yarnpkg.com/stacktrace-parser/-/stacktrace-parser-0.1.4.tgz#01397922e5f62ecf30845522c95c4fe1d25e7d4e" | ||
|
@@ -9673,12 +9669,6 @@ which@^1.2.1, which@^1.2.12, which@^1.2.14, which@^1.2.9, which@^1.3.0: | |
dependencies: | ||
isexe "^2.0.0" | ||
|
||
why-is-node-running@^2.0.2: | ||
version "2.0.2" | ||
resolved "https://registry.yarnpkg.com/why-is-node-running/-/why-is-node-running-2.0.2.tgz#faf352f095356c8c37a28bf645f874e5648c8d02" | ||
dependencies: | ||
stackback "0.0.2" | ||
|
||
wide-align@^1.1.0: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.2.tgz#571e0f1b0604636ebc0dfc21b0339bbe31341710" | ||
|