Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
57c0103
feat: add SnapshotAgent for HTTP request recording and playback
mcollina Jun 8, 2025
a90fe15
Merge branch 'main' into feature/snapshot-testing
mcollina Jul 19, 2025
8084eac
feat: implement Phase 1 of SnapshotAgent enhancements
mcollina Jul 19, 2025
4401261
docs: update PLAN.md to reflect Phase 1 completion
mcollina Jul 19, 2025
65e53a1
feat: implement Phase 2 - Enhanced Request Matching
mcollina Jul 19, 2025
0e8046e
feat: implement Phase 3 - Advanced Playback Features for SnapshotAgent
mcollina Jul 19, 2025
0a50c9b
docs: update PLAN.md to reflect completion of all primary objectives
mcollina Jul 19, 2025
f379bab
feat: update TypeScript definitions and add comprehensive tsd tests
mcollina Jul 19, 2025
0372422
Merge remote-tracking branch 'origin/main' into feature/snapshot-testing
mcollina Jul 20, 2025
ffaaa48
feat: implement Phase 4 optional enhancements for SnapshotAgent
mcollina Jul 20, 2025
ac43299
fix: resolve flaky sequential response test
mcollina Jul 20, 2025
d40eaf0
chore: remove PLAN.md file
mcollina Jul 20, 2025
83c4f7e
removed PR_DESCRIPTION.md
mcollina Jul 24, 2025
4c1d77c
docs: update snapshot agent documentation and implementation
mcollina Jul 28, 2025
559d936
fixup
mcollina Jul 29, 2025
01fdcc0
test: add redirect interceptor integration test and fix race condition
mcollina Jul 29, 2025
fe03c68
fix: make SnapshotAgent work properly with redirect interceptor
mcollina Jul 29, 2025
d7d9024
fix: complete SnapshotAgent redirect interceptor integration
mcollina Jul 29, 2025
27e1c49
fixup
mcollina Jul 29, 2025
2664559
fixup
mcollina Jul 29, 2025
a9d7cb7
fix: clean up console.logs and improve SnapshotAgent experimental war…
mcollina Jul 29, 2025
c968233
test: add test case for SnapshotAgent with pre-existing array responses
mcollina Jul 29, 2025
5db08e8
docs: simplify snapshot testing example to single working demo
mcollina Jul 29, 2025
14a70bb
remove spurious console.error
mcollina Jul 30, 2025
f61bb5a
clean: remove phase mentions and fix t.after() placement
mcollina Jul 30, 2025
3b460af
refactor: convert snapshot tests to use describe blocks and top-level…
mcollina Jul 30, 2025
4edfca0
fix: ensure agent.close() method is always awaited in tests
mcollina Jul 31, 2025
4cc196c
feat: add async close() method to SnapshotRecorder that saves recordings
mcollina Jul 31, 2025
f3945d4
fixup
mcollina Jul 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: clean up console.logs and improve SnapshotAgent experimental war…
…ning

- Remove spurious console.log statements from SnapshotAgent and related tests
- Remove experimental warning from SnapshotRecorder constructor
- Ensure SnapshotAgent experimental warning is only emitted once per process
- Fix trailing whitespace in snapshot-recorder test

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Matteo Collina <[email protected]>
  • Loading branch information
mcollina and claude committed Jul 29, 2025
commit a9d7cb7c8f15dd7b0d325a85859cb506b67a02e4
19 changes: 11 additions & 8 deletions lib/mock/snapshot-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ const kSnapshotPath = Symbol('kSnapshotPath')
const kSnapshotLoaded = Symbol('kSnapshotLoaded')
const kRealAgent = Symbol('kRealAgent')

// Static flag to ensure warning is only emitted once
let warningEmitted = false

class SnapshotAgent extends MockAgent {
constructor (opts = {}) {
// Emit experimental warning
process.emitWarning(
'SnapshotAgent is experimental and subject to change',
'ExperimentalWarning'
)
// Emit experimental warning only once
if (!warningEmitted) {
process.emitWarning(
'SnapshotAgent is experimental and subject to change',
'ExperimentalWarning'
)
warningEmitted = true
}

const mockOptions = { ...opts }
delete mockOptions.mode
Expand Down Expand Up @@ -131,7 +137,6 @@ class SnapshotAgent extends MockAgent {

const recordingHandler = {
onRequestStart (controller, context) {
console.log('aaa')
return handler.onRequestStart(controller, { ...context, history: this.history })
},

Expand All @@ -140,7 +145,6 @@ class SnapshotAgent extends MockAgent {
},

onResponseStart (controller, statusCode, headers, statusMessage) {
console.log('onResponseStart', arguments)
responseData.statusCode = statusCode
responseData.headers = headers
return handler.onResponseStart(controller, statusCode, headers, statusMessage)
Expand All @@ -152,7 +156,6 @@ class SnapshotAgent extends MockAgent {
},

onResponseEnd (controller, trailers) {
console.log('onResponseEnd')
responseData.trailers = trailers

// Record the interaction using captured 'self' context (fire and forget)
Expand Down
6 changes: 0 additions & 6 deletions lib/mock/snapshot-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,6 @@ function isUrlExcluded (url, excludePatterns = []) {

class SnapshotRecorder {
constructor (options = {}) {
// Emit experimental warning
process.emitWarning(
'SnapshotRecorder is experimental and subject to change',
'ExperimentalWarning'
)

this.snapshots = new Map()
this.snapshotPath = options.snapshotPath
this.mode = options.mode || 'record'
Expand Down
2 changes: 1 addition & 1 deletion test/snapshot-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ test('SnapshotRecorder - redirect responses are stored correctly', (t) => {
snapshot = recorder.findSnapshot(redirectRequestOpts)
assert(snapshot, 'Should find snapshot for redirect request')
assert.strictEqual(snapshot.request.url, 'https://api.example.com/redirect-start')

// The recorder supports sequential responses, so it should have both
assert(Array.isArray(snapshot.responses), 'Should have responses array')
assert.strictEqual(snapshot.responses.length, 2, 'Should have two responses')
Expand Down
4 changes: 0 additions & 4 deletions test/snapshot-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ test('SnapshotAgent - record mode', async (t) => {
const origin = `http://localhost:${port}`

t.after(() => new Promise((resolve, reject) => {
console.log('closing')
server.close((err) => {
if (err) {
reject(err)
Expand Down Expand Up @@ -67,8 +66,6 @@ test('SnapshotAgent - record mode', async (t) => {
assert.strictEqual(snapshots[0].request.url, `${origin}/test`)
assert.strictEqual(snapshots[0].responses[0].statusCode, 200)

console.log('bbb')

// Cleanup
t.after(() => unlink(snapshotPath))
})
Expand Down Expand Up @@ -1241,4 +1238,3 @@ test('SnapshotAgent - complex filtering scenarios', async (t) => {
// Cleanup
t.after(() => unlink(snapshotPath).catch(() => {}))
})