forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: extract globals & use in test-abort-backtrace
First steps towards not needing to require test/common/index.js everywhere. Refs: nodejs#20128 (comment)
- Loading branch information
1 parent
57e3015
commit a0a4a98
Showing
4 changed files
with
77 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* eslint-disable node-core/required-modules */ | ||
'use strict'; | ||
const assert = require('assert'); | ||
|
||
let knownGlobals = [ | ||
Buffer, | ||
clearImmediate, | ||
clearInterval, | ||
clearTimeout, | ||
global, | ||
process, | ||
setImmediate, | ||
setInterval, | ||
setTimeout | ||
]; | ||
|
||
if (global.gc) { | ||
knownGlobals.push(global.gc); | ||
} | ||
|
||
if (global.DTRACE_HTTP_SERVER_RESPONSE) { | ||
knownGlobals.push(DTRACE_HTTP_SERVER_RESPONSE); | ||
knownGlobals.push(DTRACE_HTTP_SERVER_REQUEST); | ||
knownGlobals.push(DTRACE_HTTP_CLIENT_RESPONSE); | ||
knownGlobals.push(DTRACE_HTTP_CLIENT_REQUEST); | ||
knownGlobals.push(DTRACE_NET_STREAM_END); | ||
knownGlobals.push(DTRACE_NET_SERVER_CONNECTION); | ||
} | ||
|
||
if (global.COUNTER_NET_SERVER_CONNECTION) { | ||
knownGlobals.push(COUNTER_NET_SERVER_CONNECTION); | ||
knownGlobals.push(COUNTER_NET_SERVER_CONNECTION_CLOSE); | ||
knownGlobals.push(COUNTER_HTTP_SERVER_REQUEST); | ||
knownGlobals.push(COUNTER_HTTP_SERVER_RESPONSE); | ||
knownGlobals.push(COUNTER_HTTP_CLIENT_REQUEST); | ||
knownGlobals.push(COUNTER_HTTP_CLIENT_RESPONSE); | ||
} | ||
|
||
if (process.env.NODE_TEST_KNOWN_GLOBALS) { | ||
const knownFromEnv = process.env.NODE_TEST_KNOWN_GLOBALS.split(','); | ||
allowGlobals(...knownFromEnv); | ||
} | ||
|
||
function allowGlobals(...whitelist) { | ||
knownGlobals = knownGlobals.concat(whitelist); | ||
} | ||
exports.allowGlobals = allowGlobals; | ||
|
||
function leakedGlobals() { | ||
const leaked = []; | ||
|
||
for (const val in global) { | ||
if (!knownGlobals.includes(global[val])) { | ||
leaked.push(val); | ||
} | ||
} | ||
|
||
if (global.__coverage__) { | ||
return leaked.filter((varname) => !/^(?:cov_|__cov)/.test(varname)); | ||
} else { | ||
return leaked; | ||
} | ||
} | ||
exports.leakedGlobals = leakedGlobals; | ||
|
||
process.on('exit', function() { | ||
const leaked = leakedGlobals(); | ||
if (leaked.length > 0) { | ||
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`); | ||
} | ||
}); |
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