Skip to content

Commit da27542

Browse files
MoLowtargos
authored andcommitted
test_runner: use v8.serialize instead of TAP
PR-URL: #47867 Fixes: #44656 Fixes: #47955 Fixes: #47481 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 7dd32f1 commit da27542

19 files changed

+303
-4600
lines changed

doc/api/cli.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,8 @@ on unsupported platforms will not be fixed.
23212321
### `NODE_TEST_CONTEXT=value`
23222322

23232323
If `value` equals `'child'`, test reporter options will be overridden and test
2324-
output will be sent to stdout in the TAP format.
2324+
output will be sent to stdout in the TAP format. If any other value is provided,
2325+
Node.js makes no guarantees about the reporter format used or its stability.
23252326

23262327
### `NODE_TLS_REJECT_UNAUTHORIZED=value`
23272328

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
const { DefaultSerializer } = require('v8');
4+
const { Buffer } = require('buffer');
5+
const { serializeError } = require('internal/error_serdes');
6+
7+
8+
module.exports = async function* v8Reporter(source) {
9+
const serializer = new DefaultSerializer();
10+
11+
for await (const item of source) {
12+
const originalError = item.data.details?.error;
13+
if (originalError) {
14+
// Error is overriden with a serialized version, so that it can be
15+
// deserialized in the parent process.
16+
// Error is restored after serialization.
17+
item.data.details.error = serializeError(originalError);
18+
}
19+
// Add 4 bytes, to later populate with message length
20+
serializer.writeRawBytes(Buffer.allocUnsafe(4));
21+
serializer.writeHeader();
22+
serializer.writeValue(item);
23+
24+
if (originalError) {
25+
item.data.details.error = originalError;
26+
}
27+
28+
const serializedMessage = serializer.releaseBuffer();
29+
const serializedMessageLength = serializedMessage.length - 4;
30+
31+
serializedMessage.set([
32+
serializedMessageLength >> 24 & 0xFF,
33+
serializedMessageLength >> 16 & 0xFF,
34+
serializedMessageLength >> 8 & 0xFF,
35+
serializedMessageLength & 0xFF,
36+
], 0);
37+
yield serializedMessage;
38+
}
39+
};

0 commit comments

Comments
 (0)