Skip to content

Commit 9ff9782

Browse files
Trottaddaleax
authored andcommitted
test: remove common module from test it thwarts
test-global-console-exists cannot use the common module as explained in a comment but it was included later anyway. This change removes it. PR-URL: #13748 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0a9e96e commit 9ff9782

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

test/parallel/test-global-console-exists.js

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
11
/* eslint-disable required-modules */
2-
// ordinarily test files must require('common') but that action causes
3-
// the global console to be compiled, defeating the purpose of this test
42

53
'use strict';
64

7-
const common = require('../common');
5+
// Ordinarily test files must require('common') but that action causes
6+
// the global console to be compiled, defeating the purpose of this test.
7+
88
const assert = require('assert');
99
const EventEmitter = require('events');
1010
const leakWarning = /EventEmitter memory leak detected\. 2 hello listeners/;
1111

12-
common.hijackStderr(common.mustCall(function(data) {
13-
if (process.stderr.writeTimes === 0) {
14-
assert.ok(leakWarning.test(data));
15-
} else {
16-
assert.fail('stderr.write should be called only once');
17-
}
18-
}));
19-
20-
process.on('warning', function(warning) {
12+
let writeTimes = 0;
13+
let warningTimes = 0;
14+
process.on('warning', () => {
2115
// This will be called after the default internal
2216
// process warning handler is called. The default
2317
// process warning writes to the console, which will
2418
// invoke the monkeypatched process.stderr.write
2519
// below.
26-
assert.strictEqual(process.stderr.writeTimes, 1);
20+
assert.strictEqual(writeTimes, 1);
2721
EventEmitter.defaultMaxListeners = oldDefault;
28-
// when we get here, we should be done
22+
warningTimes++;
23+
});
24+
25+
process.on('exit', () => {
26+
assert.strictEqual(warningTimes, 1);
2927
});
3028

29+
process.stderr.write = (data) => {
30+
if (writeTimes === 0)
31+
assert.ok(leakWarning.test(data));
32+
else
33+
assert.fail('stderr.write should be called only once');
34+
35+
writeTimes++;
36+
};
37+
3138
const oldDefault = EventEmitter.defaultMaxListeners;
3239
EventEmitter.defaultMaxListeners = 1;
3340

3441
const e = new EventEmitter();
35-
e.on('hello', common.noop);
36-
e.on('hello', common.noop);
42+
e.on('hello', () => {});
43+
e.on('hello', () => {});
3744

3845
// TODO: Figure out how to validate console. Currently,
3946
// there is no obvious way of validating that console

0 commit comments

Comments
 (0)