@testrelic/playwright-analytics 2.3.18 → 2.4.0
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 +198 -0
- package/dist/index.cjs +34 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -32
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/scripts/postinstall.cjs +54 -0
package/README.md
CHANGED
|
@@ -125,6 +125,189 @@ npx playwright test
|
|
|
125
125
|
|
|
126
126
|
The JSON report will be written to `./test-results/analytics-timeline.json` and the HTML report to `./test-results/analytics-timeline.html`.
|
|
127
127
|
|
|
128
|
+
## Cloud Integration
|
|
129
|
+
|
|
130
|
+
TestRelic can upload test results, action steps, artifacts (screenshots, videos), and network logs directly to the [TestRelic cloud platform](https://platform.testrelic.ai) for team-wide visibility, historical tracking, and the interactive Steps dashboard.
|
|
131
|
+
|
|
132
|
+
### Setup
|
|
133
|
+
|
|
134
|
+
**Step 1: Get your API key**
|
|
135
|
+
|
|
136
|
+
Sign in to [platform.testrelic.ai](https://platform.testrelic.ai) and generate an API key from **Settings → API Keys**.
|
|
137
|
+
|
|
138
|
+
**Step 2: Create the config file**
|
|
139
|
+
|
|
140
|
+
Installing the package automatically creates `.testrelic/testrelic-config.json` in your project root via a `postinstall` script. If it wasn't created (e.g. in CI with `CI=true`), create it manually:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"cloud": {
|
|
145
|
+
"apiKey": "$TESTRELIC_API_KEY",
|
|
146
|
+
"endpoint": "https://platform.testrelic.ai/api/v1",
|
|
147
|
+
"upload": "both"
|
|
148
|
+
},
|
|
149
|
+
"testrelic-repo": {
|
|
150
|
+
"name": "my-project"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Replace `my-project` with the name of your repository as it should appear in the cloud dashboard. The `apiKey` value of `"$TESTRELIC_API_KEY"` is automatically resolved from the environment variable of the same name at runtime — no secrets in your config file.
|
|
156
|
+
|
|
157
|
+
**Step 3: Set your API key in the environment**
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
export TESTRELIC_API_KEY=your_api_key_here
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
In CI, add `TESTRELIC_API_KEY` as a repository secret and pass it to the test job.
|
|
164
|
+
|
|
165
|
+
**Step 4: Enable cloud upload in your Playwright config**
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
// playwright.config.ts
|
|
169
|
+
export default defineConfig({
|
|
170
|
+
reporter: [
|
|
171
|
+
['list'],
|
|
172
|
+
[
|
|
173
|
+
'@testrelic/playwright-analytics',
|
|
174
|
+
{
|
|
175
|
+
cloud: {
|
|
176
|
+
apiKey: process.env.TESTRELIC_API_KEY,
|
|
177
|
+
endpoint: 'https://platform.testrelic.ai/api/v1',
|
|
178
|
+
upload: 'both',
|
|
179
|
+
uploadArtifacts: true,
|
|
180
|
+
artifactMaxSizeMb: 50,
|
|
181
|
+
},
|
|
182
|
+
includeActionSteps: true,
|
|
183
|
+
includeCodeSnippets: true,
|
|
184
|
+
includeNetworkStats: true,
|
|
185
|
+
includeArtifacts: true,
|
|
186
|
+
captureResponseBody: true,
|
|
187
|
+
captureRequestBody: true,
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
],
|
|
191
|
+
use: {
|
|
192
|
+
video: 'on',
|
|
193
|
+
screenshot: 'on',
|
|
194
|
+
trace: 'on',
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Config File Reference
|
|
200
|
+
|
|
201
|
+
The `.testrelic/testrelic-config.json` file is the project-level configuration for cloud integration. It should be committed to version control.
|
|
202
|
+
|
|
203
|
+
**Full schema:**
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"cloud": {
|
|
208
|
+
"apiKey": "$TESTRELIC_API_KEY",
|
|
209
|
+
"endpoint": "https://platform.testrelic.ai/api/v1",
|
|
210
|
+
"upload": "both",
|
|
211
|
+
"timeout": 30000
|
|
212
|
+
},
|
|
213
|
+
"testrelic-repo": {
|
|
214
|
+
"name": "my-project"
|
|
215
|
+
},
|
|
216
|
+
"queue": {
|
|
217
|
+
"maxAge": "7d",
|
|
218
|
+
"directory": ".testrelic/queue"
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
| Key | Description |
|
|
224
|
+
|---|---|
|
|
225
|
+
| `cloud.apiKey` | API key for authentication. Use `"$TESTRELIC_API_KEY"` to read from the environment variable. |
|
|
226
|
+
| `cloud.endpoint` | Cloud API endpoint. Defaults to `https://platform.testrelic.ai/api/v1`. |
|
|
227
|
+
| `cloud.upload` | Upload strategy — see [Upload Strategy](#upload-strategy) below. |
|
|
228
|
+
| `cloud.timeout` | Request timeout in milliseconds (default: `30000`). |
|
|
229
|
+
| `testrelic-repo.name` | Repository/project name shown in the cloud dashboard. |
|
|
230
|
+
| `queue.maxAge` | How long to retain queued failed uploads before discarding (default: `"7d"`). |
|
|
231
|
+
| `queue.directory` | Directory for queued uploads (default: `.testrelic/queue`). |
|
|
232
|
+
|
|
233
|
+
### Upload Strategy
|
|
234
|
+
|
|
235
|
+
The `upload` field controls how test data is sent to the cloud:
|
|
236
|
+
|
|
237
|
+
| Value | Behaviour |
|
|
238
|
+
|---|---|
|
|
239
|
+
| `"realtime"` | Streams test events to the cloud as they happen. Fast feedback but skips the batch payload. |
|
|
240
|
+
| `"batch"` | Sends a single complete JSON payload after all tests finish. Includes full step data. |
|
|
241
|
+
| `"both"` | **Recommended.** Streams realtime events AND sends the complete batch payload at the end. Required for the Steps tab in the cloud dashboard to be populated. |
|
|
242
|
+
|
|
243
|
+
> **Important:** Using `upload: "realtime"` alone skips the batch payload that the cloud platform uses to populate the Steps, navigation timeline, and network stats views. Use `"both"` to ensure all data appears in the dashboard.
|
|
244
|
+
|
|
245
|
+
### Environment Variables
|
|
246
|
+
|
|
247
|
+
Environment variables take the highest priority and override both reporter options and the config file:
|
|
248
|
+
|
|
249
|
+
| Variable | Description |
|
|
250
|
+
|---|---|
|
|
251
|
+
| `TESTRELIC_API_KEY` | API key — always set this in CI secrets rather than hardcoding it. |
|
|
252
|
+
| `TESTRELIC_CLOUD_ENDPOINT` | Override the API endpoint (e.g. for a self-hosted or stage deployment). |
|
|
253
|
+
| `TESTRELIC_UPLOAD_STRATEGY` | Override the upload strategy (`realtime`, `batch`, or `both`). |
|
|
254
|
+
| `TESTRELIC_CLOUD_TIMEOUT` | Override the request timeout in milliseconds. |
|
|
255
|
+
|
|
256
|
+
**Priority order (highest wins):**
|
|
257
|
+
1. Environment variables
|
|
258
|
+
2. Reporter `cloud:` options in `playwright.config.ts`
|
|
259
|
+
3. `.testrelic/testrelic-config.json`
|
|
260
|
+
4. Built-in defaults
|
|
261
|
+
|
|
262
|
+
### .gitignore Guidance
|
|
263
|
+
|
|
264
|
+
The `.testrelic/` directory serves multiple purposes. Only the config file should be committed:
|
|
265
|
+
|
|
266
|
+
```gitignore
|
|
267
|
+
# Commit: .testrelic/testrelic-config.json
|
|
268
|
+
# Ignore runtime directories:
|
|
269
|
+
.testrelic/queue/
|
|
270
|
+
.testrelic/cache/
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Migrating from Previous Versions
|
|
274
|
+
|
|
275
|
+
**Config file location (v2.3.x → v2.4.0)**
|
|
276
|
+
|
|
277
|
+
The config file has moved from a flat `.testrelic` file to `.testrelic/testrelic-config.json`. This prevents a filesystem conflict where the SDK needed to create a `.testrelic/` directory (for queue and cache) while the config file occupied the same path.
|
|
278
|
+
|
|
279
|
+
If you have an existing `.testrelic` flat file, it still works — the SDK reads it with a deprecation warning:
|
|
280
|
+
|
|
281
|
+
```
|
|
282
|
+
[testrelic] Deprecation: config file ".testrelic" has moved to ".testrelic/testrelic-config.json".
|
|
283
|
+
Please migrate your config file to the new location.
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
To migrate, rename the file and move it into the directory:
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
mkdir -p .testrelic
|
|
290
|
+
mv .testrelic .testrelic/testrelic-config.json # on Unix/macOS
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
**`project` key renamed to `testrelic-repo` (v2.3.x → v2.4.0)**
|
|
294
|
+
|
|
295
|
+
The `project` config key has been renamed to `testrelic-repo` for clarity. The old key still works with a deprecation warning:
|
|
296
|
+
|
|
297
|
+
```
|
|
298
|
+
[testrelic] Deprecation: "project" key in config is deprecated. Rename it to "testrelic-repo".
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Update your config file:
|
|
302
|
+
|
|
303
|
+
```json
|
|
304
|
+
// Before
|
|
305
|
+
{ "project": { "name": "my-project" } }
|
|
306
|
+
|
|
307
|
+
// After
|
|
308
|
+
{ "testrelic-repo": { "name": "my-project" } }
|
|
309
|
+
```
|
|
310
|
+
|
|
128
311
|
## Output Example
|
|
129
312
|
|
|
130
313
|
```jsonc
|
|
@@ -220,6 +403,21 @@ All options are passed as the second element of the reporter tuple:
|
|
|
220
403
|
| `apiIncludeUrls` | `(string \| RegExp)[]` | `[]` (all URLs) | Only track API calls matching these patterns |
|
|
221
404
|
| `apiExcludeUrls` | `(string \| RegExp)[]` | `[]` (none excluded) | Exclude API calls matching these patterns |
|
|
222
405
|
|
|
406
|
+
### Cloud Upload Options
|
|
407
|
+
|
|
408
|
+
Passed inside the `cloud:` key of the reporter options. These are merged with (and take priority over) the `.testrelic/testrelic-config.json` values.
|
|
409
|
+
|
|
410
|
+
| Option | Type | Default | Description |
|
|
411
|
+
|---|---|---|---|
|
|
412
|
+
| `cloud.apiKey` | `string` | — | API key for cloud authentication. Prefer `process.env.TESTRELIC_API_KEY`. |
|
|
413
|
+
| `cloud.endpoint` | `string` | `https://platform.testrelic.ai/api/v1` | Cloud API endpoint. |
|
|
414
|
+
| `cloud.upload` | `'realtime' \| 'batch' \| 'both'` | `'batch'` | Upload strategy. Use `'both'` to populate all cloud dashboard views including Steps. |
|
|
415
|
+
| `cloud.timeout` | `number` | `30000` | Request timeout in milliseconds. |
|
|
416
|
+
| `cloud.uploadArtifacts` | `boolean` | `true` | Upload screenshots and videos to cloud storage. |
|
|
417
|
+
| `cloud.artifactMaxSizeMb` | `number` | `50` | Maximum size per artifact file in MB. Files exceeding this are skipped. |
|
|
418
|
+
| `cloud.queueDirectory` | `string` | `.testrelic/queue` | Directory for queued uploads that failed and will be retried. |
|
|
419
|
+
| `cloud.queueMaxAge` | `string` | `'7d'` | Maximum age for queued items before they are discarded (e.g. `'7d'`, `'24h'`). |
|
|
420
|
+
|
|
223
421
|
### Configuration Examples
|
|
224
422
|
|
|
225
423
|
**Default (zero config)** — captures everything with built-in redaction:
|