@stanterprise/playwright-reporter 0.0.16 → 0.0.18

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
@@ -93,6 +93,80 @@ npx playwright test
93
93
  | `maxAttachmentSize` | number | `10485760` | Max attachment content size in bytes (10MB default) |
94
94
  | `verbose` | boolean | `false` | Enable verbose logging |
95
95
 
96
+ ## Sharding Support
97
+
98
+ The reporter automatically detects and reports when tests are running in sharded mode. When sharding is configured, the reporter includes the following metadata in test run events:
99
+
100
+ - `shard.current`: The current shard number (1-based)
101
+ - `shard.total`: The total number of shards
102
+
103
+ ### Configuring Sharding
104
+
105
+ In your `playwright.config.ts`:
106
+
107
+ ```typescript
108
+ import { defineConfig } from "@playwright/test";
109
+
110
+ export default defineConfig({
111
+ shard: { total: 5, current: 1 },
112
+ reporter: [["stanterprise-playwright-reporter"]],
113
+ });
114
+ ```
115
+
116
+ Or via CLI:
117
+
118
+ ```bash
119
+ npx playwright test --shard=1/5
120
+ npx playwright test --shard=2/5
121
+ # ... etc
122
+ ```
123
+
124
+ ### Aggregating Results Across Shards
125
+
126
+ **Important:** To have a complete set of tests accumulated in the observability server, you must specify the same `STANTERPRISE_RUN_ID` environment variable for all shards. This ensures that results from all shards are associated with the same test run.
127
+
128
+ ```bash
129
+ # Set the same run ID for all shards
130
+ export STANTERPRISE_RUN_ID="my-test-run-123"
131
+
132
+ # Run all shards with the same run ID
133
+ npx playwright test --shard=1/5
134
+ npx playwright test --shard=2/5
135
+ npx playwright test --shard=3/5
136
+ npx playwright test --shard=4/5
137
+ npx playwright test --shard=5/5
138
+ ```
139
+
140
+ In CI/CD environments, you can use a unique identifier from your CI system:
141
+
142
+ ```bash
143
+ # GitHub Actions example
144
+ STANTERPRISE_RUN_ID="${GITHUB_RUN_ID}" npx playwright test --shard=1/5
145
+
146
+ # GitLab CI example
147
+ STANTERPRISE_RUN_ID="${CI_PIPELINE_ID}" npx playwright test --shard=1/5
148
+
149
+ # Jenkins example
150
+ STANTERPRISE_RUN_ID="${BUILD_ID}" npx playwright test --shard=1/5
151
+ ```
152
+
153
+ Without a shared `STANTERPRISE_RUN_ID`, each shard will generate its own unique run ID, and the results will be reported as separate test runs rather than a single aggregated run.
154
+
155
+ The shard information is automatically included in the metadata sent to the server, allowing you to:
156
+
157
+ - Track which tests ran on which shard
158
+ - Aggregate results from multiple shards
159
+ - Debug shard-specific issues
160
+
161
+ When verbose logging is enabled, you'll see shard information in the console output:
162
+
163
+ ```
164
+ Stanterprise Reporter: Test run started with ID: 123e4567-e89b-12d3-a456-426614174000
165
+ Number of tests: 42
166
+ Run started at: 2026-01-25T10:30:00.000Z
167
+ Shard: 1 of 5
168
+ ```
169
+
96
170
  ## What Gets Reported
97
171
 
98
172
  ### Test Events
@@ -240,7 +314,6 @@ This error can also occur when test event payloads exceed the gRPC message size
240
314
  ```
241
315
 
242
316
  2. **Reduce attachment sizes**:
243
-
244
317
  - Configure Playwright to save attachments to disk instead of embedding them
245
318
  - The reporter automatically uses file paths when available instead of content
246
319
 
@@ -19,6 +19,11 @@ function handleOnBeginEvent(config, suite, name, runId, client, options) {
19
19
  variables.forEach((value, key) => {
20
20
  metadata[key] = value;
21
21
  });
22
+ // Add shard information if present
23
+ if (config.shard) {
24
+ metadata["shard.current"] = String(config.shard.current);
25
+ metadata["shard.total"] = String(config.shard.total);
26
+ }
22
27
  const request = new events_1.ReportRunStartEventRequest({
23
28
  run_id: runId,
24
29
  name: name,
@@ -12,6 +12,24 @@ function handleOnStepEndEvent(test, result, step, runId, client, options) {
12
12
  // Build metadata from step annotations
13
13
  const metadata = (0, utils_1.buildStepMetadata)(step);
14
14
  const stepId = (0, utils_2.generateStepId)(step, test);
15
+ // Extract comprehensive error details if present
16
+ const errorMessage = step.error?.message || "";
17
+ const errorStack = step.error?.stack || "";
18
+ const errorValue = step.error?.value || "";
19
+ const errorSnippet = step.error?.snippet || "";
20
+ const errorLocation = step.error?.location
21
+ ? `${step.error.location.file}:${step.error.location.line}:${step.error.location.column}`
22
+ : "";
23
+ // Combine all error information into metadata for comprehensive error tracking
24
+ const errorMetadata = {};
25
+ if (errorStack)
26
+ errorMetadata.error_stack = (0, utils_1.truncateValue)(errorStack);
27
+ if (errorValue)
28
+ errorMetadata.error_value = (0, utils_1.truncateValue)(errorValue);
29
+ if (errorSnippet)
30
+ errorMetadata.error_snippet = (0, utils_1.truncateValue)(errorSnippet);
31
+ if (errorLocation)
32
+ errorMetadata.error_location = (0, utils_1.truncateValue)(errorLocation);
15
33
  // Build and send the StepEnd event
16
34
  const request = new events_1.StepEndEventRequest({
17
35
  step: new entities_1.StepRun({
@@ -23,12 +41,12 @@ function handleOnStepEndEvent(test, result, step, runId, client, options) {
23
41
  start_time: (0, utils_1.createTimestamp)(step.startTime),
24
42
  duration: (0, utils_1.createDuration)(step.duration),
25
43
  status: stepStatus,
26
- error: step.error ? step.error.message || "" : "",
27
- errors: step.error ? [step.error.message || ""] : [],
44
+ error: errorMessage,
45
+ errors: errorMessage ? [errorMessage] : [],
28
46
  location: step.location
29
47
  ? `${step.location.file}:${step.location.line}:${step.location.column}`
30
48
  : "",
31
- metadata: (0, utils_1.toMetadataMap)(metadata),
49
+ metadata: (0, utils_1.toMetadataMap)({ ...metadata, ...errorMetadata }),
32
50
  parent_step_id: step.parent
33
51
  ? (0, utils_2.generateStepId)(step.parent, test)
34
52
  : undefined,
package/dist/reporter.js CHANGED
@@ -45,6 +45,9 @@ class StanterpriseReporter {
45
45
  console.log(`Stanterprise Reporter: Test run started with ID: ${this.runId}`);
46
46
  console.log(`Number of tests: ${suite.allTests().length}`);
47
47
  console.log(`Run started at: ${this.runStartTime.toISOString()}`);
48
+ if (config.shard) {
49
+ console.log(`Shard: ${config.shard.current} of ${config.shard.total}`);
50
+ }
48
51
  }
49
52
  if (this.options.grpcEnabled) {
50
53
  (0, handlers_1.handleOnBeginEvent)(config, suite, process.env.STANTERPRISE_TEST_RUN_NAME || "Playwright Test Run", this.runId, this.grpcClient, this.options);
@@ -2,6 +2,13 @@
2
2
  * Utility functions for building metadata objects
3
3
  */
4
4
  import type { TestCase, TestResult, TestStep } from "@playwright/test/reporter";
5
+ /**
6
+ * Truncate a string to a maximum length with ellipsis indicator
7
+ * @param value String value to truncate
8
+ * @param maxLength Maximum length (default 100KB)
9
+ * @returns Truncated string with warning suffix if truncated
10
+ */
11
+ export declare function truncateValue(value: string, maxLength?: number): string;
5
12
  /**
6
13
  * Build metadata from annotations array
7
14
  * @param annotations Array of annotations with type and optional description
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.truncateValue = truncateValue;
3
4
  exports.buildAnnotationsMetadata = buildAnnotationsMetadata;
4
5
  exports.buildTestMetadata = buildTestMetadata;
5
6
  exports.buildStepMetadata = buildStepMetadata;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stanterprise/playwright-reporter",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
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": {
@@ -44,7 +44,7 @@
44
44
  "devDependencies": {
45
45
  "@playwright/test": "^1.52.0",
46
46
  "@types/jest": "^29.5.14",
47
- "@types/node": "^22.15.29",
47
+ "@types/node": "^22.19.7",
48
48
  "jest": "^29.7.0",
49
49
  "ts-jest": "^29.4.5",
50
50
  "typescript": "^5.9.3"