Skip to content

Test Suite Documentation

All tests use the Node.js built-in test runner (node:test) with node:assert/strict. No external test frameworks (Jest, Mocha, Vitest) are used. Test data is provided as inline mock fixtures -- no external fixture files.


Running Tests

tradingview-strategy (63 tests)

cd tradingview-strategy
node --test tests/**/*.test.js

This runs all 9 test files across 3 categories: interpreters, engine, and contracts.

tradingview-mcp (70+ tests)

cd tradingview-mcp

# End-to-end tests (requires TradingView Desktop running with CDP on port 9222)
node --test tests/e2e.test.js

# CLI tests (no connection required)
node --test tests/cli.test.js

# Pine analysis tests
node --test tests/pine_analyze.test.js

# Replay tests
node --test tests/replay.test.js

# Sanitization tests
node --test tests/sanitization.test.js

tradingview-strategy Test Categories

Interpreter Tests (4 files)

tests/interpreters/bias.test.js -- 8 tests

Tests the interpretBias() function that parses HTF Bias AI indicator graphics.

Test What it verifies
Detects bullish bias from label text "Close Above PDH\nBias PDH" parses to daily: 'bullish', draw_on_liquidity: 'PDH'
Detects bearish bias from label text "Close Below PDL\nBias PDL" parses to daily: 'bearish'
Detects neutral bias from outside bar "Outside Bar but Closed Inside\nNo Bias" parses to daily: 'neutral'
Detects counter-trend bias (failed close) "Failed to Close Below PDL\nBias PDH" still reads as bullish
Extracts PDH/PDL levels from lines Horizontal lines at prices map to levels.pdh and levels.pdl
Separates daily vs weekly lines Solid lines (style 0) = daily; dashed lines (style 2) = weekly (PWH/PWL)
Uses most recent label When multiple labels exist, last in array (highest x) wins
Handles empty data gracefully Empty arrays produce neutral bias with null DOL

tests/interpreters/session.test.js -- 7 tests

Tests the interpretSession() function that parses Session Hunt AI graphics.

Test What it verifies
Detects HUNT_HIGH when high is swept Gray dashed high + "London H checkmark" label = HUNT_HIGH
Detects HUNT_LOW when low is swept Gray dashed low + "London L checkmark" label = HUNT_LOW
Detects INVALID when both swept Both labels have checkmarks = INVALID
Detects re-extension from orange lines Orange (#ff9900) lines indicate reextended: true with price levels
Detects NY mode from London labels "London H" label implies NY session mode
Detects London mode from Asia labels "Asia H" label implies London session mode
Handles empty data gracefully Empty arrays produce null hunt side

tests/interpreters/orderblock.test.js -- 6 tests

Tests the interpretOrderblocks() function that parses OB AI graphics.

Test What it verifies
Parses bullish OB from paired lines Two blue horizontal lines at same x = one bullish OB with high/low
Parses bearish OB from paired lines Two dark red horizontal lines = one bearish OB
Detects spent OB from dotted style Line style 1 (dotted) = spent: true
Parses ATR banner table "ES \| $102.50" table row extracts instrument, risk, stop points/ticks, position size
Associates FVG boxes with nearest OB Boxes near OB price range attach as fvg property
Handles empty data gracefully Empty arrays produce empty OB lists and null ATR

tests/interpreters/smt.test.js -- 5 tests

Tests the interpretSMT() function that parses SMT Divergences graphics.

Test What it verifies
Detects bullish SMT from label_up style yloc: 2 (belowBar) = bullish signal
Detects bearish SMT from label_down style yloc: 1 (aboveBar) = bearish signal
Counts multiple SMTs Multiple labels counted; last by x-position determines last_signal
Extracts paired instrument "SMT - NQ1!" label text parses instrument name
Handles no SMTs gracefully Empty data produces all-false/null output

Engine Tests (3 files)

tests/engine/confluence.test.js -- 4 tests

Tests the scoreConfluence() function and MAX_SCORE constant.

Test What it verifies
Scores maximum confluence (9) All 6 factors present: bias_aligns_hunt, weekly_confirms, ob_in_path, ob_has_fvg, smt_confirms, macro_timing
Scores 0 when nothing aligns Bearish bias + bullish hunt + no OBs + no SMT + no macro = 0
Scores bias alignment at weight 2 bias_aligns_hunt alone contributes score of 2 (weighted)
Does not count spent OBs OBs with spent: true are excluded from ob_in_path

tests/engine/no-trade.test.js -- 9 tests

Tests the evaluateNoTrade() function that produces no-trade reasons.

Test What it verifies
Returns empty when all valid Clean setup produces no reasons
Flags neutral bias neutral_bias reason
Flags invalid hunt invalid_hunt reason
Flags no hunt locked no_hunt_locked when hunt side is null
Flags no unspent OBs no_unspent_ob when all OBs are spent
Flags outside entry window outside_entry_window reason
Flags R:R below minimum rr_below_minimum when risk/reward < 2.0
Flags DOL already hit dol_already_hit when hit_target: true
Flags hunt-bias misalignment hunt_bias_misalign when hunt and bias disagree
Returns multiple reasons Validates that multiple failures accumulate

tests/engine/setup-detector.test.js -- 5 tests

Tests the detectSetup() function that names the specific trade setup.

Test What it verifies
Detects hunt_long_ob_fvg_smt_macro Full bullish setup with all elements present
Detects hunt_short_ob Bearish setup with OB but no FVG/SMT/macro
Detects reext_ prefix Re-extension setups get a reext_ prefix
Returns no_setup for INVALID hunt Invalid hunt produces null direction
Returns hunt_no_bias for misalignment Hunt without matching bias = no tradeable setup

Contract Tests (2 files)

tests/contracts/colors.test.js -- 10 tests

Tests normalizeColor() and colorsMatch() from the colors contract.

Test What it verifies
Passes through 6-char hex #ff0000 unchanged
Strips alpha from 8-char hex #ff0000cc -> #ff0000
Expands 3-char hex #f00 -> #ff0000
Converts rgb() rgb(255, 0, 0) -> #ff0000
Converts rgba() rgba(0, 128, 255, 0.5) -> #0080ff
Handles null/undefined Returns #000000
Matches identical colors Exact match returns true
Matches within tolerance Per-channel delta <= tolerance passes
Rejects outside tolerance Large delta fails
Normalizes before comparing Mixed formats compared correctly

tests/contracts/session-times.test.js -- 8 tests

Tests getCurrentWindow() and checkMacro().

Test What it verifies
gap_scan at 06:00 (NY) Pre-market gap scan window
ny_am at 08:00 (NY) NY morning session
ny_pm at 12:00 (NY) NY afternoon session
post_eod at 15:30 (NY) After end-of-day cutoff
london at 03:00 (NY) London session in NY mode
Macro at 08:55 Returns in_macro: true, name 08:50-09:10
No macro at 08:30 Returns in_macro: false
PM macro at 15:20 Detects the 15:15-15:45 special window

tradingview-mcp Test Files

tests/e2e.test.js (70+ tests)

End-to-end tests that require a live CDP connection to TradingView Desktop on port 9222. Tests all 78 MCP tools against a real chart, including chart navigation, Pine graphics reading, indicator management, drawing tools, screenshot capture, and data export.

tests/cli.test.js

Tests the CLI router and command parsing without requiring a CDP connection. Verifies command registration, help output, and argument parsing.

tests/pine_analyze.test.js

Tests Pine Script analysis utilities that parse and inspect indicator code structure.

tests/replay.test.js

Tests the chart replay functionality (bar replay mode for backtesting).

tests/sanitization.test.js

Tests input sanitization for MCP tool parameters, ensuring safe handling of special characters and malformed inputs.


Test Patterns

  • No external framework: All tests use node:test (describe, it) and node:assert/strict
  • Inline mock data: Test fixtures are defined directly in the test file as plain objects, mimicking the shape of MCP tool responses
  • No network calls: Strategy tests mock all MCP data; only tradingview-mcp e2e tests require a live connection
  • Deterministic: No time-dependent tests except session-times.test.js which tests specific hour/minute inputs (not wall-clock time)
  • Fast execution: The full strategy suite (63 tests) completes in under 1 second