-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: add customizable app_client_class config value #138
Open
Niicck
wants to merge
1
commit into
MrBin99:master
Choose a base branch
from
Niicck:app-client-class
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+124
−36
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import pytest | ||
|
||
from django_vite.core.asset_loader import ( | ||
DjangoViteAppClient, | ||
DjangoViteAssetLoader, | ||
ManifestClient, | ||
) | ||
|
||
|
||
def mock_get_manifest_from_url(): | ||
""" | ||
Pretend that we're fetching manifest.json from an external source. | ||
""" | ||
return { | ||
"src/mock_external_entry.js": { | ||
"css": ["assets/entry-0ed1a6fd.css"], | ||
"file": "assets/entry-5c085aac.js", | ||
"isEntry": True, | ||
"src": "entry.js", | ||
}, | ||
"src/mock_external_entry.css": { | ||
"file": "assets/entry-0ed1a6fd.css", | ||
"src": "entry.css", | ||
}, | ||
} | ||
|
||
|
||
class CustomManifestClient(ManifestClient): | ||
""" | ||
Custom ManifestClient that loads manifest.json from an external source. | ||
""" | ||
|
||
def load_manifest(self): | ||
return mock_get_manifest_from_url() | ||
|
||
|
||
class CustomAppClient(DjangoViteAppClient): | ||
""" | ||
Custom AppClient with a Custom ManifestClient. | ||
""" | ||
|
||
ManifestClient = CustomManifestClient | ||
|
||
|
||
def test_app_client_class(patch_settings): | ||
patch_settings( | ||
{ | ||
"DJANGO_VITE": { | ||
"default": { | ||
"app_client_class": "tests.tests.test_custom_app_client_class.CustomAppClient", | ||
} | ||
} | ||
} | ||
) | ||
DjangoViteAssetLoader._instance = None | ||
assert ( | ||
"src/mock_external_entry.js" | ||
in DjangoViteAssetLoader.instance()._apps["default"].manifest._entries | ||
) | ||
|
||
|
||
def test_invalid_app_client_class(patch_settings): | ||
with pytest.raises(ModuleNotFoundError): | ||
patch_settings( | ||
{ | ||
"DJANGO_VITE": { | ||
"default": { | ||
"app_client_class": "django_vite.invalid.CustomAppClient", | ||
} | ||
} | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems a bit redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defining the ManifestClient as a class variable allows you to create a subclassed DjangoViteAppClient with a separate subclassed ManifestClient. You can look at the
test_custom_app_client_class
for an example. If we didn't do this, then we'd have no way to overwrite the logic of the ManifestClient without doing module-level monkeypatching.Thinking this through, we should probably also add other dependency classes like TagGenerator as class variables as well, to allow them to be easily extensible.