Skip to content
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

Not working with StaticLiveServerTestCase #95

Open
ipeterov opened this issue Oct 25, 2023 · 1 comment
Open

Not working with StaticLiveServerTestCase #95

ipeterov opened this issue Oct 25, 2023 · 1 comment

Comments

@ipeterov
Copy link

ipeterov commented Oct 25, 2023

I wrote Playwright tests for my web app that uses django-vite. Currently, I have to run manage.py collectstatic every time I want to run my tests (if the frontend changed).

Django has a special tool for this use case - StaticLiveServerTestCase. It serves the static files right from STATICFILES_DIRS, allowing me to just run the tests without doing manage.py collectstatic.

When I'm running the tests, they are failing with a django-vite error:

Cannot find src/main.jsx in Vite manifest at /code/static/manifest.json

It looks like the error is originating here. I checked with a debugger, and self._manifest was None.

It would be cool to be able to use this Django feature with django-vite. How can I help to resolve/investigate the issue?

@Niicck
Copy link
Collaborator

Niicck commented Oct 26, 2023

During your playwright test execution, you'll want to adjust your DJANGO_VITE_MANIFEST_PATH and DJANGO_VITE_STATIC_URL_PREFIX.

By default, with DEV_MODE=False, django-vite will expect to look for your manifest.json in your STATIC_ROOT, which I'm guessing you've set to /code/static/. But your manifest.json won't be there if haven't run collectstatic.

So you're going to need to set your DJANGO_VITE_MANIFEST_PATH to the location in STATICFILES_DIR where your compiled vite assets initially lived before then get collected into your STATIC_ROOT. See if that solves your self._manifest being set to None. That's step 1.

Step 2 will be probably be the problem of your individual vite_assets not being discovered since they're not in STATIC_ROOT either. manifest.json gives the related paths of each of your vite_asset entries, but since they aren't in your STATIC_ROOT, the vite_asset tag may not know where they live.

If your assets don't get loaded after you've fixed your manifest_path, then you need to adjust DJANGO_VITE_STATIC_URL_PREFIX to point to the same root directory as your DJANGO_VITE_MANIFEST_PATH -- the place they live in STATICFILES_DIR before they get collected.

Let me know how that works out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants