Clearing the data store between tests
It turns out our tests are not independent: changes to the db object in one test affect the other tests, too. We have to clear down our test database between each run. We can solve that by creating a clear function that will clear the database object, and we’ll use a beforeEach block to call it before every test.
What we need is the clear function that we can call directly in our tests. However, if you try to add this function to the +page.server.js file, you’ll get a warning from SvelteKit when you run your Playwright tests:
Error: Invalid export 'clear' in /birthdays (valid exports are load, prerender, csr, ssr, actions, trailingSlash, or anything with a '_' prefix)
Why does this error appear only in the Playwright tests and not the Vitest tests? Your Vitest tests do not run through the SvelteKit server code, so the framework has no opportunity to check for invalid exports. It’s only when you...