Skip to content

Commit 4057eb4

Browse files
committed
test: show more information in test-http2-debug upon failure
Use spawnSyncAndAssert() so that the stderr is logged when it doesn't match expectations.
1 parent 4454d09 commit 4057eb4

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

test/parallel/test-http2-debug.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
'use strict';
2+
23
const common = require('../common');
34
if (!common.hasCrypto)
45
common.skip('missing crypto');
56
const assert = require('assert');
6-
const child_process = require('child_process');
7+
const { spawnSyncAndAssert } = require('../common/child_process');
78
const path = require('path');
89

9-
process.env.NODE_DEBUG_NATIVE = 'http2';
10-
process.env.NODE_DEBUG = 'http2';
11-
const { stdout, stderr } = child_process.spawnSync(process.execPath, [
10+
spawnSyncAndAssert(process.execPath, [
1211
path.resolve(__dirname, 'test-http2-ping.js'),
13-
], { encoding: 'utf8' });
12+
], {
13+
env: {
14+
...process.env,
15+
NODE_DEBUG: 'http2',
16+
NODE_DEBUG_NATIVE: 'http2',
17+
},
18+
},
19+
{
20+
trim: true,
21+
stderr(output) {
22+
assert.match(output,
23+
/Setting the NODE_DEBUG environment variable to 'http2' can expose sensitive data/);
24+
assert.match(output, /\(such as passwords, tokens and authentication headers\) in the resulting log\.\r?\n/);
25+
assert.match(output, /Http2Session client \(\d+\) handling data frame for stream \d+\r?\n/);
26+
assert.match(output, /HttpStream \d+ \(\d+\) \[Http2Session client \(\d+\)\] reading starting\r?\n/);
27+
assert.match(output, /HttpStream \d+ \(\d+\) \[Http2Session client \(\d+\)\] closed with code 0\r?\n/);
28+
assert.match(output, /HttpStream \d+ \(\d+\) \[Http2Session server \(\d+\)\] closed with code 0\r?\n/);
29+
assert.match(output, /HttpStream \d+ \(\d+\) \[Http2Session server \(\d+\)\] tearing down stream\r?\n/);
30+
},
31+
stdout: ''
32+
});
1433

15-
assert(stderr.match(/Setting the NODE_DEBUG environment variable to 'http2' can expose sensitive data \(such as passwords, tokens and authentication headers\) in the resulting log\.\r?\n/),
16-
stderr);
17-
assert(stderr.match(/Http2Session client \(\d+\) handling data frame for stream \d+\r?\n/),
18-
stderr);
19-
assert(stderr.match(/HttpStream \d+ \(\d+\) \[Http2Session client \(\d+\)\] reading starting\r?\n/),
20-
stderr);
21-
assert(stderr.match(/HttpStream \d+ \(\d+\) \[Http2Session client \(\d+\)\] closed with code 0\r?\n/),
22-
stderr);
23-
assert(stderr.match(/HttpStream \d+ \(\d+\) \[Http2Session server \(\d+\)\] closed with code 0\r?\n/),
24-
stderr);
25-
assert(stderr.match(/HttpStream \d+ \(\d+\) \[Http2Session server \(\d+\)\] tearing down stream\r?\n/),
26-
stderr);
27-
assert.strictEqual(stdout.trim(), '');

0 commit comments

Comments
 (0)