-
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
[Bug]: Setup testing database environment breaks the immutable infrastructure rule #1844
Comments
Thank you for reporting. Transferring the issue to Strapi engineers, so they can help us updating the testing guide. |
@pwizla Hi, how's it going now ? Any feedback ? |
Hi @DevDengChao Strapi developers are currently extremely busy fixing and improving Strapi v4 while actively developing v5. I can't provide any ETA for now, but rest assured that updating the Testing documentation is in our backlog; Strapi Docs team knows this is often requested so we'll prioritize it. In the meantime I'll check with Support team if we can find a quick workaround around the immutable infrastructure rule. |
@pwizla We should also add TS version to the docs aka for setupStrapi the TS version should. async function setupStrapi() {
if (!instance) {
const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
const outDir = await tsUtils.resolveOutDir(appDir);
const distDir = isTSProject ? outDir : appDir;
const buildDirExists = fs.existsSync(outDir);
if (isTSProject && !buildDirExists)
throw new Error(
`${outDir} directory not found. Please run the build command before starting your application`
);
await Strapi({ appDir, distDir }).load();
instance = strapi; // strapi is global now
}
return instance;
} with the current testing will not work for TS users. |
Also strapi can not be tested to my knolage witout a db connected to it |
Another approch is |
Hi, |
Link to the documentation page or resource
https://docs.strapi.io/dev-docs/testing#set-up-a-testing-environment
Describe the bug
The document recommends developers to use a temp local file to host a SQLite database for unit testing, this behavior breaks the immutable infrastructure rule: the developer is using a different database instance from he/she used in production.
This action rises the risk of passing unit test but server down in production.
The risk may comes from different databse type (SQLite vs MySQL), different database version or even hardwares.
Additional context
Suggested improvements or fixes
Deprecate the temp local SQLite database guide for unit testing, and introduce some rollback/truncate guides like https://forum.strapi.io/t/testing-with-a-postgres-database/2232/3?u=devdengchao .
Related issue(s)/PR(s)
The text was updated successfully, but these errors were encountered: