testdriverai 7.2.26 → 7.2.27
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/.github/workflows/test-with-comments.yml +73 -0
- package/docs/GITHUB_COMMENTS.md +330 -0
- package/docs/GITHUB_COMMENTS_ANNOUNCEMENT.md +167 -0
- package/docs/QUICK-START-GITHUB-COMMENTS.md +84 -0
- package/docs/TEST-GITHUB-COMMENTS.md +129 -0
- package/docs/github-integration-setup.md +266 -0
- package/examples/github-actions.yml +68 -0
- package/examples/github-comment-demo.test.mjs +42 -0
- package/interfaces/vitest-plugin.mjs +100 -0
- package/lib/github-comment-formatter.js +263 -0
- package/lib/github-comment.mjs +424 -0
- package/lib/vitest/hooks.mjs +15 -0
- package/package.json +2 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
name: TestDriver Tests with GitHub Comments
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [opened, synchronize, reopened]
|
|
6
|
+
push:
|
|
7
|
+
branches: [main]
|
|
8
|
+
workflow_dispatch: # Allows manual trigger from Actions tab
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
test:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
pull-requests: write # Required to post comments on PRs
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout code
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Setup Node.js
|
|
23
|
+
uses: actions/setup-node@v4
|
|
24
|
+
with:
|
|
25
|
+
node-version: '20'
|
|
26
|
+
cache: 'npm'
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: npm ci
|
|
30
|
+
|
|
31
|
+
- name: Run assert test with GitHub comments
|
|
32
|
+
env:
|
|
33
|
+
# TestDriver API key (from repository secrets)
|
|
34
|
+
TD_API_KEY: ${{ secrets.TD_API_KEY }}
|
|
35
|
+
|
|
36
|
+
# GitHub token for posting comments (auto-provided)
|
|
37
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
38
|
+
|
|
39
|
+
# PR number for PR comments (auto-extracted for pull_request events)
|
|
40
|
+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
41
|
+
|
|
42
|
+
# Git information (automatically provided by GitHub Actions)
|
|
43
|
+
# GITHUB_SHA, GITHUB_REF, GITHUB_REPOSITORY are already set
|
|
44
|
+
|
|
45
|
+
run: |
|
|
46
|
+
echo "🚀 Running TestDriver assert test..."
|
|
47
|
+
echo "📍 Repository: $GITHUB_REPOSITORY"
|
|
48
|
+
echo "🔢 PR Number: ${{ github.event.pull_request.number || 'N/A (not a PR)' }}"
|
|
49
|
+
echo "📦 Running test..."
|
|
50
|
+
npm run test:sdk -- test/testdriver/assert.test.mjs
|
|
51
|
+
|
|
52
|
+
- name: Upload test results (on failure)
|
|
53
|
+
if: failure()
|
|
54
|
+
uses: actions/upload-artifact@v4
|
|
55
|
+
with:
|
|
56
|
+
name: test-results
|
|
57
|
+
path: |
|
|
58
|
+
test-report.junit.xml
|
|
59
|
+
.testdriver/
|
|
60
|
+
retention-days: 7
|
|
61
|
+
|
|
62
|
+
- name: Comment on PR (manual fallback if auto-comment fails)
|
|
63
|
+
if: failure() && github.event_name == 'pull_request'
|
|
64
|
+
uses: actions/github-script@v7
|
|
65
|
+
with:
|
|
66
|
+
script: |
|
|
67
|
+
const testRunUrl = process.env.TESTDRIVER_RUN_URL || 'Check workflow logs';
|
|
68
|
+
github.rest.issues.createComment({
|
|
69
|
+
issue_number: context.issue.number,
|
|
70
|
+
owner: context.repo.owner,
|
|
71
|
+
repo: context.repo.repo,
|
|
72
|
+
body: `⚠️ TestDriver tests encountered an error. ${testRunUrl}`
|
|
73
|
+
})
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
# GitHub Comment Integration
|
|
2
|
+
|
|
3
|
+
TestDriver can automatically post beautiful, formatted comments to your GitHub pull requests and commits with test results, including dashcam replays, exceptions, and detailed statistics.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 📊 **Test Results Summary** - Pass/fail statistics and duration
|
|
8
|
+
- 🎥 **Dashcam GIF Replays** - Embedded GIF previews with links to full replays
|
|
9
|
+
- ❌ **Exception Details** - Error messages and stack traces for failed tests
|
|
10
|
+
- 📋 **Detailed Test Table** - Status, file, duration, and replay link for each test
|
|
11
|
+
- 🔄 **Auto-update** - Updates existing comment instead of creating duplicates
|
|
12
|
+
- 🎨 **Beautiful Formatting** - Professional markdown with emojis and badges
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
|
|
16
|
+
### 1. Enable in CI Environment
|
|
17
|
+
|
|
18
|
+
Set the required environment variables in your CI workflow:
|
|
19
|
+
|
|
20
|
+
#### GitHub Actions
|
|
21
|
+
|
|
22
|
+
```yaml
|
|
23
|
+
name: TestDriver Tests
|
|
24
|
+
|
|
25
|
+
on:
|
|
26
|
+
pull_request:
|
|
27
|
+
push:
|
|
28
|
+
branches: [main]
|
|
29
|
+
|
|
30
|
+
jobs:
|
|
31
|
+
test:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v3
|
|
35
|
+
|
|
36
|
+
- name: Setup Node.js
|
|
37
|
+
uses: actions/setup-node@v3
|
|
38
|
+
with:
|
|
39
|
+
node-version: '20'
|
|
40
|
+
|
|
41
|
+
- name: Install dependencies
|
|
42
|
+
run: npm install
|
|
43
|
+
|
|
44
|
+
- name: Run TestDriver tests
|
|
45
|
+
env:
|
|
46
|
+
TD_API_KEY: ${{ secrets.TD_API_KEY }}
|
|
47
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
48
|
+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
49
|
+
run: npm run test:sdk
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Important:** For pull request events, `GITHUB_PR_NUMBER` must be explicitly set from `github.event.pull_request.number`.
|
|
53
|
+
|
|
54
|
+
### 2. Environment Variables
|
|
55
|
+
|
|
56
|
+
| Variable | Description | Required | Example |
|
|
57
|
+
|----------|-------------|----------|---------|
|
|
58
|
+
| `TD_API_KEY` | TestDriver API key | ✅ Yes | Get from [console.testdriver.ai](https://console.testdriver.ai/team) |
|
|
59
|
+
| `GITHUB_TOKEN` | GitHub token with PR write permissions | ✅ Yes | Automatically available in GitHub Actions |
|
|
60
|
+
| `GITHUB_PR_NUMBER` | Pull request number | For PR comments | `123` |
|
|
61
|
+
| `GITHUB_SHA` | Commit SHA | For commit comments | Automatically set in GitHub Actions |
|
|
62
|
+
|
|
63
|
+
**Token Alternatives:**
|
|
64
|
+
- `GITHUB_TOKEN` (preferred)
|
|
65
|
+
- `GH_TOKEN` (alternative)
|
|
66
|
+
|
|
67
|
+
### 3. Comment Destinations
|
|
68
|
+
|
|
69
|
+
TestDriver will post comments based on available context:
|
|
70
|
+
|
|
71
|
+
- **Pull Request Comment** - If `GITHUB_PR_NUMBER` is set (recommended)
|
|
72
|
+
- **Commit Comment** - If only `GITHUB_SHA` is available (fallback)
|
|
73
|
+
|
|
74
|
+
## Example Comment
|
|
75
|
+
|
|
76
|
+
Here's what a TestDriver GitHub comment looks like:
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
# 🟢 TestDriver Test Results
|
|
81
|
+
|
|
82
|
+
**Status:** ✅ PASSED
|
|
83
|
+
**Duration:** 2m 34s
|
|
84
|
+
**Platform:** linux
|
|
85
|
+
**Branch:** `feature/new-test`
|
|
86
|
+
**Commit:** `a1b2c3d`
|
|
87
|
+
|
|
88
|
+
## 📊 Test Summary
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
Total: 5
|
|
92
|
+
Passed: 4 ✅
|
|
93
|
+
Failed: 1 ❌
|
|
94
|
+
Skipped: 0 ⏭️
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### [📋 View Full Test Run](https://console.testdriver.ai/runs/123)
|
|
98
|
+
|
|
99
|
+
## 📝 Test Results
|
|
100
|
+
|
|
101
|
+
| Status | Test | File | Duration | Replay |
|
|
102
|
+
|--------|------|------|----------|--------|
|
|
103
|
+
| ✅ | should login successfully | `tests/auth.test.mjs` | 12.5s | [🎥 View](https://console.testdriver.ai/replay/abc123) |
|
|
104
|
+
| ✅ | should add item to cart | `tests/cart.test.mjs` | 8.2s | [🎥 View](https://console.testdriver.ai/replay/def456) |
|
|
105
|
+
| ❌ | should complete checkout | `tests/checkout.test.mjs` | 15.3s | [🎥 View](https://console.testdriver.ai/replay/ghi789) |
|
|
106
|
+
|
|
107
|
+
## 🎥 Dashcam Replays
|
|
108
|
+
|
|
109
|
+
### should login successfully
|
|
110
|
+
|
|
111
|
+
[](https://console.testdriver.ai/replay/abc123)
|
|
112
|
+
|
|
113
|
+
[🎬 View Full Replay](https://console.testdriver.ai/replay/abc123)
|
|
114
|
+
|
|
115
|
+
## 🔴 Failures
|
|
116
|
+
|
|
117
|
+
### should complete checkout
|
|
118
|
+
|
|
119
|
+
**File:** `tests/checkout.test.mjs`
|
|
120
|
+
|
|
121
|
+
**📹 [Watch Replay](https://console.testdriver.ai/replay/ghi789)**
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
AssertionError: expected false to be truthy
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
<details>
|
|
128
|
+
<summary>Stack Trace</summary>
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
AssertionError: expected false to be truthy
|
|
132
|
+
at /workspace/tests/checkout.test.mjs:45:7
|
|
133
|
+
...
|
|
134
|
+
```
|
|
135
|
+
</details>
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
<sub>Generated by [TestDriver](https://testdriver.ai) • Run ID: `1234567890-abc123`</sub>
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Configuration
|
|
143
|
+
|
|
144
|
+
### Customizing Comment Behavior
|
|
145
|
+
|
|
146
|
+
You can control GitHub comment posting with environment variables:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Disable GitHub comments entirely
|
|
150
|
+
TESTDRIVER_SKIP_GITHUB_COMMENT=true npm run test
|
|
151
|
+
|
|
152
|
+
# Use custom GitHub token
|
|
153
|
+
GH_TOKEN=ghp_yourtoken npm run test
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### GitLab / Other CI Systems
|
|
157
|
+
|
|
158
|
+
While the integration is optimized for GitHub, you can use the comment generator programmatically:
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
import { generateGitHubComment } from 'testdriverai/lib/github-comment.mjs';
|
|
162
|
+
|
|
163
|
+
const testRunData = {
|
|
164
|
+
runId: '1234567890-abc',
|
|
165
|
+
status: 'passed',
|
|
166
|
+
totalTests: 5,
|
|
167
|
+
passedTests: 4,
|
|
168
|
+
failedTests: 1,
|
|
169
|
+
skippedTests: 0,
|
|
170
|
+
duration: 154000,
|
|
171
|
+
testRunUrl: 'https://console.testdriver.ai/runs/123',
|
|
172
|
+
platform: 'linux',
|
|
173
|
+
branch: 'main',
|
|
174
|
+
commit: 'a1b2c3d',
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const testCases = [
|
|
178
|
+
{
|
|
179
|
+
testName: 'should work',
|
|
180
|
+
testFile: 'test.test.mjs',
|
|
181
|
+
status: 'passed',
|
|
182
|
+
duration: 5000,
|
|
183
|
+
replayUrl: 'https://console.testdriver.ai/replay/abc',
|
|
184
|
+
},
|
|
185
|
+
// ... more tests
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
const markdown = generateGitHubComment(testRunData, testCases);
|
|
189
|
+
console.log(markdown);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Troubleshooting
|
|
193
|
+
|
|
194
|
+
### Comment not posting
|
|
195
|
+
|
|
196
|
+
1. **Check environment variables:**
|
|
197
|
+
```bash
|
|
198
|
+
echo $GITHUB_TOKEN
|
|
199
|
+
echo $GITHUB_PR_NUMBER
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
2. **Check CI logs:**
|
|
203
|
+
Look for log messages:
|
|
204
|
+
- `"GitHub token not found, skipping comment posting"`
|
|
205
|
+
- `"Repository info not available"`
|
|
206
|
+
- `"Posted GitHub comment"`
|
|
207
|
+
|
|
208
|
+
3. **Verify token permissions:**
|
|
209
|
+
- GitHub Actions: `GITHUB_TOKEN` should have `write` permissions for `pull-requests` or `contents`
|
|
210
|
+
- Personal tokens: Needs `repo` scope
|
|
211
|
+
|
|
212
|
+
### Comment not updating
|
|
213
|
+
|
|
214
|
+
If you see duplicate comments instead of updates:
|
|
215
|
+
- Ensure the bot/user posting comments is consistent across runs
|
|
216
|
+
- The update mechanism looks for existing comments with "Generated by [TestDriver]" signature
|
|
217
|
+
|
|
218
|
+
### Replays not showing
|
|
219
|
+
|
|
220
|
+
If dashcam replays aren't included:
|
|
221
|
+
- Verify dashcam is starting correctly (check for `🎥 Dashcam URL:` in logs)
|
|
222
|
+
- Ensure tests are calling `await testdriver.provision.*()` which auto-starts dashcam
|
|
223
|
+
- Check that dashcam stops successfully (look for replay URLs in output)
|
|
224
|
+
|
|
225
|
+
### GIF embeds not loading
|
|
226
|
+
|
|
227
|
+
The GIF embeds are generated dynamically by the TestDriver API:
|
|
228
|
+
- URL format: `https://console.testdriver.ai/api/replay/{replayId}/gif`
|
|
229
|
+
- If GIFs don't load, the API endpoint may be unavailable
|
|
230
|
+
- Fallback: Users can still click the "View Full Replay" link
|
|
231
|
+
|
|
232
|
+
## API Reference
|
|
233
|
+
|
|
234
|
+
### `generateGitHubComment(testRunData, testCases)`
|
|
235
|
+
|
|
236
|
+
Generates markdown for a GitHub comment.
|
|
237
|
+
|
|
238
|
+
**Parameters:**
|
|
239
|
+
- `testRunData` (Object): Test run summary data
|
|
240
|
+
- `runId` (string): Unique test run ID
|
|
241
|
+
- `status` (string): Overall status ('passed', 'failed', 'cancelled')
|
|
242
|
+
- `totalTests` (number): Total number of tests
|
|
243
|
+
- `passedTests` (number): Number of passed tests
|
|
244
|
+
- `failedTests` (number): Number of failed tests
|
|
245
|
+
- `skippedTests` (number): Number of skipped tests
|
|
246
|
+
- `duration` (number): Total duration in milliseconds
|
|
247
|
+
- `testRunUrl` (string): URL to full test run
|
|
248
|
+
- `platform` (string): Test platform ('linux', 'windows', 'mac')
|
|
249
|
+
- `branch` (string): Git branch name
|
|
250
|
+
- `commit` (string): Git commit SHA
|
|
251
|
+
- `testCases` (Array): Array of test case objects
|
|
252
|
+
- `testName` (string): Test name
|
|
253
|
+
- `testFile` (string): Test file path
|
|
254
|
+
- `status` (string): Test status
|
|
255
|
+
- `duration` (number): Test duration in ms
|
|
256
|
+
- `replayUrl` (string): Dashcam replay URL (optional)
|
|
257
|
+
- `errorMessage` (string): Error message if failed (optional)
|
|
258
|
+
- `errorStack` (string): Stack trace if failed (optional)
|
|
259
|
+
|
|
260
|
+
**Returns:** String (markdown)
|
|
261
|
+
|
|
262
|
+
### `postOrUpdateTestResults(testRunData, testCases, githubOptions)`
|
|
263
|
+
|
|
264
|
+
Posts or updates a GitHub comment with test results.
|
|
265
|
+
|
|
266
|
+
**Parameters:**
|
|
267
|
+
- `testRunData` (Object): Same as `generateGitHubComment`
|
|
268
|
+
- `testCases` (Array): Same as `generateGitHubComment`
|
|
269
|
+
- `githubOptions` (Object): GitHub API configuration
|
|
270
|
+
- `token` (string): GitHub token
|
|
271
|
+
- `owner` (string): Repository owner
|
|
272
|
+
- `repo` (string): Repository name
|
|
273
|
+
- `prNumber` (number): PR number (optional)
|
|
274
|
+
- `commitSha` (string): Commit SHA (optional)
|
|
275
|
+
|
|
276
|
+
**Returns:** Promise<Object> - GitHub API response
|
|
277
|
+
|
|
278
|
+
## Examples
|
|
279
|
+
|
|
280
|
+
### Manual Comment Posting
|
|
281
|
+
|
|
282
|
+
```javascript
|
|
283
|
+
import { postOrUpdateTestResults } from 'testdriverai/lib/github-comment.mjs';
|
|
284
|
+
|
|
285
|
+
await postOrUpdateTestResults(
|
|
286
|
+
{
|
|
287
|
+
runId: '123',
|
|
288
|
+
status: 'passed',
|
|
289
|
+
totalTests: 10,
|
|
290
|
+
passedTests: 10,
|
|
291
|
+
failedTests: 0,
|
|
292
|
+
skippedTests: 0,
|
|
293
|
+
duration: 60000,
|
|
294
|
+
testRunUrl: 'https://console.testdriver.ai/runs/123',
|
|
295
|
+
platform: 'linux',
|
|
296
|
+
branch: 'main',
|
|
297
|
+
commit: 'abc123',
|
|
298
|
+
},
|
|
299
|
+
testCases,
|
|
300
|
+
{
|
|
301
|
+
token: process.env.GITHUB_TOKEN,
|
|
302
|
+
owner: 'myorg',
|
|
303
|
+
repo: 'myrepo',
|
|
304
|
+
prNumber: 456,
|
|
305
|
+
}
|
|
306
|
+
);
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Custom Formatting
|
|
310
|
+
|
|
311
|
+
```javascript
|
|
312
|
+
import { generateGitHubComment } from 'testdriverai/lib/github-comment.mjs';
|
|
313
|
+
|
|
314
|
+
const markdown = generateGitHubComment(testRunData, testCases);
|
|
315
|
+
|
|
316
|
+
// Customize markdown
|
|
317
|
+
const customMarkdown = markdown.replace(
|
|
318
|
+
'# 🟢 TestDriver Test Results',
|
|
319
|
+
'# 🟢 My Custom Test Report'
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
// Post using GitHub API directly
|
|
323
|
+
// ... your posting logic
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Support
|
|
327
|
+
|
|
328
|
+
- **Documentation:** [testdriver.ai/docs](https://testdriver.ai/docs)
|
|
329
|
+
- **Issues:** [github.com/testdriverai/testdriverai/issues](https://github.com/testdriverai/testdriverai/issues)
|
|
330
|
+
- **Discord:** Join our [community Discord](https://discord.gg/testdriver)
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# 🎉 GitHub Comments Feature
|
|
2
|
+
|
|
3
|
+
## What's New
|
|
4
|
+
|
|
5
|
+
TestDriver now automatically posts beautiful, detailed comments to your GitHub pull requests and commits with:
|
|
6
|
+
|
|
7
|
+
- ✅ **Test Results** - Pass/fail statistics at a glance
|
|
8
|
+
- 🎥 **Dashcam GIF Replays** - Embedded animated previews of each test
|
|
9
|
+
- 📊 **Detailed Statistics** - Duration, platform, branch, commit info
|
|
10
|
+
- ❌ **Exception Details** - Full error messages and stack traces for failures
|
|
11
|
+
- 🔄 **Smart Updates** - Updates existing comments instead of creating duplicates
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
### 1. Add to GitHub Actions
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
- name: Run TestDriver tests
|
|
19
|
+
env:
|
|
20
|
+
TD_API_KEY: ${{ secrets.TD_API_KEY }}
|
|
21
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
22
|
+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
23
|
+
run: npm run test:sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. That's it!
|
|
27
|
+
|
|
28
|
+
TestDriver will automatically detect the CI environment and post comments when:
|
|
29
|
+
- `GITHUB_TOKEN` is present
|
|
30
|
+
- `GITHUB_PR_NUMBER` (for PR comments) or `GITHUB_SHA` (for commit comments) is set
|
|
31
|
+
|
|
32
|
+
## Example Comment
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
Your team will see:
|
|
37
|
+
- **Status badges** with pass/fail counts
|
|
38
|
+
- **Embedded GIF replays** directly in the comment
|
|
39
|
+
- **Clickable links** to full test runs and individual replays
|
|
40
|
+
- **Collapsible error details** with full stack traces
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
### 🎥 Dashcam Replays
|
|
45
|
+
|
|
46
|
+
Every test automatically records a dashcam replay. These appear in the GitHub comment as:
|
|
47
|
+
1. **GIF preview** - Shows the test execution as an animated image
|
|
48
|
+
2. **Link to full replay** - Opens the complete replay in TestDriver console
|
|
49
|
+
3. **Test-specific context** - Each test has its own replay section
|
|
50
|
+
|
|
51
|
+
### 📊 Test Statistics
|
|
52
|
+
|
|
53
|
+
The comment shows:
|
|
54
|
+
- Total test count
|
|
55
|
+
- Pass/fail/skip breakdown
|
|
56
|
+
- Total execution time
|
|
57
|
+
- Platform (Linux/Windows/Mac)
|
|
58
|
+
- Git branch and commit
|
|
59
|
+
|
|
60
|
+
### ❌ Exception Handling
|
|
61
|
+
|
|
62
|
+
Failed tests include:
|
|
63
|
+
- Error message prominently displayed
|
|
64
|
+
- Collapsible stack trace
|
|
65
|
+
- Direct link to the failing test's replay
|
|
66
|
+
- File and line number information
|
|
67
|
+
|
|
68
|
+
### 🔄 Comment Updates
|
|
69
|
+
|
|
70
|
+
TestDriver intelligently:
|
|
71
|
+
- **Updates existing comments** on subsequent pushes to the same PR
|
|
72
|
+
- **Creates new comments** only when needed
|
|
73
|
+
- **Identifies its own comments** using a signature
|
|
74
|
+
|
|
75
|
+
## Configuration
|
|
76
|
+
|
|
77
|
+
### Environment Variables
|
|
78
|
+
|
|
79
|
+
| Variable | Description | Required |
|
|
80
|
+
|----------|-------------|----------|
|
|
81
|
+
| `TD_API_KEY` | TestDriver API key | ✅ Yes |
|
|
82
|
+
| `GITHUB_TOKEN` | GitHub token | ✅ Yes |
|
|
83
|
+
| `GITHUB_PR_NUMBER` | PR number for PR comments | 📝 Recommended |
|
|
84
|
+
| `GITHUB_SHA` | Commit SHA (fallback) | ⚙️ Auto-detected |
|
|
85
|
+
| `TESTDRIVER_SKIP_GITHUB_COMMENT` | Set to 'true' to disable | ❌ No |
|
|
86
|
+
|
|
87
|
+
### Disabling Comments
|
|
88
|
+
|
|
89
|
+
To disable GitHub comments for a specific run:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
TESTDRIVER_SKIP_GITHUB_COMMENT=true npm run test
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Documentation
|
|
96
|
+
|
|
97
|
+
For complete documentation, see:
|
|
98
|
+
- **[GitHub Comments Guide](./GITHUB_COMMENTS.md)** - Full setup and configuration
|
|
99
|
+
- **[Example Workflow](./../examples/github-actions.yml)** - Copy-paste GitHub Actions workflow
|
|
100
|
+
- **[Example Test](./../examples/github-comment-demo.test.mjs)** - Demo test file
|
|
101
|
+
|
|
102
|
+
## Troubleshooting
|
|
103
|
+
|
|
104
|
+
### Comment not appearing?
|
|
105
|
+
|
|
106
|
+
1. **Check environment variables:**
|
|
107
|
+
```bash
|
|
108
|
+
echo "Token: ${GITHUB_TOKEN:0:10}..."
|
|
109
|
+
echo "PR: $GITHUB_PR_NUMBER"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
2. **Verify permissions:**
|
|
113
|
+
- GitHub Actions needs `pull-requests: write` or `contents: write`
|
|
114
|
+
|
|
115
|
+
3. **Check logs:**
|
|
116
|
+
- Look for "Posting GitHub comment..." in test output
|
|
117
|
+
- Check for "GitHub token not found" warnings
|
|
118
|
+
|
|
119
|
+
### Replays not embedded?
|
|
120
|
+
|
|
121
|
+
- Ensure tests are using `await testdriver.provision.*()`
|
|
122
|
+
- Check that dashcam stops successfully (look for "🎥 Dashcam URL")
|
|
123
|
+
- Verify replay URLs in test output
|
|
124
|
+
|
|
125
|
+
## Examples
|
|
126
|
+
|
|
127
|
+
### Basic Test with Comment
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
it("should login successfully", async (context) => {
|
|
131
|
+
const testdriver = TestDriver(context, { headless: true });
|
|
132
|
+
|
|
133
|
+
await testdriver.provision.chrome({
|
|
134
|
+
url: 'https://your-app.com/login',
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Test steps...
|
|
138
|
+
const result = await testdriver.assert("I'm logged in");
|
|
139
|
+
expect(result).toBeTruthy();
|
|
140
|
+
|
|
141
|
+
// Dashcam automatically recorded and will appear in GitHub comment!
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Local Testing
|
|
146
|
+
|
|
147
|
+
Run locally without posting comments:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
npm run test:sdk
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Run locally WITH comment posting (requires token):
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
GITHUB_TOKEN=ghp_xxx GITHUB_PR_NUMBER=123 npm run test:sdk
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Support
|
|
160
|
+
|
|
161
|
+
- **Documentation:** [testdriver.ai/docs](https://testdriver.ai/docs)
|
|
162
|
+
- **Issues:** [GitHub Issues](https://github.com/testdriverai/testdriverai/issues)
|
|
163
|
+
- **Discord:** [Join our community](https://discord.gg/testdriver)
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
Made with ❤️ by the TestDriver team
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Quick Start: GitHub Comments
|
|
2
|
+
|
|
3
|
+
## For GitHub Actions (Easiest!)
|
|
4
|
+
|
|
5
|
+
Add this to your `.github/workflows/test.yml`:
|
|
6
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
name: Tests
|
|
9
|
+
|
|
10
|
+
on: pull_request
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
pull-requests: write # ← This is all you need!
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Setup Node
|
|
23
|
+
uses: actions/setup-node@v4
|
|
24
|
+
with:
|
|
25
|
+
node-version: '20'
|
|
26
|
+
|
|
27
|
+
- run: npm ci
|
|
28
|
+
|
|
29
|
+
- name: Run TestDriver tests
|
|
30
|
+
env:
|
|
31
|
+
TD_API_KEY: ${{ secrets.TD_API_KEY }}
|
|
32
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Auto-provided
|
|
33
|
+
run: npm test
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
That's it! TestDriver will automatically:
|
|
37
|
+
- ✅ Detect the PR number
|
|
38
|
+
- ✅ Detect the repository
|
|
39
|
+
- ✅ Post beautiful comments with test results
|
|
40
|
+
- 🎥 Embed dashcam GIF replays
|
|
41
|
+
- 📊 Show pass/fail statistics
|
|
42
|
+
- 🔴 Display exception details
|
|
43
|
+
|
|
44
|
+
## For Local Development
|
|
45
|
+
|
|
46
|
+
1. **Create a GitHub Personal Access Token**
|
|
47
|
+
- Go to https://github.com/settings/tokens
|
|
48
|
+
- Click "Generate new token (classic)"
|
|
49
|
+
- Select scope: `repo` or `public_repo`
|
|
50
|
+
- Copy the token
|
|
51
|
+
|
|
52
|
+
2. **Set environment variables**
|
|
53
|
+
```bash
|
|
54
|
+
export GITHUB_TOKEN=ghp_your_token_here
|
|
55
|
+
export GITHUB_PR_NUMBER=123
|
|
56
|
+
npm test
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## What Gets Posted
|
|
60
|
+
|
|
61
|
+
```markdown
|
|
62
|
+
# 🟢 TestDriver Test Results
|
|
63
|
+
|
|
64
|
+
**Status:** ✅ PASSED
|
|
65
|
+
**Duration:** 12.3s
|
|
66
|
+
|
|
67
|
+
## 📝 Test Results
|
|
68
|
+
| Status | Test | Duration | Replay |
|
|
69
|
+
|--------|------|----------|--------|
|
|
70
|
+
| ✅ | Login test | 4.5s | [🎥 View](link) |
|
|
71
|
+
|
|
72
|
+
## 🎥 Dashcam Replays
|
|
73
|
+
[Animated GIF embedded here]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Disable Comments
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
TESTDRIVER_SKIP_GITHUB_COMMENT=true npm test
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Full Documentation
|
|
83
|
+
|
|
84
|
+
See [github-integration-setup.md](./github-integration-setup.md) for complete details.
|