Skip to content

Commit

Permalink
test_runner: use v8.serialize instead of TAP
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
MoLow committed Jul 6, 2023
1 parent 13bc548 commit bdca468
Show file tree
Hide file tree
Showing 19 changed files with 303 additions and 4,600 deletions.
3 changes: 2 additions & 1 deletion doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,8 @@ on unsupported platforms will not be fixed.
### `NODE_TEST_CONTEXT=value`

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

### `NODE_TLS_REJECT_UNAUTHORIZED=value`

Expand Down
39 changes: 39 additions & 0 deletions lib/internal/test_runner/reporter/v8-serializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

const { DefaultSerializer } = require('v8');
const { Buffer } = require('buffer');
const { serializeError } = require('internal/error_serdes');


module.exports = async function* v8Reporter(source) {
const serializer = new DefaultSerializer();

for await (const item of source) {
const originalError = item.data.details?.error;
if (originalError) {
// Error is overriden with a serialized version, so that it can be
// deserialized in the parent process.
// Error is restored after serialization.
item.data.details.error = serializeError(originalError);
}
// Add 4 bytes, to later populate with message length
serializer.writeRawBytes(Buffer.allocUnsafe(4));
serializer.writeHeader();
serializer.writeValue(item);

if (originalError) {
item.data.details.error = originalError;
}

const serializedMessage = serializer.releaseBuffer();
const serializedMessageLength = serializedMessage.length - 4;

serializedMessage.set([
serializedMessageLength >> 24 & 0xFF,
serializedMessageLength >> 16 & 0xFF,
serializedMessageLength >> 8 & 0xFF,
serializedMessageLength & 0xFF,
], 0);
yield serializedMessage;
}
};

0 comments on commit bdca468

Please sign in to comment.