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

[Bug]: Setup testing database environment breaks the immutable infrastructure rule #1844

Closed
DevDengChao opened this issue Sep 15, 2023 · 7 comments
Assignees
Labels
issue: docs/instructions Issues about incorrect instructions found on docs.strapi.io

Comments

@DevDengChao
Copy link

Link to the documentation page or resource

https://docs.strapi.io/dev-docs/testing#set-up-a-testing-environment

Describe the bug

image

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)

@pwizla
Copy link
Collaborator

pwizla commented Sep 15, 2023

Thank you for reporting. Transferring the issue to Strapi engineers, so they can help us updating the testing guide.

@DevDengChao
Copy link
Author

@pwizla Hi, how's it going now ? Any feedback ?

@pwizla
Copy link
Collaborator

pwizla commented Oct 18, 2023

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 pwizla added the issue: docs/instructions Issues about incorrect instructions found on docs.strapi.io label Oct 18, 2023
@pwizla pwizla self-assigned this Oct 18, 2023
@Boegie19
Copy link
Contributor

@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.

@Boegie19
Copy link
Contributor

Also strapi can not be tested to my knolage witout a db connected to it

@DevDengChao
Copy link
Author

@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.

Another approch is compile() before await Strapi( ... ).load();

@pwizla
Copy link
Collaborator

pwizla commented Dec 4, 2023

Hi,
Thanks for reporting. I'm closing this issue, but it's included in the meta issue about reworking the Testing page (#1940).
In the meantime I'll check with Strapi engineers to see if they can come up with a solution.

@pwizla pwizla closed this as completed Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: docs/instructions Issues about incorrect instructions found on docs.strapi.io
Projects
None yet
Development

No branches or pull requests

3 participants