Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 2 additions & 0 deletions src/cryptoadvance/specter/templates/base.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='typography.css') }}?{{rand}}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='output.css') }}?{{rand}}">

{% if config.SPECTER_CONFIGURATION_CLASS_FULLNAME and 'DevelopmentConfig' in config.SPECTER_CONFIGURATION_CLASS_FULLNAME %}
<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>
{% endif %}
<script type="text/javascript" src="{{ url_for('static', filename='helpers.js') }}"></script>

{% include "includes/helpers.jinja" %}
Expand Down
53 changes: 53 additions & 0 deletions tests/test_livereload_conditional.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
Test to verify that livereload.js is only included in DevelopmentConfig
"""
import logging
import pytest
from cryptoadvance.specter.server import create_app, init_app
from cryptoadvance.specter.specter import Specter


def test_livereload_not_in_testconfig(caplog, app_no_node):
"""
Test that livereload.js is NOT included when using TestConfig (similar to ProductionConfig)
The app_no_node fixture uses TestConfig which should NOT include livereload.js
"""
caplog.set_level(logging.INFO)
caplog.set_level(logging.DEBUG, logger="cryptoadvance.specter")

client = app_no_node.test_client()

# Get the welcome page (which uses base.jinja)
result = client.get("/", follow_redirects=True)
assert result.status_code == 200

# Verify that livereload.js script is NOT in the response
response_text = result.data.decode('utf-8')
assert '35729/livereload.js' not in response_text, \
"livereload.js should NOT be included in TestConfig (similar to ProductionConfig)"


def test_livereload_in_developmentconfig(empty_data_folder):
"""
Test that livereload.js IS included when using DevelopmentConfig
"""
# Create app with DevelopmentConfig and minimal specter instance
specter = Specter(data_folder=empty_data_folder, checker_threads=False)
app = create_app(config='DevelopmentConfig')
app.config["TESTING"] = True
app.testing = True
app.tor_service_id = None
app.tor_enabled = False

with app.app_context():
init_app(app, specter=specter)
client = app.test_client()

# Get the welcome page (which uses base.jinja)
result = client.get("/", follow_redirects=True)
assert result.status_code == 200

# Verify that livereload.js script IS in the response
response_text = result.data.decode('utf-8')
assert '35729/livereload.js' in response_text, \
"livereload.js SHOULD be included in DevelopmentConfig"
Loading