Skip to content

πŸ“ˆ Get real-time stocks from TradingView

Prevent leaked indicator retries between tests

copilot-swe-agent[bot]da3148b4a499
diff --git a/tests/indicators.test.ts b/tests/indicators.test.ts
index ec1d575..f74003e 100644
--- a/tests/indicators.test.ts
+++ b/tests/indicators.test.ts
@@ -69,8 +69,12 @@ describe('Indicators', () => {
const SuperTrend = new chart.Study(indicators.SuperTrend);
let QTY = 10;
+ let done = false;
+ const retryTimers = new Set<NodeJS.Timeout>();
const perfResult = await new Promise((resolve) => {
SuperTrend.onUpdate(() => {
+ if (done) return;
+
// SuperTrend is a strategy so it sends a strategy report
const perfReport = SuperTrend.strategyReport.performance;
@@ -96,21 +100,31 @@ describe('Indicators', () => {
});
if (perfReport?.all?.totalTrades !== undefined && QTY >= 50) {
+ done = true;
+ retryTimers.forEach((timer) => clearTimeout(timer));
+ retryTimers.clear();
resolve(true);
return;
}
QTY += 10;
console.log('TRY WITH', QTY, '%');
- setTimeout(() => {
+ const timer = setTimeout(() => {
+ retryTimers.delete(timer);
+ if (done) return;
+
indicators.SuperTrend.setOption('default_qty_value', QTY);
SuperTrend.setIndicator(indicators.SuperTrend);
}, 1000);
+ retryTimers.add(timer);
});
});
expect(perfResult).toBe(true);
+ done = true;
+ retryTimers.forEach((timer) => clearTimeout(timer));
+ retryTimers.clear();
SuperTrend.remove();
}, 30000);