Skip to content

Conversation

pwizla
Copy link
Collaborator

@pwizla pwizla commented Sep 18, 2025

This PR merges content from 2 blog posts published on Unit testing and tries to update them for Strapi 5

TODO:

  • integrate blog posts content
  • refine content
  • fix why example tests are failing
  • rework content with the fixed test examples

Direct preview link 👉 here

@pwizla pwizla self-assigned this Sep 18, 2025
@vercel
Copy link

vercel bot commented Sep 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
documentation Ready Ready Preview Comment Oct 20, 2025 2:33pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

@github-actions github-actions bot added the internal PRs created by the Strapi core team label Sep 18, 2025
@pwizla pwizla added this to the 6.9.2 milestone Sep 19, 2025
@pwizla pwizla modified the milestones: 6.9.2, 6.9.3 Oct 1, 2025
@pwizla pwizla marked this pull request as ready for review October 3, 2025 14:37
@pwizla pwizla requested a review from meganelacheny as a code owner October 3, 2025 14:37
@pwizla pwizla changed the title Update Unit testing Rework the Unit testing for Strapi 5 Oct 3, 2025
@ancashoria
Copy link

Hey, it's great you're updating the testing page.
I'm trying to setup a Strapi testing environment using sqlite and I'd like to mention one thing I have stumbled upon because it seems it's still present in the updated article.

This section: https://documentation-git-cms-testing-reworked-strapijs.vercel.app/cms/testing#set-up-a-testing-environment

When I have two different files for the database config, only one of them ends up in dist/config/database.js and since my test setup uses the dist folder, my test setup breaks if I run yarn dev setup.

const app = await createStrapi({
      appDir: "./",
      distDir: "./dist",
    }).load();

Basically if I run yarn test after yarn dev, my testing fails.

Hopefuly this helps somehow.

@ancashoria
Copy link

ancashoria commented Oct 9, 2025

Is there a way to bootstrap the sqlite db based on a template? My API tests expect some data already configured.

@pwizla
Copy link
Collaborator Author

pwizla commented Oct 9, 2025

Hi @ancashoria, thanks for your interest and kind words regarding this PR :)

To be honest, I only have basic experience with testing, but as a technical writer for Strapi, I’m doing my best, with the help of AI-based tools, to update this page. I’m afraid your feedback points to issues that are a bit beyond my current skill set, but I’ll try to get help from Strapi engineers to improve the PR (it still needs their review, anyway 👀).

I’ll keep you posted!

@pwizla pwizla changed the title Rework the Unit testing for Strapi 5 Rework the Unit testing page for Strapi 5 Oct 10, 2025
@pwizla pwizla modified the milestones: 6.9.4, 6.9.5 Oct 10, 2025
@pwizla pwizla added the pr: updated content PRs updating existing documentation content label Oct 15, 2025
@pwizla pwizla added source: CMS flag: don't merge This PR should not be merged at the moment labels Oct 15, 2025
@pwizla
Copy link
Collaborator Author

pwizla commented Oct 20, 2025

@ancashoria I haven't had any replies from the Strapi devs yet, but did my best to update things (both the present PR and the accompanying https://github.com/pwizla/strapi-unit-testing-examples repo with the help of AIs.

Here's what I did:

  1. distDir conflict issue:
    Added a detailed warning section explaining the problem when using distDir after running yarn dev
    Updated the test harness to avoid distDir conflicts by using createStrapi().load() without overrides

  2. SQLite bootstrap/template:
    Added a complete "Seed predictable test data" section with step-by-step guide
    Implemented TEST_SEED=true environment variable support in the test harness
    The seeding function automatically adapts for test environment (skips complex operations that aren't needed for basic tests)

Usage: Run TEST_SEED=true yarn test or TEST_SEED=true npm run test(I've tested it locally and now all tests pass)

Both solutions are now documented and working in the updated testing guide. The test suite runs cleanly without the previous SQLite "aborted" errors.

I hope this helps!

@pwizla pwizla removed the flag: don't merge This PR should not be merged at the moment label Oct 21, 2025
@pwizla pwizla merged commit 3660e1c into main Oct 21, 2025
4 of 5 checks passed
@pwizla pwizla deleted the cms/testing-reworked branch October 21, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal PRs created by the Strapi core team pr: updated content PRs updating existing documentation content source: CMS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants