|
| 1 | +// Flags: --expose-internals |
| 2 | + |
| 3 | +'use strict'; |
| 4 | + |
| 5 | +const { internalBinding } = require('internal/test/binding'); |
| 6 | + |
| 7 | +// Monkey patch before requiring anything |
| 8 | +class DummyParser { |
| 9 | + constructor(type) { |
| 10 | + this.test_type = type; |
| 11 | + } |
| 12 | +} |
| 13 | +DummyParser.REQUEST = Symbol(); |
| 14 | +internalBinding('http_parser').HTTPParser = DummyParser; |
| 15 | + |
| 16 | +const common = require('../common'); |
| 17 | +const assert = require('assert'); |
| 18 | +const { spawn } = require('child_process'); |
| 19 | +const { parsers } = require('_http_common'); |
| 20 | + |
| 21 | +// Test _http_common was not loaded before monkey patching |
| 22 | +const parser = parsers.alloc(); |
| 23 | +assert.strictEqual(parser instanceof DummyParser, true); |
| 24 | +assert.strictEqual(parser.test_type, DummyParser.REQUEST); |
| 25 | + |
| 26 | +if (process.argv[2] !== 'child') { |
| 27 | + // Also test in a child process with IPC (specific case of https://github.com/nodejs/node/issues/23716) |
| 28 | + const child = spawn(process.execPath, [ |
| 29 | + '--expose-internals', __filename, 'child' |
| 30 | + ], { |
| 31 | + stdio: ['inherit', 'inherit', 'inherit', 'ipc'] |
| 32 | + }); |
| 33 | + child.on('exit', common.mustCall((code, signal) => { |
| 34 | + assert.strictEqual(code, 0); |
| 35 | + assert.strictEqual(signal, null); |
| 36 | + })); |
| 37 | +} |
0 commit comments