Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions dash_vite_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ def _set_assets_path_ignore(self, app: Dash) -> None:
# Remove prefix2 prefix
assets_to_ignore.append(path[len(prefix2) :])

# Set as assets_path_ignore if any paths were found
# Set assets_path_ignore if any paths were found
if assets_to_ignore:
app.config.assets_path_ignore = assets_to_ignore
if not app.config.assets_path_ignore:
app.config.assets_path_ignore = []
app.config.assets_path_ignore.extend(assets_to_ignore)

def _should_skip_build(self) -> bool:
"""
Expand Down
108 changes: 108 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,114 @@ def __init__(self):
expected_ignore = ['css', 'js']
assert mock_app.config.assets_path_ignore == expected_ignore

def test_set_assets_path_ignore_extends_existing(self):
"""Test _set_assets_path_ignore method extends existing assets_path_ignore."""
build_assets_paths = ['./assets/css', 'assets/js']
entry_js_paths = ['assets/js/main.js']
npm_packages = [NpmPackage('react')]

plugin = VitePlugin(
build_assets_paths=build_assets_paths, entry_js_paths=entry_js_paths, npm_packages=npm_packages
)

# Create a mock Dash app with existing assets_path_ignore
class MockConfig:
def __init__(self):
self.assets_folder = 'assets'
self.assets_path_ignore = ['existing/ignore']

mock_app = MagicMock()
mock_app.config = MockConfig()

# Call _set_assets_path_ignore
plugin._set_assets_path_ignore(mock_app)

# Check that assets_path_ignore was extended correctly
expected_ignore = ['existing/ignore', 'css', 'js']
assert mock_app.config.assets_path_ignore == expected_ignore

def test_set_assets_path_ignore_no_matching_paths(self):
"""Test _set_assets_path_ignore method when no paths match assets_dir_name."""
build_assets_paths = ['other/css', './public/js']
entry_js_paths = ['assets/js/main.js']
npm_packages = [NpmPackage('react')]

plugin = VitePlugin(
build_assets_paths=build_assets_paths, entry_js_paths=entry_js_paths, npm_packages=npm_packages
)

# Create a mock Dash app with real config object
class MockConfig:
def __init__(self):
self.assets_folder = 'assets'
self.assets_path_ignore = []

mock_app = MagicMock()
mock_app.config = MockConfig()

# Call _set_assets_path_ignore
plugin._set_assets_path_ignore(mock_app)

# Check that assets_path_ignore remains empty
assert mock_app.config.assets_path_ignore == []

def test_set_assets_path_ignore_empty_build_assets_paths(self):
"""Test _set_assets_path_ignore method when build_assets_paths is empty."""
build_assets_paths = []
entry_js_paths = ['assets/js/main.js']
npm_packages = [NpmPackage('react')]

plugin = VitePlugin(
build_assets_paths=build_assets_paths, entry_js_paths=entry_js_paths, npm_packages=npm_packages
)

# Create a mock Dash app with real config object
class MockConfig:
def __init__(self):
self.assets_folder = 'assets'
self.assets_path_ignore = []

mock_app = MagicMock()
mock_app.config = MockConfig()

# Call _set_assets_path_ignore
plugin._set_assets_path_ignore(mock_app)

# Check that assets_path_ignore remains empty
assert mock_app.config.assets_path_ignore == []

def test_set_assets_path_ignore_complex_paths(self):
"""Test _set_assets_path_ignore method with complex paths."""
build_assets_paths = [
'assets/js',
'./assets/css/styles',
'assets/images/icons',
'public/assets/js', # Should not match
'./public/css', # Should not match
]
entry_js_paths = ['assets/js/main.js']
npm_packages = [NpmPackage('react')]

plugin = VitePlugin(
build_assets_paths=build_assets_paths, entry_js_paths=entry_js_paths, npm_packages=npm_packages
)

# Create a mock Dash app with real config object
class MockConfig:
def __init__(self):
self.assets_folder = 'assets'
self.assets_path_ignore = []

mock_app = MagicMock()
mock_app.config = MockConfig()

# Call _set_assets_path_ignore
plugin._set_assets_path_ignore(mock_app)

# Check that assets_path_ignore contains the correct paths
expected_ignore = ['js', 'css/styles', 'images/icons']
assert mock_app.config.assets_path_ignore == expected_ignore

def test_build_assets_with_vite(self):
"""Test _build_assets_with_vite method."""
build_assets_paths = ['assets/js']
Expand Down
Loading