@stanterprise/playwright-reporter 0.0.21 → 0.1.1

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.
package/README.md CHANGED
@@ -49,7 +49,7 @@ export default defineConfig({
49
49
  grpcMaxMessageSize: 104857600, // Max message size (100MB default)
50
50
  maxAttachmentSize: 10485760, // Max attachment size (10MB default)
51
51
  verbose: false, // Enable verbose logging
52
- debug: false, // Enable debug mode (writes gRPC messages to JSONL file)
52
+ debug: false, // Enable debug mode (writes gRPC messages to JSONL file)
53
53
  debugFile: "stanterprise-debug.jsonl", // Path for debug JSONL output
54
54
  },
55
55
  ],
@@ -63,6 +63,7 @@ export default defineConfig({
63
63
  You can also configure the reporter using environment variables:
64
64
 
65
65
  - `STANTERPRISE_GRPC_ADDRESS`: gRPC server address (default: `localhost:50051`)
66
+ - `STANTERPRISE_GRPC_HOST`: gRPC server host
66
67
  - `STANTERPRISE_GRPC_ENABLED`: Enable/disable gRPC reporting (default: `true`)
67
68
  - `STANTERPRISE_META_*`: Custom metadata fields for test runs (prefix will be stripped)
68
69
  - `STANTERPRISE_DEBUG`: Enable debug mode — captures outgoing gRPC messages to a JSONL file (default: `false`; case-insensitive: `"true"`, `"TRUE"`, `"True"` all work)
@@ -89,18 +90,20 @@ npx playwright test
89
90
 
90
91
  ## Configuration Options
91
92
 
92
- | Option | Type | Default | Description |
93
- | -------------------- | ------- | ----------------- | --------------------------------------------------- |
94
- | `grpcAddress` | string | `localhost:50051` | gRPC server address |
95
- | `grpcEnabled` | boolean | `true` | Enable/disable gRPC reporting |
96
- | `grpcTimeout` | number | `1000` | Timeout for gRPC calls in milliseconds |
97
- | `grpcMaxMessageSize` | number | `104857600` | Max message size in bytes (100MB default) |
98
- | `maxAttachmentSize` | number | `10485760` | Max attachment content size in bytes (10MB default) |
99
- | `verbose` | boolean | `false` | Enable verbose logging |
100
- | `grpcMaxRetries` | number | `3` | Maximum number of retry attempts for failed gRPC calls |
101
- | `grpcRetryDelay` | number | `100` | Initial delay for retries in ms (uses exponential backoff) |
102
- | `debug` | boolean | `false` | Enable debug mode — writes all outgoing gRPC messages to a JSONL file. **Warning:** output may include sensitive request payloads and grow very large. Use only in controlled environments. |
103
- | `debugFile` | string | `stanterprise-debug.jsonl` | File path for debug JSONL output. Parent directories are created automatically if they do not exist. |
93
+ | Option | Type | Default | Description |
94
+ | -------------------- | ------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
95
+ | `grpcAddress` | string | `localhost:50051` | Full gRPC server address. Takes precedence over `grpcHost` and `grpcPort`. |
96
+ | `grpcHost` | string | | gRPC server host. Used when `grpcAddress` is not provided. Combined with `grpcPort` to form the address. |
97
+ | `grpcPort` | number | `50051` | gRPC server port. Used when `grpcAddress` is not provided. Combined with `grpcHost` to form the address. |
98
+ | `grpcEnabled` | boolean | `true` | Enable/disable gRPC reporting |
99
+ | `grpcTimeout` | number | `1000` | Timeout for gRPC calls in milliseconds |
100
+ | `grpcMaxMessageSize` | number | `104857600` | Max message size in bytes (100MB default) |
101
+ | `maxAttachmentSize` | number | `10485760` | Max attachment content size in bytes (10MB default) |
102
+ | `verbose` | boolean | `false` | Enable verbose logging |
103
+ | `grpcMaxRetries` | number | `3` | Maximum number of retry attempts for failed gRPC calls |
104
+ | `grpcRetryDelay` | number | `100` | Initial delay for retries in ms (uses exponential backoff) |
105
+ | `debug` | boolean | `false` | Enable debug mode — writes all outgoing gRPC messages to a JSONL file. **Warning:** output may include sensitive request payloads and grow very large. Use only in controlled environments. |
106
+ | `debugFile` | string | `stanterprise-debug.jsonl` | File path for debug JSONL output. Parent directories are created automatically if they do not exist. |
104
107
 
105
108
  ### Retry Configuration
106
109
 
@@ -112,10 +115,11 @@ The reporter automatically retries failed gRPC calls for transient errors using
112
115
  **Exponential backoff formula**: `grpcRetryDelay * (2 ^ attemptNumber)`
113
116
 
114
117
  Example with default settings (`grpcRetryDelay: 100`, `grpcMaxRetries: 3`):
118
+
115
119
  - Initial attempt: Immediate
116
- - Retry 1: Wait 100ms (100 * 2^0)
117
- - Retry 2: Wait 200ms (100 * 2^1)
118
- - Retry 3: Wait 400ms (100 * 2^2)
120
+ - Retry 1: Wait 100ms (100 \* 2^0)
121
+ - Retry 2: Wait 200ms (100 \* 2^1)
122
+ - Retry 3: Wait 400ms (100 \* 2^2)
119
123
 
120
124
  ```typescript
121
125
  export default defineConfig({
@@ -123,9 +127,9 @@ export default defineConfig({
123
127
  [
124
128
  "stanterprise-playwright-reporter",
125
129
  {
126
- grpcMaxRetries: 5, // Try up to 5 times
127
- grpcRetryDelay: 200, // Start with 200ms delay
128
- verbose: true, // Log retry attempts
130
+ grpcMaxRetries: 5, // Try up to 5 times
131
+ grpcRetryDelay: 200, // Start with 200ms delay
132
+ verbose: true, // Log retry attempts
129
133
  },
130
134
  ],
131
135
  ],
@@ -136,7 +140,7 @@ To disable retries:
136
140
 
137
141
  ```typescript
138
142
  {
139
- grpcMaxRetries: 0 // No retries, fail fast
143
+ grpcMaxRetries: 0; // No retries, fail fast
140
144
  }
141
145
  ```
142
146
 
@@ -2,4 +2,4 @@ import { FullResult } from "@playwright/test/reporter";
2
2
  import { StanterpriseReporterOptions } from "../types";
3
3
  import * as grpc from "@grpc/grpc-js";
4
4
  import { MessageQueue } from "../client/messageQueue";
5
- export declare function handleOnEndEvent(result: FullResult, runId: string, client: grpc.Client, options: StanterpriseReporterOptions, queue?: MessageQueue): void;
5
+ export declare function handleOnEndEvent(result: FullResult, runId: string, client: grpc.Client, options: StanterpriseReporterOptions, queue?: MessageQueue, metadata?: Record<string, string>): void;
@@ -19,7 +19,7 @@ function mapTestStatus(status) {
19
19
  return common_1.TestStatus.UNKNOWN;
20
20
  }
21
21
  }
22
- function handleOnEndEvent(result, runId, client, options, queue) {
22
+ function handleOnEndEvent(result, runId, client, options, queue, metadata) {
23
23
  // Validate and sanitize inputs to prevent serialization failures
24
24
  const startTimeMs = result.startTime?.getTime();
25
25
  const duration = result.duration;
@@ -35,6 +35,7 @@ function handleOnEndEvent(result, runId, client, options, queue) {
35
35
  final_status: mapTestStatus(result.status),
36
36
  start_time: (0, utils_1.createTimestampFromMs)(validStartTimeMs),
37
37
  duration: (0, utils_1.createDuration)(validDuration),
38
+ metadata: (0, utils_1.toMetadataMap)(metadata || {}),
38
39
  });
39
40
  (0, grpcClient_1.reportUnary)(options, client, "/testsystem.v1.observer.TestEventCollector/ReportRunEnd", request, options.grpcTimeout, queue).catch((error) => {
40
41
  if (error instanceof Error) {
@@ -6,6 +6,7 @@ export default class StanterpriseReporter implements Reporter {
6
6
  private runId;
7
7
  private runStartTime;
8
8
  private messageQueue;
9
+ private metadata;
9
10
  constructor(options?: StanterpriseReporterOptions);
10
11
  onBegin(config: FullConfig, suite: Suite): void;
11
12
  onExit(): Promise<void>;
package/dist/reporter.js CHANGED
@@ -19,6 +19,7 @@ class StanterpriseReporter {
19
19
  this.runStartTime = new Date();
20
20
  // Sequential message queue – guarantees ordered delivery to the server
21
21
  this.messageQueue = new messageQueue_1.MessageQueue();
22
+ this.metadata = {};
22
23
  this.options = (0, optionsMapper_1.default)(options);
23
24
  if (this.options.verbose) {
24
25
  console.log("Stanterprise Reporter: Initialized with options:", {
@@ -34,6 +35,10 @@ class StanterpriseReporter {
34
35
  (0, debugLogger_1.initDebugFile)(this.options);
35
36
  }
36
37
  onBegin(config, suite) {
38
+ if (config.shard) {
39
+ this.metadata["shard.current"] = String(config.shard.current);
40
+ this.metadata["shard.total"] = String(config.shard.total);
41
+ }
37
42
  // Lazily create the client if enabled.
38
43
  if (this.options.grpcEnabled) {
39
44
  this.grpcClient = (0, grpcClient_1.default)(this.options);
@@ -81,7 +86,7 @@ class StanterpriseReporter {
81
86
  console.log(`Playwright start time: ${result.startTime.toISOString()}`);
82
87
  }
83
88
  if (this.options.grpcEnabled) {
84
- (0, handlers_1.handleOnEndEvent)(result, this.runId, this.grpcClient, this.options, this.messageQueue);
89
+ (0, handlers_1.handleOnEndEvent)(result, this.runId, this.grpcClient, this.options, this.messageQueue, this.metadata);
85
90
  }
86
91
  return Promise.resolve();
87
92
  }
package/dist/types.d.ts CHANGED
@@ -10,6 +10,19 @@ export interface StanterpriseReporterOptions {
10
10
  * @default "localhost:50051" or process.env.STANTERPRISE_GRPC_ADDRESS
11
11
  */
12
12
  grpcAddress?: string;
13
+ /**
14
+ * Optional separate host for gRPC when `grpcAddress` is not provided.
15
+ * This allows specifying gRPC connection details separately from other potential uses of `grpcAddress`.
16
+ * If `grpcAddress` is provided, it takes precedence over this field.
17
+ */
18
+ grpcHost?: string;
19
+ /**
20
+ * Optional separate port for gRPC when `grpcAddress` is not provided.
21
+ * This allows specifying gRPC connection details separately from other potential uses of `grpcAddress`.
22
+ * If `grpcAddress` is provided, it takes precedence over this field.
23
+ * @default 50051
24
+ */
25
+ grpcPort?: number;
13
26
  /**
14
27
  * Whether gRPC reporting is enabled
15
28
  * @default true or process.env.STANTERPRISE_GRPC_ENABLED !== "false"
@@ -8,19 +8,16 @@ exports.default = defineOptions;
8
8
  */
9
9
  function defineOptions(providedOptions) {
10
10
  const result = {};
11
- result.grpcAddress =
12
- providedOptions.grpcAddress ||
13
- process.env.STANTERPRISE_GRPC_ADDRESS ||
14
- "localhost:50051";
11
+ result.grpcAddress = identifyAddress(providedOptions);
15
12
  result.grpcEnabled =
16
13
  providedOptions.grpcEnabled ??
17
14
  (process.env.STANTERPRISE_GRPC_ENABLED || "true").toLowerCase() !== "false";
18
- result.grpcTimeout = providedOptions.grpcTimeout || 1000;
19
- result.grpcMaxMessageSize = providedOptions.grpcMaxMessageSize || 104857600;
20
- result.maxAttachmentSize = providedOptions.maxAttachmentSize || 10485760;
21
- result.verbose = providedOptions.verbose || false;
15
+ result.grpcTimeout = providedOptions.grpcTimeout ?? 1000;
16
+ result.grpcMaxMessageSize = providedOptions.grpcMaxMessageSize ?? 104857600;
17
+ result.maxAttachmentSize = providedOptions.maxAttachmentSize ?? 10485760;
18
+ result.verbose = providedOptions.verbose ?? false;
22
19
  result.grpcMaxRetries = providedOptions.grpcMaxRetries ?? 3;
23
- result.grpcRetryDelay = providedOptions.grpcRetryDelay || 100;
20
+ result.grpcRetryDelay = providedOptions.grpcRetryDelay ?? 100;
24
21
  result.debug =
25
22
  providedOptions.debug ??
26
23
  (process.env.STANTERPRISE_DEBUG || "").toLowerCase() === "true";
@@ -30,3 +27,22 @@ function defineOptions(providedOptions) {
30
27
  "stanterprise-debug.jsonl";
31
28
  return result;
32
29
  }
30
+ function identifyAddress(providedOptions) {
31
+ if (providedOptions.grpcAddress) {
32
+ return providedOptions.grpcAddress;
33
+ }
34
+ if (process.env.STANTERPRISE_GRPC_ADDRESS) {
35
+ return process.env.STANTERPRISE_GRPC_ADDRESS;
36
+ }
37
+ if (process.env.STANTERPRISE_GRPC_HOST) {
38
+ const host = process.env.STANTERPRISE_GRPC_HOST;
39
+ const port = process.env.STANTERPRISE_GRPC_PORT || "50051";
40
+ return `${host}:${port}`;
41
+ }
42
+ if (providedOptions.grpcHost) {
43
+ const host = providedOptions.grpcHost;
44
+ const port = providedOptions.grpcPort ?? 50051;
45
+ return `${host}:${port}`;
46
+ }
47
+ return "localhost:50051";
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stanterprise/playwright-reporter",
3
- "version": "0.0.21",
3
+ "version": "0.1.1",
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": {
@@ -53,6 +53,6 @@
53
53
  "@grpc/grpc-js": "^1.14.1",
54
54
  "@protobuf-ts/grpc-transport": "^2.11.1",
55
55
  "@protobuf-ts/grpcweb-transport": "^2.11.1",
56
- "@stanterprise/protobuf": "^0.0.21"
56
+ "@stanterprise/protobuf": "^0.1.1"
57
57
  }
58
58
  }