Ecommerce Template: E2E Tests Fail - Multiple Issues
Describe the Bug
Issues
1. Missing files
The tests depend on the file public/media/image-post1.webp but there is no public folder as this is untracked due to a .gitignore entry.
2. Tests depend on an empty db
You need to drop the users table or run payload migrate:fresh before running the tests as the test can't create an admin user unless it creates the very first user in the db. Tests could run on an in-memory db, or load a different URI from .env.test, or run the migrate command automatically before/after the suite runs.
3. There is no cleanup. Each test run creates duplicates of the product image and the public/assets folder fills up with copies which have to be manually deleted.
4. After accounting for the previous issues, tests still fail before starting.
In the beforeAll hook, the function createVariantsAndProducts has a variable productWithVariantsJSON which resolves to { errors: [ { message: 'Something went wrong.' } ] }
This is due to the data object containing gallery: [imageID], which should be gallery: [{ image: imageID }].
5. Cart tests fail.
The cart tests recreate test products which cause errors due to the slugs already existing. The tests should be refactored to be idempotent.
6. Remove item from cart fails.
This is probably due to #14645
7. The rest of the tests fail.
I stopped debugging/fixing here after getting the first 10 to pass. The last 10 tests still fail.
Link to the code that reproduces this issue
https://github.com/payloadcms/payload/tree/main/templates/ecommerce
Reproduction Steps
- Set up the template using the CLI: pnpx create-payload-app my-project -t ecommerce
- Run the command
pnpm test:e2e - Go through the fixes above one by one to progress through the issues
Which area(s) are affected? (Select all that apply)
area: templates
Environment Info
Binaries:
Node: 24.9.0
npm: 11.6.0
Yarn: 1.22.22
pnpm: 10.17.1
Relevant Packages:
payload: 3.64.0
next: 15.5.6
@payloadcms/db-mongodb: 3.64.0
@payloadcms/email-nodemailer: 3.64.0
@payloadcms/graphql: 3.64.0
@payloadcms/live-preview: 3.64.0
@payloadcms/live-preview-react: 3.64.0
@payloadcms/next/utilities: 3.64.0
@payloadcms/plugin-form-builder: 3.64.0
@payloadcms/plugin-seo: 3.64.0
@payloadcms/richtext-lexical: 3.64.0
@payloadcms/translations: 3.64.0
@payloadcms/ui/shared: 3.64.0
react: 19.2.0
react-dom: 19.2.0
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
Available memory (MB): 16384
Available CPU cores: 8