@stanterprise/playwright-reporter 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -20,11 +20,21 @@ function mapTestStatus(status) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
function handleOnEndEvent(result, runId, client, options) {
|
|
23
|
+
// Validate and sanitize inputs to prevent serialization failures
|
|
24
|
+
const startTimeMs = result.startTime?.getTime();
|
|
25
|
+
const duration = result.duration;
|
|
26
|
+
// Ensure valid numeric values (protobuf cannot serialize NaN or undefined)
|
|
27
|
+
const validStartTimeMs = typeof startTimeMs === "number" && !isNaN(startTimeMs)
|
|
28
|
+
? startTimeMs
|
|
29
|
+
: Date.now();
|
|
30
|
+
const validDuration = typeof duration === "number" && !isNaN(duration) && duration >= 0
|
|
31
|
+
? duration
|
|
32
|
+
: 0;
|
|
23
33
|
const request = new events_1.TestRunEndEventRequest({
|
|
24
34
|
run_id: runId,
|
|
25
35
|
final_status: mapTestStatus(result.status),
|
|
26
|
-
start_time: (0, utils_1.createTimestampFromMs)(
|
|
27
|
-
duration: (0, utils_1.createDuration)(
|
|
36
|
+
start_time: (0, utils_1.createTimestampFromMs)(validStartTimeMs),
|
|
37
|
+
duration: (0, utils_1.createDuration)(validDuration),
|
|
28
38
|
});
|
|
29
39
|
(0, grpcClient_1.reportUnary)(options, client, "/testsystem.v1.observer.TestEventCollector/ReportEnd", request, options.grpcTimeout).catch((error) => {
|
|
30
40
|
if (error instanceof Error) {
|
|
@@ -12,15 +12,24 @@ const Timestamp = protobuf_1.google.google.protobuf.Timestamp;
|
|
|
12
12
|
* Create a protobuf Timestamp from a JavaScript Date
|
|
13
13
|
*/
|
|
14
14
|
function createTimestamp(date) {
|
|
15
|
+
const ms = date.getTime();
|
|
16
|
+
// Validate to prevent NaN from causing protobuf serialization failures
|
|
17
|
+
if (isNaN(ms)) {
|
|
18
|
+
throw new Error(`Invalid date provided to createTimestamp: ${date.toString()}`);
|
|
19
|
+
}
|
|
15
20
|
return new Timestamp({
|
|
16
|
-
seconds: Math.floor(
|
|
17
|
-
nanos: (
|
|
21
|
+
seconds: Math.floor(ms / 1000),
|
|
22
|
+
nanos: (ms % 1000) * 1000000,
|
|
18
23
|
});
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* Create a protobuf Timestamp from milliseconds since epoch
|
|
22
27
|
*/
|
|
23
28
|
function createTimestampFromMs(ms) {
|
|
29
|
+
// Validate to prevent NaN from causing protobuf serialization failures
|
|
30
|
+
if (typeof ms !== "number" || isNaN(ms)) {
|
|
31
|
+
throw new Error(`Invalid milliseconds provided to createTimestampFromMs: ${ms}`);
|
|
32
|
+
}
|
|
24
33
|
return new Timestamp({
|
|
25
34
|
seconds: Math.floor(ms / 1000),
|
|
26
35
|
nanos: (ms % 1000) * 1000000,
|
|
@@ -38,6 +47,13 @@ function createTimestampFromMs(ms) {
|
|
|
38
47
|
* @returns A Duration object (implemented as Timestamp due to export limitations)
|
|
39
48
|
*/
|
|
40
49
|
function createDuration(durationMs) {
|
|
50
|
+
// Validate to prevent NaN from causing protobuf serialization failures
|
|
51
|
+
if (typeof durationMs !== "number" || isNaN(durationMs)) {
|
|
52
|
+
throw new Error(`Invalid duration provided to createDuration: ${durationMs}`);
|
|
53
|
+
}
|
|
54
|
+
if (durationMs < 0) {
|
|
55
|
+
throw new Error(`Negative duration provided to createDuration: ${durationMs}`);
|
|
56
|
+
}
|
|
41
57
|
return new Timestamp({
|
|
42
58
|
seconds: Math.floor(durationMs / 1000),
|
|
43
59
|
nanos: (durationMs % 1000) * 1000000,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stanterprise/playwright-reporter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Custom Playwright test reporter that sends test results to Stanterprise via gRPC",
|
|
5
5
|
"homepage": "https://github.com/stanterprise/stanterprise-playwright-reporter#readme",
|
|
6
6
|
"bugs": {
|