Using a server hook to seed sample data
In the early chapters of the book, we added seed data into the /birthdays
route in the src/routes/birthdays/+page.server.js
file. At the top, there are two calls to addNew
to create two fake birthdays. We relied on this data within our Playwright tests. It’s now time to clean up.
Creating repeated data in the development environment
If you’ve been running the dev server while you edited files, you will have noticed that as SvelteKit reloaded your files, the fake birthdays were repeatedly created, resulting in many birthday objects in the system. This was because of those addNew
calls at the top of the route’s +page.server.js
file. Another problem caused by our seed data will now be fixed.
First, we’ll update the Playwright tests to create all their test data via the API. Then we’ll remove the hardcoded seed data from our system. Finally, we will bring the seed data back when loading the development...