Skip to content

Commit 53c7b71

Browse files
committed
🐛 Fix TDD comparison caching and cloud minClusterSize (#158, #160)
**Issue #158 - TDD still-failing screenshots aren't updated:** Added `_upsertComparison()` helper that replaces existing comparisons by ID instead of always appending. This fixes the bug where re-running tests in TDD daemon mode would accumulate stale comparison results, causing fixed screenshots to still appear as failures. **Issue #160 - minClusterSize not sent to cloud API:** Added `minClusterSize` to the `runOptions` object in the run command. The setting was already loaded from config but wasn't being passed through to the API payload builder.
1 parent 4f859db commit 53c7b71

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/commands/run.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export async function runCommand(
236236
message,
237237
environment: config.build.environment,
238238
threshold: config.comparison.threshold,
239+
minClusterSize: config.comparison.minClusterSize,
239240
eager: config.eager || false,
240241
allowNoToken: config.allowNoToken || false,
241242
wait: config.wait || options.wait || false,

src/tdd/tdd-service.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ export class TddService {
259259
// Track whether results have been printed (to avoid duplicate output)
260260
this._resultsPrinted = false;
261261

262+
// Bind the helper method
263+
this._upsertComparison = this._upsertComparison.bind(this);
264+
262265
if (this.setBaseline) {
263266
output.info(
264267
'[vizzly] Baseline update mode - will overwrite existing baselines with new ones'
@@ -1131,6 +1134,20 @@ export class TddService {
11311134
return metadata;
11321135
}
11331136

1137+
/**
1138+
* Upsert a comparison result - replaces existing if same ID, otherwise appends.
1139+
* This prevents stale results from accumulating in daemon mode.
1140+
* @private
1141+
*/
1142+
_upsertComparison(result) {
1143+
let existingIndex = this.comparisons.findIndex(c => c.id === result.id);
1144+
if (existingIndex >= 0) {
1145+
this.comparisons[existingIndex] = result;
1146+
} else {
1147+
this.comparisons.push(result);
1148+
}
1149+
}
1150+
11341151
/**
11351152
* Compare a screenshot against baseline
11361153
*/
@@ -1248,7 +1265,7 @@ export class TddService {
12481265
properties: validatedProperties,
12491266
});
12501267

1251-
this.comparisons.push(result);
1268+
this._upsertComparison(result);
12521269
return result;
12531270
}
12541271

@@ -1288,7 +1305,7 @@ export class TddService {
12881305
honeydiffResult,
12891306
});
12901307

1291-
this.comparisons.push(result);
1308+
this._upsertComparison(result);
12921309
return result;
12931310
} else {
12941311
let hotspotAnalysis = this.getHotspotForScreenshot(name);
@@ -1315,7 +1332,7 @@ export class TddService {
13151332
diff: diffInfo,
13161333
});
13171334

1318-
this.comparisons.push(result);
1335+
this._upsertComparison(result);
13191336
return result;
13201337
}
13211338
} catch (error) {
@@ -1356,7 +1373,7 @@ export class TddService {
13561373
properties: validatedProperties,
13571374
});
13581375

1359-
this.comparisons.push(result);
1376+
this._upsertComparison(result);
13601377
return result;
13611378
}
13621379

@@ -1371,7 +1388,7 @@ export class TddService {
13711388
errorMessage: error.message,
13721389
});
13731390

1374-
this.comparisons.push(result);
1391+
this._upsertComparison(result);
13751392
return result;
13761393
}
13771394
}
@@ -1792,7 +1809,7 @@ export class TddService {
17921809
signature,
17931810
};
17941811

1795-
this.comparisons.push(result);
1812+
this._upsertComparison(result);
17961813
output.info(`Baseline created for ${name}`);
17971814
return result;
17981815
}

0 commit comments

Comments
 (0)