-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Strapi 5 + typescript + jest === broken #2179
Comments
I'm not sure this is a documentation issue, @derrickmehaffy. Strapi is specifically dynamically loading |
Unless, I guess, the docs say to use something else, like vitest or something like it that can incrementally compile and run tests. |
This issue has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/how-can-i-add-vitest-to-a-strapi-5-app/41255/1 |
I can make it it run by add jest.config.ts and ts-jest, but I still get this error message:
|
Bug report
Required System information
Describe the bug
Jest tests fail to run because Strapi won't load
.ts
config files.Steps to reproduce the behavior
I published an example app that shows the issue to save you time, but I took the following steps to create the app:
I then added the
testPathIgnorePatterns
to the Jest config as shown in the Strapi jest setup guide.I added a
strapi.ts
helper file as explained in the Strapi jest setup guide. I converted it to TypeScript and used the newcreateStrapi
function as well.I added a
config/env/test/database.ts
and aconfig/env/production/database.ts
file.I added the following lines to my
.env
file:I added
tests/app.test.ts
as described in the Strapi jest setup guide. This file has been converted to TypeScript as well.Run tests with
yarn test
.Expand this to see the test output...
As you can see, there are a lot of warnings like
Config file not loaded, extension must be one of .js,.json): database.ts
and then the tests fails because something internal to Strapi can't destructure config values.Interestingly, if I pass the value
{ distDir: "dist" }
tocreateStrapi
instrapi.ts
, and runyarn build
before I runyarn test
, the tests pass. Presumably this is because it's running the tests from thedist
dir andyarn build
is transpiling those files to.js
files.Expected behavior
I would expect there to be some way to run tests under TypeScript with Strapi that didn't require a build first. This is also broken under Strapi 4 in the same way and I was trying out Strapi 5 to see if I could make it work.
Screenshots
N/A
Code snippets
N/A
Additional context
I'm really happy Strapi is getting better TypeScript support! I'd love if it could get better testing support as well. Thanks so much for the great software!!
The text was updated successfully, but these errors were encountered: